generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 重構MonopolyEventBus、事件處理及測試
- Loading branch information
Showing
130 changed files
with
1,647 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Domain.Common; | ||
|
||
namespace Server.Common; | ||
|
||
internal interface IMonopolyEventHandler | ||
{ | ||
public Type EventType { get; } | ||
Task HandleAsync(DomainEvent e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Domain.Common; | ||
|
||
namespace Server.Common; | ||
|
||
public abstract class MonopolyEventHandlerBase<TEvent> : IMonopolyEventHandler where TEvent : DomainEvent | ||
{ | ||
public Type EventType => typeof(TEvent); | ||
|
||
public Task HandleAsync(DomainEvent e) | ||
{ | ||
if (e is TEvent tEvent) | ||
{ | ||
return HandleSpecificEvent(tEvent); | ||
} | ||
throw new InvalidOperationException($"Handler for {e.GetType()} not registered"); | ||
} | ||
|
||
protected abstract Task HandleSpecificEvent(TEvent e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Server/Hubs/EventHandlers/CannotGetRewardBecauseStandOnStartEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Domain.Events; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Server.Common; | ||
using SharedLibrary; | ||
using SharedLibrary.ResponseArgs.Monopoly; | ||
|
||
namespace Server.Hubs.EventHandlers; | ||
|
||
public class CannotGetRewardBecauseStandOnStartEventHandler(IHubContext<MonopolyHub, IMonopolyResponses> hubContext) | ||
: MonopolyEventHandlerBase<CannotGetRewardBecauseStandOnStartEvent> | ||
{ | ||
protected override Task HandleSpecificEvent(CannotGetRewardBecauseStandOnStartEvent e) | ||
{ | ||
return hubContext.Clients.All.CannotGetRewardBecauseStandOnStartEvent( | ||
new CannotGetRewardBecauseStandOnStartEventArgs | ||
{ | ||
PlayerId = e.PlayerId | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Domain.Events; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Server.Common; | ||
using SharedLibrary; | ||
using SharedLibrary.ResponseArgs.Monopoly; | ||
|
||
namespace Server.Hubs.EventHandlers; | ||
|
||
public class ChessMovedEventHandler(IHubContext<MonopolyHub, IMonopolyResponses> hubContext) : MonopolyEventHandlerBase<ChessMovedEvent> | ||
{ | ||
protected override Task HandleSpecificEvent(ChessMovedEvent e) | ||
{ | ||
return hubContext.Clients.All.ChessMovedEvent(new ChessMovedEventArgs | ||
{ | ||
PlayerId = e.PlayerId, | ||
BlockId = e.BlockId, | ||
Direction = e.Direction, | ||
RemainingSteps = e.RemainingSteps | ||
}); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Server/Hubs/EventHandlers/CurrentPlayerCannotBidEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Domain.Events; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Server.Common; | ||
using SharedLibrary; | ||
using SharedLibrary.ResponseArgs.Monopoly; | ||
|
||
namespace Server.Hubs.EventHandlers; | ||
|
||
public class CurrentPlayerCannotBidEventHandler(IHubContext<MonopolyHub, IMonopolyResponses> hubContext) | ||
: MonopolyEventHandlerBase<CurrentPlayerCannotBidEvent> | ||
{ | ||
protected override Task HandleSpecificEvent(CurrentPlayerCannotBidEvent e) | ||
{ | ||
return hubContext.Clients.All.CurrentPlayerCannotBidEvent( | ||
new CurrentPlayerCannotBidEventArgs | ||
{ | ||
PlayerId = e.PlayerId | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Domain.Events; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Server.Common; | ||
using SharedLibrary; | ||
using SharedLibrary.ResponseArgs.Monopoly; | ||
|
||
namespace Server.Hubs.EventHandlers; | ||
|
||
public class EndAuctionEventHandler(IHubContext<MonopolyHub, IMonopolyResponses> hubContext) | ||
: MonopolyEventHandlerBase<EndAuctionEvent> | ||
{ | ||
protected override Task HandleSpecificEvent(EndAuctionEvent e) | ||
{ | ||
return hubContext.Clients.All.EndAuctionEvent( | ||
new EndAuctionEventArgs | ||
{ | ||
PlayerId = e.PlayerId, | ||
LandId = e.LandId, | ||
OwnerId = e.OwnerId, | ||
PlayerMoney = e.PlayerMoney, | ||
OwnerMoney = e.OwnerMoney | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Domain.Events; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Server.Common; | ||
using SharedLibrary; | ||
using SharedLibrary.ResponseArgs.Monopoly; | ||
|
||
namespace Server.Hubs.EventHandlers; | ||
|
||
public class EndRoundEventHandler(IHubContext<MonopolyHub, IMonopolyResponses> hubContext) | ||
: MonopolyEventHandlerBase<EndRoundEvent> | ||
{ | ||
protected override Task HandleSpecificEvent(EndRoundEvent e) | ||
{ | ||
return hubContext.Clients.All.EndRoundEvent(new EndRoundEventArgs | ||
{ | ||
PlayerId = e.PlayerId, | ||
NextPlayerId = e.NextPlayerId | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Domain.Events; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Server.Common; | ||
using SharedLibrary; | ||
using SharedLibrary.ResponseArgs.Monopoly; | ||
|
||
namespace Server.Hubs.EventHandlers; | ||
|
||
public class EndRoundFailEventHandler(IHubContext<MonopolyHub, IMonopolyResponses> hubContext) | ||
: MonopolyEventHandlerBase<EndRoundFailEvent> | ||
{ | ||
protected override Task HandleSpecificEvent(EndRoundFailEvent e) | ||
{ | ||
return hubContext.Clients.All.EndRoundFailEvent(new EndRoundFailEventArgs | ||
{ | ||
PlayerId = e.PlayerId, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Domain.Events; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Server.Common; | ||
using SharedLibrary; | ||
using SharedLibrary.ResponseArgs.Monopoly; | ||
|
||
namespace Server.Hubs.EventHandlers; | ||
|
||
public class GameStartEventHandler(IHubContext<MonopolyHub, IMonopolyResponses> hubContext) | ||
: MonopolyEventHandlerBase<GameStartEvent> | ||
{ | ||
protected override Task HandleSpecificEvent(GameStartEvent e) | ||
{ | ||
return hubContext.Clients.All.GameStartEvent(new GameStartEventArgs | ||
{ | ||
GameStage = e.GameStage, | ||
CurrentPlayerId = e.CurrentPlayerId, | ||
}); | ||
} | ||
} |
Oops, something went wrong.