From 04e741f29b341c24a79def7cfb6793cf164eae11 Mon Sep 17 00:00:00 2001 From: aa89227 Date: Sun, 31 Dec 2023 09:06:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=A7=8BMonopolyEventBus?= =?UTF-8?q?=E3=80=81=E4=BA=8B=E4=BB=B6=E8=99=95=E7=90=86=E5=8F=8A=E6=B8=AC?= =?UTF-8?q?=E8=A9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Client/Pages/Ready/ReadyPage.razor.cs | 3 +- Client/Pages/TypedHubConnection.cs | 9 +- Domain/Events/EndAuctionEvent.cs | 2 +- Domain/Events/GameStartEvent.cs | 4 +- Domain/Events/PlayerBidEvent.cs | 4 +- Domain/Events/PlayerBuildHouseEvent.cs | 4 +- Domain/Events/PlayerBuyBlockEvent.cs | 8 +- Domain/Events/PlayerCanBuildHouseEvent.cs | 2 +- Domain/Events/PlayerCanBuyLandEvent.cs | 2 +- Domain/Events/PlayerMortgageEvent.cs | 4 +- Domain/Events/PlayerPayTollEvent.cs | 6 +- Domain/Events/PlayerRedeemEvent.cs | 2 +- Server/Common/IMonopolyEventHandler.cs | 9 ++ Server/Common/MonopolyEventHandlerBase.cs | 19 +++ Server/DependencyInjection.cs | 23 +++- ...etRewardBecauseStandOnStartEventHandler.cs | 20 +++ .../EventHandlers/ChessMovedEventHandler.cs | 21 +++ .../CurrentPlayerCannotBidEventHandler.cs | 20 +++ .../EventHandlers/EndAuctionEventHandler.cs | 24 ++++ .../EventHandlers/EndRoundEventHandler.cs | 20 +++ .../EventHandlers/EndRoundFailEventHandler.cs | 19 +++ .../EventHandlers/GameStartEventHandler.cs | 20 +++ .../EventHandlers/HouseMaxEventHandler.cs | 22 +++ .../EventHandlers/IMonopolyEventHandler.cs | 8 -- .../EventHandlers/MortgageDueEventHandler.cs | 21 +++ .../OnlyOnePersonEventHandler.cs | 19 +++ .../PlayCannotSelectLocationEventHandler.cs | 20 +++ .../PlaySelectLocationEventHandler.cs | 20 +++ .../EventHandlers/PlayerBidEventHandler.cs | 22 +++ .../PlayerBidFailEventHandler.cs | 23 ++++ .../PlayerBuildHouseEventHandler.cs | 24 ++++ .../PlayerBuyBlockEventHandler.cs | 21 +++ ...erBuyBlockInsufficientFundsEventHandler.cs | 23 ++++ ...yBlockOccupiedByOtherPlayerEventHandler.cs | 22 +++ .../PlayerCanBuildHouseEventHandler.cs | 22 +++ .../PlayerCanBuyLandEventHandler.cs | 20 +++ .../PlayerCannotBuildHouseEventHandler.cs | 21 +++ .../PlayerCannotMortgageEventHandler.cs | 21 +++ .../PlayerCannotReadyEventHandler.cs | 22 +++ .../PlayerChooseDirectionEventHandler.cs | 20 +++ .../PlayerDoesntNeedToPayTollEventHandler.cs | 20 +++ .../PlayerMortgageEventHandler.cs | 22 +++ ...PlayerNeedToChooseDirectionEventHandler.cs | 21 +++ .../PlayerNeedsToPayTollEventHandler.cs | 20 +++ .../PlayerPayTollEventHandler.cs | 22 +++ .../EventHandlers/PlayerReadyEventHandler.cs | 20 +++ .../EventHandlers/PlayerRedeemEventHandler.cs | 21 +++ .../PlayerRollDiceEventHandler.cs | 21 +++ .../PlayerSelectRoleEventHandler.cs | 20 +++ .../PlayerTooPoorToBidEventHandler.cs | 23 ++++ .../PlayerTooPoorToPayTollEventHandler.cs | 21 +++ .../PlayerTooPoorToRedeemEventHandler.cs | 22 +++ .../SomePlayersPreparingEventHandler.cs | 20 +++ .../EventHandlers/SuspendRoundEventHandler.cs | 20 +++ .../EventHandlers/ThroughStartEventHandler.cs | 20 +++ Server/Hubs/MonopolyHub.cs | 16 ++- Server/MonopolyEventBus.cs | 35 +++-- .../SignalrDefaultPresenter.cs | 2 +- Server/Program.cs | 12 +- Server/Services/DevelopmentPlatformService.cs | 29 ++-- Server/Services/IPlatformService.cs | 8 ++ Server/Services/PlatformService.cs | 16 +-- SharedLibrary/IMonopolyResponse.cs | 103 -------------- SharedLibrary/IMonopolyResponses.cs | 94 +++++++++++++ SharedLibrary/MonopolyMap/MonopolyMap.cs | 16 +-- .../ResponseArgs/GetReadyInfoEvent.cs | 30 ----- ...otGetRewardBecauseStandOnStartEventArgs.cs | 6 + .../Monopoly/ChessMovedEventArgs.cs | 9 ++ .../CurrentPlayerCannotBidEventArgs.cs | 6 + .../Monopoly/EndAuctionEventArgs.cs | 10 ++ .../Monopoly/EndRoundEventArgs.cs | 7 + .../Monopoly/EndRoundFailEventArgs.cs | 6 + .../Monopoly/GameStartEventArgs.cs | 7 + .../Monopoly/HouseMaxEventArgs.cs | 8 ++ .../Monopoly/MortgageDueEventArgs.cs | 7 + .../Monopoly/OnlyOnePersonEventArgs.cs | 6 + .../PlayCannotSelectLocationEventArgs.cs | 7 + .../Monopoly/PlaySelectLocationEventArgs.cs | 7 + .../Monopoly/PlayerBankruptEvent.cs | 6 + .../Monopoly/PlayerBidEventArgs.cs | 8 ++ .../Monopoly/PlayerBidFailEventArgs.cs | 9 ++ .../Monopoly/PlayerBuildHouseEventArgs.cs | 9 ++ .../Monopoly/PlayerBuyBlockEventArgs.cs | 7 + ...layerBuyBlockInsufficientFundsEventArgs.cs | 8 ++ ...rBuyBlockOccupiedByOtherPlayerEventArgs.cs | 7 + .../Monopoly/PlayerCanBuildHouseEventArgs.cs | 9 ++ .../Monopoly/PlayerCanBuyLandEventArgs.cs | 8 ++ .../PlayerCannotBuildHouseEventArgs.cs | 7 + .../Monopoly/PlayerCannotMortgageEventArgs.cs | 8 ++ .../Monopoly/PlayerCannotReadyEventArgs.cs | 9 ++ .../PlayerChooseDirectionEventArgs.cs | 7 + .../PlayerDoesntNeedToPayTollEventArgs.cs | 7 + .../Monopoly/PlayerJoinGameEventArgs.cs | 6 + .../Monopoly/PlayerJoinGameFailedEventArgs.cs | 6 + .../Monopoly/PlayerMortgageEventArgs.cs | 9 ++ .../PlayerNeedToChooseDirectionEventArgs.cs | 7 + .../Monopoly/PlayerNeedsToPayTollEventArgs.cs | 8 ++ .../Monopoly/PlayerPayTollEventArgs.cs | 9 ++ .../Monopoly/PlayerReadyEventArgs.cs | 7 + .../Monopoly/PlayerRedeemEventArgs.cs | 8 ++ .../Monopoly/PlayerRolledDiceEventArgs.cs | 7 + .../Monopoly/PlayerSelectRoleEventArgs.cs | 7 + .../Monopoly/PlayerThroughStartEventArgs.cs | 8 ++ .../Monopoly/PlayerTooPoorToBidEventArgs.cs | 9 ++ .../PlayerTooPoorToPayTollEventArgs.cs | 8 ++ .../PlayerTooPoorToRedeemEventArgs.cs | 9 ++ .../Monopoly/SettlementEventArgs.cs | 7 + .../Monopoly/SomePlayersPreparingEventArgs.cs | 7 + .../Monopoly/SuspendRoundEventArgs.cs | 7 + .../ResponseArgs/PlayerBankruptEvent.cs | 6 - .../ReadyRoom/GetReadyInfoEventArgs.cs | 30 +++++ .../ReadyRoom/WelcomeEventArgs.cs | 5 + SharedLibrary/ResponseArgs/WelcomeEvent.cs | 5 - Test/DomainTests/Utils.cs | 4 +- .../AcceptanceTests/AuctionTest.cs | 51 +++---- .../AcceptanceTests/BuildHouseTest.cs | 40 +++--- .../AcceptanceTests/BuyBlockTest.cs | 16 +-- .../AcceptanceTests/EndRoundTest.cs | 50 +++---- .../AcceptanceTests/GameStartTest.cs | 13 +- .../AcceptanceTests/MortgageTest.cs | 20 ++- .../AcceptanceTests/PayTollTest.cs | 31 ++--- .../AcceptanceTests/PlayerJoinGameTest.cs | 6 +- .../AcceptanceTests/PreparedTest.cs | 18 +-- .../ServerTests/AcceptanceTests/RedeemTest.cs | 14 +- .../AcceptanceTests/RollDiceTest.cs | 126 +++++++++--------- .../AcceptanceTests/SelectDirectionTest.cs | 13 +- .../AcceptanceTests/SelectLocation.cs | 13 +- .../AcceptanceTests/SelectRoleTest.cs | 9 +- Test/ServerTests/MonopolyTestServer.cs | 84 ++++++------ Test/ServerTests/Utils.cs | 5 +- 130 files changed, 1647 insertions(+), 526 deletions(-) create mode 100644 Server/Common/IMonopolyEventHandler.cs create mode 100644 Server/Common/MonopolyEventHandlerBase.cs create mode 100644 Server/Hubs/EventHandlers/CannotGetRewardBecauseStandOnStartEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/ChessMovedEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/CurrentPlayerCannotBidEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/EndAuctionEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/EndRoundEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/EndRoundFailEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/GameStartEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/HouseMaxEventHandler.cs delete mode 100644 Server/Hubs/EventHandlers/IMonopolyEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/MortgageDueEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/OnlyOnePersonEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayCannotSelectLocationEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlaySelectLocationEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerBidEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerBidFailEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerBuildHouseEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerBuyBlockEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerBuyBlockInsufficientFundsEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerBuyBlockOccupiedByOtherPlayerEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerCanBuildHouseEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerCanBuyLandEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerCannotBuildHouseEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerCannotMortgageEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerCannotReadyEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerChooseDirectionEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerDoesntNeedToPayTollEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerMortgageEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerNeedToChooseDirectionEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerNeedsToPayTollEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerPayTollEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerReadyEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerRedeemEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerRollDiceEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerSelectRoleEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerTooPoorToBidEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerTooPoorToPayTollEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/PlayerTooPoorToRedeemEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/SomePlayersPreparingEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/SuspendRoundEventHandler.cs create mode 100644 Server/Hubs/EventHandlers/ThroughStartEventHandler.cs rename Server/{Hubs => Presenters}/SignalrDefaultPresenter.cs (91%) create mode 100644 Server/Services/IPlatformService.cs delete mode 100644 SharedLibrary/IMonopolyResponse.cs create mode 100644 SharedLibrary/IMonopolyResponses.cs delete mode 100644 SharedLibrary/ResponseArgs/GetReadyInfoEvent.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/CannotGetRewardBecauseStandOnStartEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/ChessMovedEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/CurrentPlayerCannotBidEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/EndAuctionEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/EndRoundEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/EndRoundFailEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/GameStartEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/HouseMaxEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/MortgageDueEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/OnlyOnePersonEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayCannotSelectLocationEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlaySelectLocationEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerBankruptEvent.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerBidEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerBidFailEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerBuildHouseEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockInsufficientFundsEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockOccupiedByOtherPlayerEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerCanBuildHouseEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerCanBuyLandEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerCannotBuildHouseEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerCannotMortgageEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerCannotReadyEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerChooseDirectionEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerDoesntNeedToPayTollEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerJoinGameEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerJoinGameFailedEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerMortgageEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerNeedToChooseDirectionEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerNeedsToPayTollEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerPayTollEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerReadyEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerRedeemEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerRolledDiceEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerSelectRoleEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerThroughStartEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToBidEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToPayTollEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToRedeemEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/SettlementEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/SomePlayersPreparingEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/Monopoly/SuspendRoundEventArgs.cs delete mode 100644 SharedLibrary/ResponseArgs/PlayerBankruptEvent.cs create mode 100644 SharedLibrary/ResponseArgs/ReadyRoom/GetReadyInfoEventArgs.cs create mode 100644 SharedLibrary/ResponseArgs/ReadyRoom/WelcomeEventArgs.cs delete mode 100644 SharedLibrary/ResponseArgs/WelcomeEvent.cs diff --git a/Client/Pages/Ready/ReadyPage.razor.cs b/Client/Pages/Ready/ReadyPage.razor.cs index aaa5a72..dbc8a05 100644 --- a/Client/Pages/Ready/ReadyPage.razor.cs +++ b/Client/Pages/Ready/ReadyPage.razor.cs @@ -1,6 +1,7 @@ using Client.Pages.Ready.Entities; using Microsoft.AspNetCore.Components; using SharedLibrary.ResponseArgs; +using SharedLibrary.ResponseArgs.ReadyRoom; namespace Client.Pages.Ready; @@ -28,7 +29,7 @@ private void OnPlayerJoinGameEvent(PlayerJoinGameEvent e) Players = Players.Append(player).ToList(); Update(); } - private void OnGetReadyInfoEvent(GetReadyInfoEvent e) + private void OnGetReadyInfoEvent(GetReadyInfoEventArgs e) { Players = e.Players.Select(x => new Player { diff --git a/Client/Pages/TypedHubConnection.cs b/Client/Pages/TypedHubConnection.cs index 8891c15..eecffa1 100644 --- a/Client/Pages/TypedHubConnection.cs +++ b/Client/Pages/TypedHubConnection.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.SignalR.Client; using SharedLibrary.ResponseArgs; +using SharedLibrary.ResponseArgs.ReadyRoom; namespace Client.Pages; @@ -10,15 +11,15 @@ internal class TypedHubConnection public event PlayerJoinGameEventDelegate? PlayerJoinGameEventHandler; public delegate void PlayerJoinGameEventDelegate(PlayerJoinGameEvent e); public event GetReadyInfoEventDelegate? GetReadyInfoEventHandler; - public delegate void GetReadyInfoEventDelegate(GetReadyInfoEvent e); + public delegate void GetReadyInfoEventDelegate(GetReadyInfoEventArgs e); public event WelcomeEventDelegate? WelcomeEventHandler; - public delegate void WelcomeEventDelegate(WelcomeEvent e); + public delegate void WelcomeEventDelegate(WelcomeEventArgs e); public TypedHubConnection(HubConnection hubConnection) { hubConnection.On(nameof(PlayerJoinGameEvent), (e) => PlayerJoinGameEventHandler?.Invoke(e)); - hubConnection.On(nameof(GetReadyInfoEvent), (e) => GetReadyInfoEventHandler?.Invoke(e)); - hubConnection.On(nameof(WelcomeEvent), (e) => WelcomeEventHandler?.Invoke(e)); + hubConnection.On(nameof(GetReadyInfoEventArgs), (e) => GetReadyInfoEventHandler?.Invoke(e)); + hubConnection.On(nameof(WelcomeEventArgs), (e) => WelcomeEventHandler?.Invoke(e)); this.hubConnection = hubConnection; } public async Task GetReadyInfo() => await hubConnection.SendAsync("GetReadyInfo"); diff --git a/Domain/Events/EndAuctionEvent.cs b/Domain/Events/EndAuctionEvent.cs index 603f002..a8a2833 100644 --- a/Domain/Events/EndAuctionEvent.cs +++ b/Domain/Events/EndAuctionEvent.cs @@ -2,5 +2,5 @@ namespace Domain.Events; -public record EndAuctionEvent(string PlayerId, decimal PlayerMoney, string BlockId, string? Owner, decimal OwnerMoney) +public record EndAuctionEvent(string PlayerId, decimal PlayerMoney, string LandId, string? OwnerId, decimal OwnerMoney) : DomainEvent; \ No newline at end of file diff --git a/Domain/Events/GameStartEvent.cs b/Domain/Events/GameStartEvent.cs index 28357e3..b9d64c6 100644 --- a/Domain/Events/GameStartEvent.cs +++ b/Domain/Events/GameStartEvent.cs @@ -2,11 +2,11 @@ namespace Domain.Events; -public record GameStartEvent(string GameStage, string CurrentPlayer) +public record GameStartEvent(string GameStage, string CurrentPlayerId) : DomainEvent; public record OnlyOnePersonEvent(string GameStage) : DomainEvent; -public record SomePlayersPreparingEvent(string GameStage, params string[] Players) +public record SomePlayersPreparingEvent(string GameStage, params string[] PlayerIds) : DomainEvent; \ No newline at end of file diff --git a/Domain/Events/PlayerBidEvent.cs b/Domain/Events/PlayerBidEvent.cs index 74439fc..a8ad81d 100644 --- a/Domain/Events/PlayerBidEvent.cs +++ b/Domain/Events/PlayerBidEvent.cs @@ -2,9 +2,9 @@ namespace Domain.Events; -public record PlayerBidEvent(string PlayerId, string BlockId, decimal HighestPrice) : DomainEvent; +public record PlayerBidEvent(string PlayerId, string LandId, decimal HighestPrice) : DomainEvent; -public record PlayerBidFailEvent(string PlayerId, string BlockId, decimal BidPrice, decimal HighestPrice) : DomainEvent; +public record PlayerBidFailEvent(string PlayerId, string LandId, decimal BidPrice, decimal HighestPrice) : DomainEvent; public record PlayerTooPoorToBidEvent(string PlayerId, decimal PlayerMoney, decimal BidPrice, decimal HighestPrice) : DomainEvent; diff --git a/Domain/Events/PlayerBuildHouseEvent.cs b/Domain/Events/PlayerBuildHouseEvent.cs index 986ef32..aa7a533 100644 --- a/Domain/Events/PlayerBuildHouseEvent.cs +++ b/Domain/Events/PlayerBuildHouseEvent.cs @@ -2,10 +2,10 @@ namespace Domain.Events; -public record PlayerBuildHouseEvent(string PlayerId, string BlockId, decimal PlayerMoney, int House) +public record PlayerBuildHouseEvent(string PlayerId, string LandId, decimal PlayerMoney, int HouseCount) : DomainEvent; -public record PlayerCannotBuildHouseEvent(string PlayerId, string BlockId) +public record PlayerCannotBuildHouseEvent(string PlayerId, string LandId) : DomainEvent; public record PlayerTooPoorToBuildHouseEvent(string PlayerId, string BlockId, decimal PlayerMoney, decimal UpgradePrice) diff --git a/Domain/Events/PlayerBuyBlockEvent.cs b/Domain/Events/PlayerBuyBlockEvent.cs index 802da6a..cf19a87 100644 --- a/Domain/Events/PlayerBuyBlockEvent.cs +++ b/Domain/Events/PlayerBuyBlockEvent.cs @@ -2,17 +2,17 @@ namespace Domain.Events; -public record PlayerBuyBlockEvent(string PlayerId, string BlockId) +public record PlayerBuyBlockEvent(string PlayerId, string LandId) : DomainEvent; public record PlayerBuyBlockMissedLandEvent(string PlayerId, string BlockId) : DomainEvent; -public record PlayerBuyBlockOccupiedByOtherPlayerEvent(string PlayerId, string BlockId) +public record PlayerBuyBlockOccupiedByOtherPlayerEvent(string PlayerId, string LandId) : DomainEvent; -public record PlayerBuyBlockInsufficientFundsEvent(string PlayerId, string BlockId, decimal landMoney) +public record PlayerBuyBlockInsufficientFundsEvent(string PlayerId, string LandId, decimal Price) : DomainEvent; -public record HouseMaxEvent(string PlayerId, string BlockId, int House) +public record HouseMaxEvent(string PlayerId, string LandId, int HouseCount) : DomainEvent; \ No newline at end of file diff --git a/Domain/Events/PlayerCanBuildHouseEvent.cs b/Domain/Events/PlayerCanBuildHouseEvent.cs index 6bc66a8..b0b64e0 100644 --- a/Domain/Events/PlayerCanBuildHouseEvent.cs +++ b/Domain/Events/PlayerCanBuildHouseEvent.cs @@ -2,4 +2,4 @@ namespace Domain.Events; -public record PlayerCanBuildHouseEvent(string PlayerId, string BlockId, int HouseCount, decimal UpgradeMoney) : DomainEvent; \ No newline at end of file +public record PlayerCanBuildHouseEvent(string PlayerId, string LandId, int HouseCount, decimal UpgradePrice) : DomainEvent; \ No newline at end of file diff --git a/Domain/Events/PlayerCanBuyLandEvent.cs b/Domain/Events/PlayerCanBuyLandEvent.cs index 3bb96e7..bbbd767 100644 --- a/Domain/Events/PlayerCanBuyLandEvent.cs +++ b/Domain/Events/PlayerCanBuyLandEvent.cs @@ -2,5 +2,5 @@ namespace Domain.Events; -public record PlayerCanBuyLandEvent(string PlayerId, string BlockId, decimal landMoney) +public record PlayerCanBuyLandEvent(string PlayerId, string LandId, decimal Price) : DomainEvent; \ No newline at end of file diff --git a/Domain/Events/PlayerMortgageEvent.cs b/Domain/Events/PlayerMortgageEvent.cs index 7ee8cad..78d580c 100644 --- a/Domain/Events/PlayerMortgageEvent.cs +++ b/Domain/Events/PlayerMortgageEvent.cs @@ -5,10 +5,10 @@ namespace Domain.Events; public record PlayerMortgageEvent(string PlayerId, decimal PlayerMoney, string BlockId, int DeadLine) : DomainEvent; -public record PlayerCannotMortgageEvent(string PlayerId, decimal PlayerMoney, string BlockId) +public record PlayerCannotMortgageEvent(string PlayerId, decimal PlayerMoney, string LandId) : DomainEvent; -public record MortgageDueEvent(string PlayerId, string BlockId) +public record MortgageDueEvent(string PlayerId, string LandId) : DomainEvent; public record MortgageCountdownEvent(string PlayerId, string BlockId, int DeadLine) diff --git a/Domain/Events/PlayerPayTollEvent.cs b/Domain/Events/PlayerPayTollEvent.cs index 47ee1ff..244a33b 100644 --- a/Domain/Events/PlayerPayTollEvent.cs +++ b/Domain/Events/PlayerPayTollEvent.cs @@ -2,10 +2,10 @@ namespace Domain.Events; -public record PlayerNeedsToPayTollEvent(string PlayerId, string ownerId, decimal toll) : DomainEvent; +public record PlayerNeedsToPayTollEvent(string PlayerId, string OwnerId, decimal Toll) : DomainEvent; -public record PlayerPayTollEvent(string PlayerId, decimal PlayerMoney, string ownerId, decimal ownerMoney) : DomainEvent; +public record PlayerPayTollEvent(string PlayerId, decimal PlayerMoney, string OwnerId, decimal OwnerMoney) : DomainEvent; public record PlayerDoesntNeedToPayTollEvent(string PlayerId, decimal PlayerMoney) : DomainEvent; -public record PlayerTooPoorToPayTollEvent(string PlayerId, decimal PlayerMoney, decimal toll) : DomainEvent; \ No newline at end of file +public record PlayerTooPoorToPayTollEvent(string PlayerId, decimal PlayerMoney, decimal Toll) : DomainEvent; \ No newline at end of file diff --git a/Domain/Events/PlayerRedeemEvent.cs b/Domain/Events/PlayerRedeemEvent.cs index 8932d2e..845c509 100644 --- a/Domain/Events/PlayerRedeemEvent.cs +++ b/Domain/Events/PlayerRedeemEvent.cs @@ -2,7 +2,7 @@ namespace Domain.Events; -public record PlayerRedeemEvent(string PlayerId, decimal PlayerMoney, string BlockId) : DomainEvent; +public record PlayerRedeemEvent(string PlayerId, decimal PlayerMoney, string LandId) : DomainEvent; public record PlayerTooPoorToRedeemEvent(string PlayerId, decimal PlayerMoney, string BlockId, decimal RedeemPrice) : DomainEvent; diff --git a/Server/Common/IMonopolyEventHandler.cs b/Server/Common/IMonopolyEventHandler.cs new file mode 100644 index 0000000..e5085f1 --- /dev/null +++ b/Server/Common/IMonopolyEventHandler.cs @@ -0,0 +1,9 @@ +using Domain.Common; + +namespace Server.Common; + +internal interface IMonopolyEventHandler +{ + public Type EventType { get; } + Task HandleAsync(DomainEvent e); +} \ No newline at end of file diff --git a/Server/Common/MonopolyEventHandlerBase.cs b/Server/Common/MonopolyEventHandlerBase.cs new file mode 100644 index 0000000..6d0aae0 --- /dev/null +++ b/Server/Common/MonopolyEventHandlerBase.cs @@ -0,0 +1,19 @@ +using Domain.Common; + +namespace Server.Common; + +public abstract class MonopolyEventHandlerBase : 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); +} \ No newline at end of file diff --git a/Server/DependencyInjection.cs b/Server/DependencyInjection.cs index 46232de..5956d4b 100644 --- a/Server/DependencyInjection.cs +++ b/Server/DependencyInjection.cs @@ -1,6 +1,9 @@ -using Application.Common; +using System.Reflection; +using Application.Common; using Domain.Common; +using Server.Common; using Server.Hubs; +using Server.Presenters; using Server.Repositories; namespace Server; @@ -10,8 +13,22 @@ public static class DependencyInjection public static IServiceCollection AddMonopolyServer(this IServiceCollection services) { services.AddSingleton() - .AddScoped, MonopolyEventBus>() + .AddSingleton, MonopolyEventBus>() .AddTransient(typeof(SignalrDefaultPresenter<>), typeof(SignalrDefaultPresenter<>)); + services.AddSignalREventHandlers(); return services; } -} \ No newline at end of file + + private static IServiceCollection AddSignalREventHandlers(this IServiceCollection services) + { + var handlers = Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t is { IsClass: true, IsAbstract: false } + && t.IsAssignableTo(typeof(IMonopolyEventHandler))) + .ToList(); + foreach (var handler in handlers) + { + services.AddSingleton(typeof(IMonopolyEventHandler), handler); + } + return services; + } +} diff --git a/Server/Hubs/EventHandlers/CannotGetRewardBecauseStandOnStartEventHandler.cs b/Server/Hubs/EventHandlers/CannotGetRewardBecauseStandOnStartEventHandler.cs new file mode 100644 index 0000000..75d9878 --- /dev/null +++ b/Server/Hubs/EventHandlers/CannotGetRewardBecauseStandOnStartEventHandler.cs @@ -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 hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(CannotGetRewardBecauseStandOnStartEvent e) + { + return hubContext.Clients.All.CannotGetRewardBecauseStandOnStartEvent( + new CannotGetRewardBecauseStandOnStartEventArgs + { + PlayerId = e.PlayerId + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/ChessMovedEventHandler.cs b/Server/Hubs/EventHandlers/ChessMovedEventHandler.cs new file mode 100644 index 0000000..4c16d6b --- /dev/null +++ b/Server/Hubs/EventHandlers/ChessMovedEventHandler.cs @@ -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 hubContext) : MonopolyEventHandlerBase +{ + 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 + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/CurrentPlayerCannotBidEventHandler.cs b/Server/Hubs/EventHandlers/CurrentPlayerCannotBidEventHandler.cs new file mode 100644 index 0000000..a185fa9 --- /dev/null +++ b/Server/Hubs/EventHandlers/CurrentPlayerCannotBidEventHandler.cs @@ -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 hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(CurrentPlayerCannotBidEvent e) + { + return hubContext.Clients.All.CurrentPlayerCannotBidEvent( + new CurrentPlayerCannotBidEventArgs + { + PlayerId = e.PlayerId + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/EndAuctionEventHandler.cs b/Server/Hubs/EventHandlers/EndAuctionEventHandler.cs new file mode 100644 index 0000000..d576b2e --- /dev/null +++ b/Server/Hubs/EventHandlers/EndAuctionEventHandler.cs @@ -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 hubContext) + : MonopolyEventHandlerBase +{ + 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 + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/EndRoundEventHandler.cs b/Server/Hubs/EventHandlers/EndRoundEventHandler.cs new file mode 100644 index 0000000..a0c70a9 --- /dev/null +++ b/Server/Hubs/EventHandlers/EndRoundEventHandler.cs @@ -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 hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(EndRoundEvent e) + { + return hubContext.Clients.All.EndRoundEvent(new EndRoundEventArgs + { + PlayerId = e.PlayerId, + NextPlayerId = e.NextPlayerId + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/EndRoundFailEventHandler.cs b/Server/Hubs/EventHandlers/EndRoundFailEventHandler.cs new file mode 100644 index 0000000..975c290 --- /dev/null +++ b/Server/Hubs/EventHandlers/EndRoundFailEventHandler.cs @@ -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 hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(EndRoundFailEvent e) + { + return hubContext.Clients.All.EndRoundFailEvent(new EndRoundFailEventArgs + { + PlayerId = e.PlayerId, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/GameStartEventHandler.cs b/Server/Hubs/EventHandlers/GameStartEventHandler.cs new file mode 100644 index 0000000..ace26a1 --- /dev/null +++ b/Server/Hubs/EventHandlers/GameStartEventHandler.cs @@ -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 hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(GameStartEvent e) + { + return hubContext.Clients.All.GameStartEvent(new GameStartEventArgs + { + GameStage = e.GameStage, + CurrentPlayerId = e.CurrentPlayerId, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/HouseMaxEventHandler.cs b/Server/Hubs/EventHandlers/HouseMaxEventHandler.cs new file mode 100644 index 0000000..d41a67f --- /dev/null +++ b/Server/Hubs/EventHandlers/HouseMaxEventHandler.cs @@ -0,0 +1,22 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class HouseMaxEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(HouseMaxEvent e) + { + return hubContext.Clients.All.HouseMaxEvent( + new HouseMaxEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + HouseCount = e.HouseCount + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/IMonopolyEventHandler.cs b/Server/Hubs/EventHandlers/IMonopolyEventHandler.cs deleted file mode 100644 index ebec956..0000000 --- a/Server/Hubs/EventHandlers/IMonopolyEventHandler.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Domain.Common; - -namespace Server.Hubs.EventHandlers; - -internal interface IMonopolyEventHandler where TEvent : DomainEvent -{ - Task Handle(TEvent e); -} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/MortgageDueEventHandler.cs b/Server/Hubs/EventHandlers/MortgageDueEventHandler.cs new file mode 100644 index 0000000..4e51e52 --- /dev/null +++ b/Server/Hubs/EventHandlers/MortgageDueEventHandler.cs @@ -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 MortgageDueEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(MortgageDueEvent e) + { + return hubContext.Clients.All.MortgageDueEvent( + new MortgageDueEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/OnlyOnePersonEventHandler.cs b/Server/Hubs/EventHandlers/OnlyOnePersonEventHandler.cs new file mode 100644 index 0000000..d067e2b --- /dev/null +++ b/Server/Hubs/EventHandlers/OnlyOnePersonEventHandler.cs @@ -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 OnlyOnePersonEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(OnlyOnePersonEvent e) + { + return hubContext.Clients.All.OnlyOnePersonEvent(new OnlyOnePersonEventArgs + { + GameStage = e.GameStage, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayCannotSelectLocationEventHandler.cs b/Server/Hubs/EventHandlers/PlayCannotSelectLocationEventHandler.cs new file mode 100644 index 0000000..d902860 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayCannotSelectLocationEventHandler.cs @@ -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 PlayCannotSelectLocationEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayCannotSelectLocationEvent e) + { + return hubContext.Clients.All.PlayCannotSelectLocationEvent(new PlayCannotSelectLocationEventArgs + { + PlayerId = e.PlayerId, + LocationId = e.LocationId + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlaySelectLocationEventHandler.cs b/Server/Hubs/EventHandlers/PlaySelectLocationEventHandler.cs new file mode 100644 index 0000000..72278db --- /dev/null +++ b/Server/Hubs/EventHandlers/PlaySelectLocationEventHandler.cs @@ -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 PlaySelectLocationEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlaySelectLocationEvent e) + { + return hubContext.Clients.All.PlaySelectLocationEvent(new PlaySelectLocationEventArgs + { + PlayerId = e.PlayerId, + LocationId = e.LocationId, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerBidEventHandler.cs b/Server/Hubs/EventHandlers/PlayerBidEventHandler.cs new file mode 100644 index 0000000..c519569 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerBidEventHandler.cs @@ -0,0 +1,22 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerBidEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerBidEvent e) + { + return hubContext.Clients.All.PlayerBidEvent( + new PlayerBidEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + HighestPrice = e.HighestPrice + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerBidFailEventHandler.cs b/Server/Hubs/EventHandlers/PlayerBidFailEventHandler.cs new file mode 100644 index 0000000..0a9b6f8 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerBidFailEventHandler.cs @@ -0,0 +1,23 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerBidFailEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerBidFailEvent e) + { + return hubContext.Clients.All.PlayerBidFailEvent( + new PlayerBidFailEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + BidPrice = e.BidPrice, + HighestPrice = e.HighestPrice + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerBuildHouseEventHandler.cs b/Server/Hubs/EventHandlers/PlayerBuildHouseEventHandler.cs new file mode 100644 index 0000000..77068ab --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerBuildHouseEventHandler.cs @@ -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 PlayerBuildHouseEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerBuildHouseEvent e) + { + return hubContext.Clients.All.PlayerBuildHouseEvent( + new PlayerBuildHouseEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + PlayerMoney = e.PlayerMoney, + HouseCount = e.HouseCount + } + ); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerBuyBlockEventHandler.cs b/Server/Hubs/EventHandlers/PlayerBuyBlockEventHandler.cs new file mode 100644 index 0000000..9280dd9 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerBuyBlockEventHandler.cs @@ -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 PlayerBuyBlockEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerBuyBlockEvent e) + { + return hubContext.Clients.All.PlayerBuyBlockEvent( + new PlayerBuyBlockEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerBuyBlockInsufficientFundsEventHandler.cs b/Server/Hubs/EventHandlers/PlayerBuyBlockInsufficientFundsEventHandler.cs new file mode 100644 index 0000000..a98076e --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerBuyBlockInsufficientFundsEventHandler.cs @@ -0,0 +1,23 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerBuyBlockInsufficientFundsEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerBuyBlockInsufficientFundsEvent e) + { + return hubContext.Clients.All.PlayerBuyBlockInsufficientFundsEvent( + new PlayerBuyBlockInsufficientFundsEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + Price = e.Price, + } + ); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerBuyBlockOccupiedByOtherPlayerEventHandler.cs b/Server/Hubs/EventHandlers/PlayerBuyBlockOccupiedByOtherPlayerEventHandler.cs new file mode 100644 index 0000000..d042696 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerBuyBlockOccupiedByOtherPlayerEventHandler.cs @@ -0,0 +1,22 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerBuyBlockOccupiedByOtherPlayerEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerBuyBlockOccupiedByOtherPlayerEvent e) + { + return hubContext.Clients.All.PlayerBuyBlockOccupiedByOtherPlayerEvent( + new PlayerBuyBlockOccupiedByOtherPlayerEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + } + ); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerCanBuildHouseEventHandler.cs b/Server/Hubs/EventHandlers/PlayerCanBuildHouseEventHandler.cs new file mode 100644 index 0000000..c86bbd4 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerCanBuildHouseEventHandler.cs @@ -0,0 +1,22 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerCanBuildHouseEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerCanBuildHouseEvent e) + { + return hubContext.Clients.All.PlayerCanBuildHouseEvent(new PlayerCanBuildHouseEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + HouseCount = e.HouseCount, + Price = e.UpgradePrice + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerCanBuyLandEventHandler.cs b/Server/Hubs/EventHandlers/PlayerCanBuyLandEventHandler.cs new file mode 100644 index 0000000..47a2262 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerCanBuyLandEventHandler.cs @@ -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 PlayerCanBuyLandEventHandler(IHubContext hubContext) : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerCanBuyLandEvent e) + { + return hubContext.Clients.All.PlayerCanBuyLandEvent(new PlayerCanBuyLandEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + Price = e.Price + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerCannotBuildHouseEventHandler.cs b/Server/Hubs/EventHandlers/PlayerCannotBuildHouseEventHandler.cs new file mode 100644 index 0000000..f49232f --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerCannotBuildHouseEventHandler.cs @@ -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 PlayerCannotBuildHouseEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerCannotBuildHouseEvent e) + { + return hubContext.Clients.All.PlayerCannotBuildHouseEvent( + new PlayerCannotBuildHouseEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerCannotMortgageEventHandler.cs b/Server/Hubs/EventHandlers/PlayerCannotMortgageEventHandler.cs new file mode 100644 index 0000000..0ff8a89 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerCannotMortgageEventHandler.cs @@ -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 PlayerCannotMortgageEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerCannotMortgageEvent e) + { + return hubContext.Clients.All.PlayerCannotMortgageEvent(new PlayerCannotMortgageEventArgs + { + PlayerId = e.PlayerId, + LandId = e.LandId, + PlayerMoney = e.PlayerMoney, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerCannotReadyEventHandler.cs b/Server/Hubs/EventHandlers/PlayerCannotReadyEventHandler.cs new file mode 100644 index 0000000..828f09c --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerCannotReadyEventHandler.cs @@ -0,0 +1,22 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerCannotReadyEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerCannotReadyEvent e) + { + return hubContext.Clients.All.PlayerCannotReadyEvent(new PlayerCannotReadyEventArgs + { + PlayerId = e.PlayerId, + PlayerState = e.PlayerState, + RoleId = e.RoleId, + LocationId = e.LocationId + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerChooseDirectionEventHandler.cs b/Server/Hubs/EventHandlers/PlayerChooseDirectionEventHandler.cs new file mode 100644 index 0000000..89e6e5e --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerChooseDirectionEventHandler.cs @@ -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 PlayerChooseDirectionEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerChooseDirectionEvent e) + { + return hubContext.Clients.All.PlayerChooseDirectionEvent(new PlayerChooseDirectionEventArgs + { + PlayerId = e.PlayerId, + Direction = e.Direction, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerDoesntNeedToPayTollEventHandler.cs b/Server/Hubs/EventHandlers/PlayerDoesntNeedToPayTollEventHandler.cs new file mode 100644 index 0000000..faf8fc4 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerDoesntNeedToPayTollEventHandler.cs @@ -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 PlayerDoesntNeedToPayTollEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerDoesntNeedToPayTollEvent e) + { + return hubContext.Clients.All.PlayerDoesntNeedToPayTollEvent(new PlayerDoesntNeedToPayTollEventArgs + { + PlayerId = e.PlayerId, + PlayerMoney = e.PlayerMoney + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerMortgageEventHandler.cs b/Server/Hubs/EventHandlers/PlayerMortgageEventHandler.cs new file mode 100644 index 0000000..511d967 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerMortgageEventHandler.cs @@ -0,0 +1,22 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerMortgageEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerMortgageEvent e) + { + return hubContext.Clients.All.PlayerMortgageEvent(new PlayerMortgageEventArgs + { + PlayerId = e.PlayerId, + LandId = e.BlockId, + PlayerMoney = e.PlayerMoney, + DeadLine = e.DeadLine, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerNeedToChooseDirectionEventHandler.cs b/Server/Hubs/EventHandlers/PlayerNeedToChooseDirectionEventHandler.cs new file mode 100644 index 0000000..2c3a9fd --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerNeedToChooseDirectionEventHandler.cs @@ -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 PlayerNeedToChooseDirectionEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerNeedToChooseDirectionEvent e) + { + return hubContext.Clients.All.PlayerNeedToChooseDirectionEvent( + new PlayerNeedToChooseDirectionEventArgs + { + PlayerId = e.PlayerId, + Directions = e.Directions + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerNeedsToPayTollEventHandler.cs b/Server/Hubs/EventHandlers/PlayerNeedsToPayTollEventHandler.cs new file mode 100644 index 0000000..831c6fc --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerNeedsToPayTollEventHandler.cs @@ -0,0 +1,20 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; + +namespace Server.Hubs.EventHandlers; + +public class PlayerNeedsToPayTollEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerNeedsToPayTollEvent e) + { + return hubContext.Clients.All.PlayerNeedsToPayTollEvent(new PlayerNeedsToPayTollEventArgs + { + PlayerId = e.PlayerId, + OwnerId = e.OwnerId, + Toll = e.Toll + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerPayTollEventHandler.cs b/Server/Hubs/EventHandlers/PlayerPayTollEventHandler.cs new file mode 100644 index 0000000..8485d92 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerPayTollEventHandler.cs @@ -0,0 +1,22 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerPayTollEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerPayTollEvent e) + { + return hubContext.Clients.All.PlayerPayTollEvent(new PlayerPayTollEventArgs + { + PlayerId = e.PlayerId, + PlayerMoney = e.PlayerMoney, + OwnerId = e.OwnerId, + OwnerMoney = e.OwnerMoney, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerReadyEventHandler.cs b/Server/Hubs/EventHandlers/PlayerReadyEventHandler.cs new file mode 100644 index 0000000..88b3651 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerReadyEventHandler.cs @@ -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 PlayerReadyEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerReadyEvent e) + { + return hubContext.Clients.All.PlayerReadyEvent(new PlayerReadyEventArgs + { + PlayerId = e.PlayerId, + PlayerState = e.PlayerState + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerRedeemEventHandler.cs b/Server/Hubs/EventHandlers/PlayerRedeemEventHandler.cs new file mode 100644 index 0000000..54829d3 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerRedeemEventHandler.cs @@ -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 PlayerRedeemEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerRedeemEvent e) + { + return hubContext.Clients.All.PlayerRedeemEvent(new PlayerRedeemEventArgs + { + PlayerId = e.PlayerId, + PlayerMoney = e.PlayerMoney, + LandId = e.LandId, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerRollDiceEventHandler.cs b/Server/Hubs/EventHandlers/PlayerRollDiceEventHandler.cs new file mode 100644 index 0000000..62dea41 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerRollDiceEventHandler.cs @@ -0,0 +1,21 @@ +using Domain.Common; +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using PlayerRolledDiceEventArgs = SharedLibrary.ResponseArgs.Monopoly.PlayerRolledDiceEventArgs; + +namespace Server.Hubs.EventHandlers; + +public class PlayerRollDiceEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerRolledDiceEvent e) + { + return hubContext.Clients.All.PlayerRolledDiceEvent(new PlayerRolledDiceEventArgs + { + PlayerId = e.PlayerId, + DiceCount = e.DiceCount + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerSelectRoleEventHandler.cs b/Server/Hubs/EventHandlers/PlayerSelectRoleEventHandler.cs new file mode 100644 index 0000000..a66e470 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerSelectRoleEventHandler.cs @@ -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 PlayerSelectRoleEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerSelectRoleEvent e) + { + return hubContext.Clients.All.PlayerSelectRoleEvent(new PlayerSelectRoleEventArgs + { + PlayerId = e.PlayerId, + RoleId = e.RoleId, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerTooPoorToBidEventHandler.cs b/Server/Hubs/EventHandlers/PlayerTooPoorToBidEventHandler.cs new file mode 100644 index 0000000..c475854 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerTooPoorToBidEventHandler.cs @@ -0,0 +1,23 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerTooPoorToBidEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerTooPoorToBidEvent e) + { + return hubContext.Clients.All.PlayerTooPoorToBidEvent( + new PlayerTooPoorToBidEventArgs + { + PlayerId = e.PlayerId, + PlayerMoney = e.PlayerMoney, + BidPrice = e.BidPrice, + HighestPrice = e.HighestPrice + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerTooPoorToPayTollEventHandler.cs b/Server/Hubs/EventHandlers/PlayerTooPoorToPayTollEventHandler.cs new file mode 100644 index 0000000..c2288ea --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerTooPoorToPayTollEventHandler.cs @@ -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 PlayerTooPoorToPayTollEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerTooPoorToPayTollEvent e) + { + return hubContext.Clients.All.PlayerTooPoorToPayTollEvent(new PlayerTooPoorToPayTollEventArgs + { + PlayerId = e.PlayerId, + PlayerMoney = e.PlayerMoney, + Toll = e.Toll, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/PlayerTooPoorToRedeemEventHandler.cs b/Server/Hubs/EventHandlers/PlayerTooPoorToRedeemEventHandler.cs new file mode 100644 index 0000000..0c637d7 --- /dev/null +++ b/Server/Hubs/EventHandlers/PlayerTooPoorToRedeemEventHandler.cs @@ -0,0 +1,22 @@ +using Domain.Events; +using Microsoft.AspNetCore.SignalR; +using Server.Common; +using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; + +namespace Server.Hubs.EventHandlers; + +public class PlayerTooPoorToRedeemEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(PlayerTooPoorToRedeemEvent e) + { + return hubContext.Clients.All.PlayerTooPoorToRedeemEvent(new PlayerTooPoorToRedeemEventArgs + { + PlayerId = e.PlayerId, + PlayerMoney = e.PlayerMoney, + LandId = e.BlockId, + RedeemPrice = e.RedeemPrice, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/SomePlayersPreparingEventHandler.cs b/Server/Hubs/EventHandlers/SomePlayersPreparingEventHandler.cs new file mode 100644 index 0000000..dda8f6f --- /dev/null +++ b/Server/Hubs/EventHandlers/SomePlayersPreparingEventHandler.cs @@ -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 SomePlayersPreparingEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(SomePlayersPreparingEvent e) + { + return hubContext.Clients.All.SomePlayersPreparingEvent(new SomePlayersPreparingEventArgs + { + GameStage = e.GameStage, + PlayerIds = e.PlayerIds, + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/SuspendRoundEventHandler.cs b/Server/Hubs/EventHandlers/SuspendRoundEventHandler.cs new file mode 100644 index 0000000..6012ba4 --- /dev/null +++ b/Server/Hubs/EventHandlers/SuspendRoundEventHandler.cs @@ -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 SuspendRoundEventHandler(IHubContext hubContext) + : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(SuspendRoundEvent e) + { + return hubContext.Clients.All.SuspendRoundEvent(new SuspendRoundEventArgs + { + PlayerId = e.PlayerId, + SuspendRounds = e.SuspendRounds + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/EventHandlers/ThroughStartEventHandler.cs b/Server/Hubs/EventHandlers/ThroughStartEventHandler.cs new file mode 100644 index 0000000..05bcae2 --- /dev/null +++ b/Server/Hubs/EventHandlers/ThroughStartEventHandler.cs @@ -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 ThroughStartEventHandler(IHubContext hubContext) : MonopolyEventHandlerBase +{ + protected override Task HandleSpecificEvent(ThroughStartEvent e) + { + return hubContext.Clients.All.ThroughStartEvent(new PlayerThroughStartEventArgs + { + PlayerId = e.PlayerId, + GainMoney = e.GainMoney, + TotalMoney = e.TotalMoney + }); + } +} \ No newline at end of file diff --git a/Server/Hubs/MonopolyHub.cs b/Server/Hubs/MonopolyHub.cs index 718dd8a..cd2571c 100644 --- a/Server/Hubs/MonopolyHub.cs +++ b/Server/Hubs/MonopolyHub.cs @@ -7,6 +7,8 @@ using SharedLibrary; using SharedLibrary.ResponseArgs; using System.Security.Claims; +using SharedLibrary.ResponseArgs.Monopoly; +using SharedLibrary.ResponseArgs.ReadyRoom; namespace Server.Hubs; @@ -142,22 +144,22 @@ public async Task GetReadyInfo(GetReadyInfoUsecase usecase) { var presenter = new DefaultPresenter(); await usecase.ExecuteAsync(new GetReadyInfoRequest(GameId, PlayerId), presenter); - await Clients.Caller.GetReadyInfoEvent(new GetReadyInfoEvent + await Clients.Caller.GetReadyInfoEvent(new GetReadyInfoEventArgs { Players = presenter.Value.Info.Players.Select(x => { - var isRole = Enum.TryParse(x.RoleId, true, out var roleEnum); + var isRole = Enum.TryParse(x.RoleId, true, out var roleEnum); if (isRole is false) { - roleEnum = GetReadyInfoEvent.RoleEnum.None; + roleEnum = GetReadyInfoEventArgs.RoleEnum.None; } - return new GetReadyInfoEvent.Player + return new GetReadyInfoEventArgs.Player { Id = x.PlayerId, Name = x.PlayerId, IsReady = x.IsReady, Role = roleEnum, - Color = (GetReadyInfoEvent.ColorEnum?)x.LocationId ?? GetReadyInfoEvent.ColorEnum.None + Color = (GetReadyInfoEventArgs.ColorEnum?)x.LocationId ?? GetReadyInfoEventArgs.ColorEnum.None }; }).ToList(), HostId = presenter.Value.Info.HostId, @@ -179,8 +181,8 @@ public override async Task OnConnectedAsync() throw new GameNotFoundException($"Can not find the game that id is {GameId}"); } await Groups.AddToGroupAsync(Context.ConnectionId, GameId); - await Clients.Caller.WelcomeEvent(new WelcomeEvent { PlayerId = PlayerId }); - await Clients.Group(GameId).PlayerJoinGameEvent(PlayerId); + await Clients.Caller.WelcomeEvent(new WelcomeEventArgs { PlayerId = PlayerId }); + await Clients.Group(GameId).PlayerJoinGameEvent(new PlayerJoinGameEventArgs { PlayerId = PlayerId }); } private class GameNotFoundException(string message) : Exception(message); diff --git a/Server/MonopolyEventBus.cs b/Server/MonopolyEventBus.cs index 7a4a7e0..f7c8fe6 100644 --- a/Server/MonopolyEventBus.cs +++ b/Server/MonopolyEventBus.cs @@ -1,27 +1,34 @@ using Application.Common; using Domain.Common; -using Microsoft.AspNetCore.SignalR; -using Server.Hubs; +using Server.Common; namespace Server; -public class MonopolyEventBus(IHubContext hubContext) : IEventBus +internal class MonopolyEventBus : IEventBus { - // 這裡暫時採用 - // 1. 不同的event,使用不同的發送方式 - // 2. 傳送到所有使用者 - // 3. 之後要視不同的Event發送到不同的Client。 - // 像是個人的錯誤,只傳送到特定使用者 - // 像是遊戲的狀態,傳送到Group Id為Game Id的所有玩家 + private readonly Dictionary _handlers; + + public MonopolyEventBus(IEnumerable handlers) + { + _handlers = handlers.ToDictionary(h => h.EventType, h => h); + } + public async Task PublishAsync(IEnumerable events) { foreach (var e in events) { - var type = e.GetType(); - // args is property of e - var args = type.GetProperties().Select(p => p.GetValue(e)).ToArray(); - // await hubContext1.Clients.Group(gameId).SendCoreAsync(type.Name, args); - await hubContext.Clients.All.SendCoreAsync(type.Name, args); + var handler = GetHandler(e); + await handler!.HandleAsync(e); + } + } + + private IMonopolyEventHandler GetHandler(DomainEvent e) + { + var type = e.GetType(); + if (!_handlers.TryGetValue(type, out var handler)) + { + throw new InvalidOperationException($"Handler for {type} not registered"); } + return handler; } } \ No newline at end of file diff --git a/Server/Hubs/SignalrDefaultPresenter.cs b/Server/Presenters/SignalrDefaultPresenter.cs similarity index 91% rename from Server/Hubs/SignalrDefaultPresenter.cs rename to Server/Presenters/SignalrDefaultPresenter.cs index b75aba1..f1cdcfa 100644 --- a/Server/Hubs/SignalrDefaultPresenter.cs +++ b/Server/Presenters/SignalrDefaultPresenter.cs @@ -1,7 +1,7 @@ using Application.Common; using Domain.Common; -namespace Server.Hubs; +namespace Server.Presenters; public class SignalrDefaultPresenter(IEventBus eventBus) : IPresenter where TResponse : CommandResponse diff --git a/Server/Program.cs b/Server/Program.cs index 5793d21..d207c0c 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -17,11 +17,11 @@ builder.Services.AddSignalR(); builder.Services.AddCors(options => options.AddPolicy("CorsPolicy", - builder => + configurePolicy => { - builder.AllowAnyHeader() + configurePolicy.AllowAnyHeader() .AllowAnyMethod() - .SetIsOriginAllowed((host) => true) + .SetIsOriginAllowed(_ => true) .AllowCredentials(); })); @@ -43,8 +43,8 @@ builder.Configuration.Bind(nameof(JwtBearerOptions), opt); opt.Events = jwtEvents; }); -builder.Services.AddAuthentication("Bearer") - .AddJwtBearer("Bearer"); +builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme); var app = builder.Build(); @@ -99,7 +99,7 @@ await createGameUsecase.ExecuteAsync( app.MapGet("/users", () => { var platformService = app.Services.CreateScope().ServiceProvider.GetRequiredService() as DevelopmentPlatformService; - var users = platformService?.GetUsers().Select(user => new { Id = user.Id, Token = user.Token }); + var users = platformService?.GetUsers().Select(user => new { user.Id, user.Token }); return Results.Json(users); }); #endif diff --git a/Server/Services/DevelopmentPlatformService.cs b/Server/Services/DevelopmentPlatformService.cs index ef7c3b2..4c06d93 100644 --- a/Server/Services/DevelopmentPlatformService.cs +++ b/Server/Services/DevelopmentPlatformService.cs @@ -2,38 +2,29 @@ namespace Server.Services; -public class DevelopmentPlatformService : IPlatformService +public class DevelopmentPlatformService(IConfiguration configuration) : IPlatformService { - private readonly IConfiguration _configuration; - - public DevelopmentPlatformService(IConfiguration configuration) - { - _configuration = configuration; - } - public Task GetUserInfo(string tokenString) { // 根據 tokenString 取得使用者資訊 - var usersSection = _configuration.GetSection("Authentication:Users"); + var usersSection = configuration.GetSection("Authentication:Users"); var users = usersSection.GetChildren(); foreach (var user in users) { - var token = user["Token"]; - if (token == tokenString) - { - var id = user["Id"]; - var email = user["Email"]; - var nickname = user["NickName"]; - var userInfo = new UserInfo(id!, email!, nickname!); - return Task.FromResult(userInfo); - } + if (user["Token"] != tokenString) continue; + + var id = user["Id"]; + var email = user["Email"]; + var nickname = user["NickName"]; + var userInfo = new UserInfo(id!, email!, nickname!); + return Task.FromResult(userInfo); } throw new Exception("找不到使用者資訊"); } public (string Id, string Token)[] GetUsers() { - var usersSection = _configuration.GetSection("Authentication:Users"); + var usersSection = configuration.GetSection("Authentication:Users"); var users = usersSection.GetChildren(); var usersInfo = new List<(string Id, string Token)>(); foreach (var user in users) diff --git a/Server/Services/IPlatformService.cs b/Server/Services/IPlatformService.cs new file mode 100644 index 0000000..4acdc3a --- /dev/null +++ b/Server/Services/IPlatformService.cs @@ -0,0 +1,8 @@ +using Server.DataModels; + +namespace Server.Services; + +public interface IPlatformService +{ + public Task GetUserInfo(string tokenString); +} \ No newline at end of file diff --git a/Server/Services/PlatformService.cs b/Server/Services/PlatformService.cs index 1e183fe..d13da06 100644 --- a/Server/Services/PlatformService.cs +++ b/Server/Services/PlatformService.cs @@ -6,14 +6,9 @@ namespace Server.Services; -public class PlatformService : IPlatformService +public class PlatformService(IOptionsMonitor options) : IPlatformService { - private readonly JwtBearerOptions _jwtOptions; - - public PlatformService(IOptionsMonitor options) - { - _jwtOptions = options.Get("Bearer"); - } + private readonly JwtBearerOptions _jwtOptions = options.Get("Bearer"); public async Task GetUserInfo(string tokenString) { @@ -31,9 +26,4 @@ public async Task GetUserInfo(string tokenString) return userInfo!; } -} - -public interface IPlatformService -{ - public Task GetUserInfo(string tokenString); -} +} \ No newline at end of file diff --git a/SharedLibrary/IMonopolyResponse.cs b/SharedLibrary/IMonopolyResponse.cs deleted file mode 100644 index 3d316b2..0000000 --- a/SharedLibrary/IMonopolyResponse.cs +++ /dev/null @@ -1,103 +0,0 @@ -using SharedLibrary.ResponseArgs; - -namespace SharedLibrary; - -public interface IMonopolyResponses -{ - Task GameCreatedEvent(string gameId); - - Task PlayerJoinGameEvent(string playerId); - Task PlayerJoinGameFailedEvent(string message); - - Task PlayerRolledDiceEvent(string playerId, int diceCount); - - Task ChessMovedEvent(string playerId, string blockId, string direction, int remainingSteps); - - Task PlayerNeedToChooseDirectionEvent(string playerId, string[] directions); - - Task ThroughStartEvent(string playerId, decimal gainMoney, decimal totalMoney); - - Task CannotGetRewardBecauseStandOnStartEvent(string playerId, decimal playerMoney); - - Task PlayerCanBuildHouseEvent(string playerId, string blockId, int houseCount, decimal upgradeMoney); - - Task PlayerCanBuyLandEvent(string playerId, string blockId, decimal landMoney); - - Task PlayerChooseDirectionEvent(string playerId, string direction); - - Task PlayerNeedsToPayTollEvent(string playerId, string ownerId, decimal toll); - - Task PlayerBuyBlockEvent(string playerId, string blockId); - - Task PlayerBuyBlockMissedLandEvent(string playerId, string blockId); - - Task PlayerBuyBlockOccupiedByOtherPlayerEvent(string playerId, string blockId); - - Task PlayerBuyBlockInsufficientFundsEvent(string playerId, string blockId, decimal landMoney); - - Task PlayerPayTollEvent(string payerId, decimal payerMoney, string payee, decimal payeeMoney); - - Task PlayerDoesntNeedToPayTollEvent(string payerId, decimal payerMoney); - - Task PlayerTooPoorToPayTollEvent(string payerId, decimal payerMoney, decimal toll); - - Task PlayerBuildHouseEvent(string playerId, string blockId, decimal playerMoney, int house); - - Task PlayerCannotBuildHouseEvent(string PlayerId, string BlockId); - - Task PlayerTooPoorToBuildHouseEvent(string PlayerId, string BlockId, decimal PlayerMoney, decimal UpgradePrice); - - Task HouseMaxEvent(string PlayerId, string BlockId, int House); - - Task PlayerMortgageEvent(string PlayerId, decimal PlayerMoney, string BlockId, int DeadLine); - - Task PlayerCannotMortgageEvent(string PlayerId, decimal PlayerMoney, string BlockId); - - Task MortgageDueEvent(string PlayerId, string BlockId); - - Task MortgageCountdownEvent(string PlayerId, string BlockId, int DeadLine); - - Task PlayerRedeemEvent(string PlayerId, decimal PlayerMoney, string BlockId); - - Task PlayerTooPoorToRedeemEvent(string PlayerId, decimal PlayerMoney, string BlockId, decimal RedeemPrice); - - Task LandNotInMortgageEvent(string PlayerId, string BlockId); - - Task PlayerBidEvent(string PlayerId, string BlockId, decimal HighestPrice); - - Task PlayerBidFailEvent(string PlayerId, string BlockId, decimal BidPrice, decimal HighestPrice); - - Task PlayerTooPoorToBidEvent(string PlayerId, decimal PlayerMoney, decimal BidPrice, decimal HighestPrice); - - Task CurrentPlayerCannotBidEvent(string PlayerId); - - Task EndAuctionEvent(string PlayerId, decimal PlayerMoney, string BlockId, string? Owner, decimal OwnerMoney); - - Task EndRoundEvent(string PlayerId, string NextPlayerId); - - Task EndRoundFailEvent(string PlayerId); - - Task SuspendRoundEvent(string PlayerId, int SuspendRounds); - - Task PlayerBankruptEvent(PlayerBankruptEvent e); - - Task SettlementEvent(int Rounds, params string[] PlayerIds); - - Task PlayerSelectRoleEvent(string PlayerId, string RoleId); - - Task PlaySelectLocationEvent(string PlayerId, int LocationId); - - Task PlayCannotSelectLocationEvent(string PlayerId, int LocationId); - - Task PlayerReadyEvent(string PlayerId, string PlayerState); - - Task PlayerCannotReadyEvent(string PlayerId, string PlayerState, string RoleId, int LocationID); - - Task GameStartEvent(string GameStage, string CurrentPlayer); - - Task OnlyOnePersonEvent(string GameStage); - - Task SomePlayersPreparingEvent(string GameStage, params string[] PlayerIds); - Task GetReadyInfoEvent(GetReadyInfoEvent e); - Task WelcomeEvent(WelcomeEvent e); -} \ No newline at end of file diff --git a/SharedLibrary/IMonopolyResponses.cs b/SharedLibrary/IMonopolyResponses.cs new file mode 100644 index 0000000..2ebba48 --- /dev/null +++ b/SharedLibrary/IMonopolyResponses.cs @@ -0,0 +1,94 @@ +using SharedLibrary.ResponseArgs.Monopoly; +using SharedLibrary.ResponseArgs.ReadyRoom; + +namespace SharedLibrary; + +public interface IMonopolyResponses +{ + Task PlayerJoinGameEvent(PlayerJoinGameEventArgs e); + Task PlayerJoinGameFailedEvent(PlayerJoinGameFailedEventArgs e); + + Task PlayerRolledDiceEvent(PlayerRolledDiceEventArgs e); + + Task ChessMovedEvent(ChessMovedEventArgs e); + + Task PlayerNeedToChooseDirectionEvent(PlayerNeedToChooseDirectionEventArgs e); + + Task ThroughStartEvent(PlayerThroughStartEventArgs e); + + Task CannotGetRewardBecauseStandOnStartEvent(CannotGetRewardBecauseStandOnStartEventArgs e); + + Task PlayerCanBuildHouseEvent(PlayerCanBuildHouseEventArgs e); + + Task PlayerCanBuyLandEvent(PlayerCanBuyLandEventArgs e); + + Task PlayerChooseDirectionEvent(PlayerChooseDirectionEventArgs e); + + Task PlayerNeedsToPayTollEvent(PlayerNeedsToPayTollEventArgs e); + + Task PlayerBuyBlockEvent(PlayerBuyBlockEventArgs e); + + Task PlayerBuyBlockOccupiedByOtherPlayerEvent(PlayerBuyBlockOccupiedByOtherPlayerEventArgs e); + + Task PlayerBuyBlockInsufficientFundsEvent(PlayerBuyBlockInsufficientFundsEventArgs e); + + Task PlayerPayTollEvent(PlayerPayTollEventArgs e); + + Task PlayerDoesntNeedToPayTollEvent(PlayerDoesntNeedToPayTollEventArgs e); + + Task PlayerTooPoorToPayTollEvent(PlayerTooPoorToPayTollEventArgs e); + + Task PlayerBuildHouseEvent(PlayerBuildHouseEventArgs e); + + Task PlayerCannotBuildHouseEvent(PlayerCannotBuildHouseEventArgs e); + + Task HouseMaxEvent(HouseMaxEventArgs e); + + Task PlayerMortgageEvent(PlayerMortgageEventArgs e); + + Task PlayerCannotMortgageEvent(PlayerCannotMortgageEventArgs e); + + Task MortgageDueEvent(MortgageDueEventArgs e); + + Task PlayerRedeemEvent(PlayerRedeemEventArgs e); + + Task PlayerTooPoorToRedeemEvent(PlayerTooPoorToRedeemEventArgs e); + + Task PlayerBidEvent(PlayerBidEventArgs e); + + Task PlayerBidFailEvent(PlayerBidFailEventArgs e); + + Task PlayerTooPoorToBidEvent(PlayerTooPoorToBidEventArgs e); + + Task CurrentPlayerCannotBidEvent(CurrentPlayerCannotBidEventArgs e); + + Task EndAuctionEvent(EndAuctionEventArgs e); + + Task EndRoundEvent(EndRoundEventArgs e); + + Task EndRoundFailEvent(EndRoundFailEventArgs e); + + Task SuspendRoundEvent(SuspendRoundEventArgs e); + + Task PlayerBankruptEvent(PlayerBankruptEvent e); + + Task SettlementEvent(SettlementEventArgs e); + + Task PlayerSelectRoleEvent(PlayerSelectRoleEventArgs e); + + Task PlaySelectLocationEvent(PlaySelectLocationEventArgs e); + + Task PlayCannotSelectLocationEvent(PlayCannotSelectLocationEventArgs e); + + Task PlayerReadyEvent(PlayerReadyEventArgs e); + + Task PlayerCannotReadyEvent(PlayerCannotReadyEventArgs e); + + Task GameStartEvent(GameStartEventArgs e); + + Task OnlyOnePersonEvent(OnlyOnePersonEventArgs e); + + Task SomePlayersPreparingEvent(SomePlayersPreparingEventArgs e); + Task GetReadyInfoEvent(GetReadyInfoEventArgs e); + Task WelcomeEvent(WelcomeEventArgs e); +} \ No newline at end of file diff --git a/SharedLibrary/MonopolyMap/MonopolyMap.cs b/SharedLibrary/MonopolyMap/MonopolyMap.cs index 736b2b1..178f527 100644 --- a/SharedLibrary/MonopolyMap/MonopolyMap.cs +++ b/SharedLibrary/MonopolyMap/MonopolyMap.cs @@ -3,20 +3,14 @@ namespace SharedLibrary.MonopolyMap; -public class MonopolyMap +public class MonopolyMap(string id, BlockBase[][] data) { - public MonopolyMap(string Id, BlockBase[][] Data) - { - this.Id = Id; - this.Data = Data; - } - - public string Id { get; } - public BlockBase[][] Data { get; } + public string Id { get; } = id; + public BlockBase[][] Data { get; } = data; public static MonopolyMap Parse(string data) { - return JsonSerializer.Deserialize(data, JsonSerializerOptions); + return JsonSerializer.Deserialize(data, JsonSerializerOptions) ?? throw new InvalidOperationException(); } public static JsonSerializerOptions JsonSerializerOptions => new() { @@ -82,7 +76,7 @@ public override bool CanConvert(Type typeToConvert) { throw new JsonException("Missing Type property"); } - BlockType type = JsonSerializer.Deserialize(typeProperty.GetRawText(), options); + var type = JsonSerializer.Deserialize(typeProperty.GetRawText(), options); return type switch { BlockType.None => JsonSerializer.Deserialize(root.GetRawText(), options), diff --git a/SharedLibrary/ResponseArgs/GetReadyInfoEvent.cs b/SharedLibrary/ResponseArgs/GetReadyInfoEvent.cs deleted file mode 100644 index d3fefa2..0000000 --- a/SharedLibrary/ResponseArgs/GetReadyInfoEvent.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace SharedLibrary.ResponseArgs; -public class GetReadyInfoEvent : EventArgs -{ - public required IEnumerable Players { get; set; } - public required string HostId { get; set; } - public class Player - { - public string Id { get; set; } = string.Empty; - public string Name { get; set; } = string.Empty; - public bool IsReady { get; set; } = false; - public ColorEnum Color { get; set; } = ColorEnum.None; - public RoleEnum Role { get; set; } = RoleEnum.None; - } - public enum ColorEnum - { - None, - Red, - Blue, - Green, - Yellow, - } - public enum RoleEnum - { - None, - OldMan, - Baby, - Dai, - Mei - } -} diff --git a/SharedLibrary/ResponseArgs/Monopoly/CannotGetRewardBecauseStandOnStartEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/CannotGetRewardBecauseStandOnStartEventArgs.cs new file mode 100644 index 0000000..ec169d0 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/CannotGetRewardBecauseStandOnStartEventArgs.cs @@ -0,0 +1,6 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class CannotGetRewardBecauseStandOnStartEventArgs : EventArgs +{ + public required string PlayerId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/ChessMovedEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/ChessMovedEventArgs.cs new file mode 100644 index 0000000..da92e72 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/ChessMovedEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class ChessMovedEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string BlockId { get; init; } + public required string Direction { get; init; } + public required int RemainingSteps { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/CurrentPlayerCannotBidEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/CurrentPlayerCannotBidEventArgs.cs new file mode 100644 index 0000000..f6b1b43 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/CurrentPlayerCannotBidEventArgs.cs @@ -0,0 +1,6 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class CurrentPlayerCannotBidEventArgs : EventArgs +{ + public required string PlayerId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/EndAuctionEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/EndAuctionEventArgs.cs new file mode 100644 index 0000000..5412f5a --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/EndAuctionEventArgs.cs @@ -0,0 +1,10 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class EndAuctionEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required decimal PlayerMoney { get; init; } + public required string LandId { get; init; } + public required string? OwnerId { get; init; } + public required decimal OwnerMoney { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/EndRoundEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/EndRoundEventArgs.cs new file mode 100644 index 0000000..00db51b --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/EndRoundEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class EndRoundEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string NextPlayerId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/EndRoundFailEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/EndRoundFailEventArgs.cs new file mode 100644 index 0000000..3e27807 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/EndRoundFailEventArgs.cs @@ -0,0 +1,6 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class EndRoundFailEventArgs : EventArgs +{ + public required string PlayerId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/GameStartEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/GameStartEventArgs.cs new file mode 100644 index 0000000..de0579d --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/GameStartEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class GameStartEventArgs : EventArgs +{ + public required string GameStage { get; init; } + public required string CurrentPlayerId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/HouseMaxEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/HouseMaxEventArgs.cs new file mode 100644 index 0000000..c99ca50 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/HouseMaxEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class HouseMaxEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required int HouseCount { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/MortgageDueEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/MortgageDueEventArgs.cs new file mode 100644 index 0000000..3f89cf6 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/MortgageDueEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class MortgageDueEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/OnlyOnePersonEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/OnlyOnePersonEventArgs.cs new file mode 100644 index 0000000..d7af04f --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/OnlyOnePersonEventArgs.cs @@ -0,0 +1,6 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class OnlyOnePersonEventArgs : EventArgs +{ + public required string GameStage { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayCannotSelectLocationEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayCannotSelectLocationEventArgs.cs new file mode 100644 index 0000000..e3eaa9f --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayCannotSelectLocationEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayCannotSelectLocationEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required int LocationId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlaySelectLocationEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlaySelectLocationEventArgs.cs new file mode 100644 index 0000000..340b8a7 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlaySelectLocationEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlaySelectLocationEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required int LocationId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerBankruptEvent.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerBankruptEvent.cs new file mode 100644 index 0000000..d2c6365 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerBankruptEvent.cs @@ -0,0 +1,6 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerBankruptEvent : EventArgs +{ + public required string PlayerId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerBidEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerBidEventArgs.cs new file mode 100644 index 0000000..7efb684 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerBidEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerBidEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required decimal HighestPrice { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerBidFailEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerBidFailEventArgs.cs new file mode 100644 index 0000000..3e7966e --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerBidFailEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerBidFailEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required decimal BidPrice { get; init; } + public required decimal HighestPrice { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerBuildHouseEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerBuildHouseEventArgs.cs new file mode 100644 index 0000000..07db11a --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerBuildHouseEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerBuildHouseEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required decimal PlayerMoney { get; init; } + public required int HouseCount { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockEventArgs.cs new file mode 100644 index 0000000..7d0814d --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerBuyBlockEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockInsufficientFundsEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockInsufficientFundsEventArgs.cs new file mode 100644 index 0000000..ab82d94 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockInsufficientFundsEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerBuyBlockInsufficientFundsEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required decimal Price { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockOccupiedByOtherPlayerEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockOccupiedByOtherPlayerEventArgs.cs new file mode 100644 index 0000000..ba4b577 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerBuyBlockOccupiedByOtherPlayerEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerBuyBlockOccupiedByOtherPlayerEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerCanBuildHouseEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerCanBuildHouseEventArgs.cs new file mode 100644 index 0000000..d9cbbfb --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerCanBuildHouseEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerCanBuildHouseEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required int HouseCount { get; init; } + public required decimal Price { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerCanBuyLandEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerCanBuyLandEventArgs.cs new file mode 100644 index 0000000..5ae4d03 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerCanBuyLandEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerCanBuyLandEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required decimal Price { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotBuildHouseEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotBuildHouseEventArgs.cs new file mode 100644 index 0000000..79834bc --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotBuildHouseEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerCannotBuildHouseEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotMortgageEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotMortgageEventArgs.cs new file mode 100644 index 0000000..cf79a34 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotMortgageEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerCannotMortgageEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required decimal PlayerMoney { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotReadyEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotReadyEventArgs.cs new file mode 100644 index 0000000..29366b2 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerCannotReadyEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerCannotReadyEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string PlayerState { get; init; } + public required string? RoleId { get; init; } + public required int LocationId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerChooseDirectionEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerChooseDirectionEventArgs.cs new file mode 100644 index 0000000..7ecb763 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerChooseDirectionEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerChooseDirectionEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string Direction { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerDoesntNeedToPayTollEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerDoesntNeedToPayTollEventArgs.cs new file mode 100644 index 0000000..6d4af39 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerDoesntNeedToPayTollEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerDoesntNeedToPayTollEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required decimal PlayerMoney { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerJoinGameEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerJoinGameEventArgs.cs new file mode 100644 index 0000000..b2b5be1 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerJoinGameEventArgs.cs @@ -0,0 +1,6 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerJoinGameEventArgs : EventArgs +{ + public required string PlayerId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerJoinGameFailedEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerJoinGameFailedEventArgs.cs new file mode 100644 index 0000000..5da3a0a --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerJoinGameFailedEventArgs.cs @@ -0,0 +1,6 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerJoinGameFailedEventArgs : EventArgs +{ + public required string Message { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerMortgageEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerMortgageEventArgs.cs new file mode 100644 index 0000000..f182506 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerMortgageEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerMortgageEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string LandId { get; init; } + public required decimal PlayerMoney { get; init; } + public required int DeadLine { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerNeedToChooseDirectionEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerNeedToChooseDirectionEventArgs.cs new file mode 100644 index 0000000..14b6a50 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerNeedToChooseDirectionEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerNeedToChooseDirectionEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string[] Directions { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerNeedsToPayTollEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerNeedsToPayTollEventArgs.cs new file mode 100644 index 0000000..69ad8f9 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerNeedsToPayTollEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary; + +public class PlayerNeedsToPayTollEventArgs +{ + public required string PlayerId { get; init; } + public required string OwnerId { get; init; } + public required decimal Toll { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerPayTollEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerPayTollEventArgs.cs new file mode 100644 index 0000000..215716b --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerPayTollEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerPayTollEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required decimal PlayerMoney { get; init; } + public required string OwnerId { get; init; } + public required decimal OwnerMoney { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerReadyEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerReadyEventArgs.cs new file mode 100644 index 0000000..48793b9 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerReadyEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerReadyEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string PlayerState { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerRedeemEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerRedeemEventArgs.cs new file mode 100644 index 0000000..144712a --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerRedeemEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerRedeemEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required decimal PlayerMoney { get; init; } + public required string LandId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerRolledDiceEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerRolledDiceEventArgs.cs new file mode 100644 index 0000000..f3c18c9 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerRolledDiceEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerRolledDiceEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required int DiceCount { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerSelectRoleEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerSelectRoleEventArgs.cs new file mode 100644 index 0000000..414f493 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerSelectRoleEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerSelectRoleEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required string RoleId { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerThroughStartEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerThroughStartEventArgs.cs new file mode 100644 index 0000000..f55d7a0 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerThroughStartEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerThroughStartEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required decimal GainMoney { get; init; } + public required decimal TotalMoney { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToBidEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToBidEventArgs.cs new file mode 100644 index 0000000..f1326b3 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToBidEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerTooPoorToBidEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required decimal PlayerMoney { get; init; } + public required decimal BidPrice { get; init; } + public required decimal HighestPrice { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToPayTollEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToPayTollEventArgs.cs new file mode 100644 index 0000000..ea79ac6 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToPayTollEventArgs.cs @@ -0,0 +1,8 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerTooPoorToPayTollEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required decimal PlayerMoney { get; init; } + public required decimal Toll { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToRedeemEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToRedeemEventArgs.cs new file mode 100644 index 0000000..23e45ae --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/PlayerTooPoorToRedeemEventArgs.cs @@ -0,0 +1,9 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class PlayerTooPoorToRedeemEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required decimal PlayerMoney { get; init; } + public required string LandId { get; init; } + public required decimal RedeemPrice { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/SettlementEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/SettlementEventArgs.cs new file mode 100644 index 0000000..bb4d257 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/SettlementEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class SettlementEventArgs : EventArgs +{ + public required int Rounds { get; init; } + public required string[] PlayerIds { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/SomePlayersPreparingEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/SomePlayersPreparingEventArgs.cs new file mode 100644 index 0000000..c9b3e41 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/SomePlayersPreparingEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class SomePlayersPreparingEventArgs : EventArgs +{ + public required string GameStage { get; init; } + public required string[] PlayerIds { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/Monopoly/SuspendRoundEventArgs.cs b/SharedLibrary/ResponseArgs/Monopoly/SuspendRoundEventArgs.cs new file mode 100644 index 0000000..1f490b7 --- /dev/null +++ b/SharedLibrary/ResponseArgs/Monopoly/SuspendRoundEventArgs.cs @@ -0,0 +1,7 @@ +namespace SharedLibrary.ResponseArgs.Monopoly; + +public class SuspendRoundEventArgs : EventArgs +{ + public required string PlayerId { get; init; } + public required int SuspendRounds { get; init; } +} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/PlayerBankruptEvent.cs b/SharedLibrary/ResponseArgs/PlayerBankruptEvent.cs deleted file mode 100644 index 642ee25..0000000 --- a/SharedLibrary/ResponseArgs/PlayerBankruptEvent.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SharedLibrary.ResponseArgs; - -public class PlayerBankruptEvent : EventArgs -{ - public required string PlayerId { get; set; } -} \ No newline at end of file diff --git a/SharedLibrary/ResponseArgs/ReadyRoom/GetReadyInfoEventArgs.cs b/SharedLibrary/ResponseArgs/ReadyRoom/GetReadyInfoEventArgs.cs new file mode 100644 index 0000000..6d5977c --- /dev/null +++ b/SharedLibrary/ResponseArgs/ReadyRoom/GetReadyInfoEventArgs.cs @@ -0,0 +1,30 @@ +namespace SharedLibrary.ResponseArgs.ReadyRoom; +public class GetReadyInfoEventArgs : EventArgs +{ + public required IEnumerable Players { get; init; } + public required string HostId { get; init; } + public class Player + { + public required string Id { get; init; } + public required string Name { get; init; } + public required bool IsReady { get; init; } + public required ColorEnum Color { get; init; } + public required RoleEnum Role { get; init; } + } + public enum ColorEnum + { + None, + Red, + Blue, + Green, + Yellow, + } + public enum RoleEnum + { + None, + OldMan, + Baby, + Dai, + Mei + } +} diff --git a/SharedLibrary/ResponseArgs/ReadyRoom/WelcomeEventArgs.cs b/SharedLibrary/ResponseArgs/ReadyRoom/WelcomeEventArgs.cs new file mode 100644 index 0000000..33e4e6b --- /dev/null +++ b/SharedLibrary/ResponseArgs/ReadyRoom/WelcomeEventArgs.cs @@ -0,0 +1,5 @@ +namespace SharedLibrary.ResponseArgs.ReadyRoom; +public class WelcomeEventArgs : EventArgs +{ + public required string PlayerId { get; set; } +} diff --git a/SharedLibrary/ResponseArgs/WelcomeEvent.cs b/SharedLibrary/ResponseArgs/WelcomeEvent.cs deleted file mode 100644 index 9bf086a..0000000 --- a/SharedLibrary/ResponseArgs/WelcomeEvent.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace SharedLibrary.ResponseArgs; -public class WelcomeEvent : EventArgs -{ - public required string PlayerId { get; set; } -} diff --git a/Test/DomainTests/Utils.cs b/Test/DomainTests/Utils.cs index 419c53b..fc2caf0 100644 --- a/Test/DomainTests/Utils.cs +++ b/Test/DomainTests/Utils.cs @@ -40,9 +40,9 @@ public static IEnumerable NextShouldBe(this IEnumerable( - nameof(IMonopolyResponses.PlayerBidEvent), - (playerId, blockId, highestPrice) - => playerId == B.Id && blockId == A1.Id && highestPrice == 1500); + hub.Verify(nameof(IMonopolyResponses.PlayerBidEvent), + (PlayerBidEventArgs e) => e is { PlayerId: "B", LandId: "A1", HighestPrice: 1500 }); hub.VerifyNoElseEvent(); } @@ -113,10 +112,8 @@ public async Task 玩家不能喊出比自己現金還高的金額() // Assert // B 喊價 - hub.Verify( - nameof(IMonopolyResponses.PlayerTooPoorToBidEvent), - (playerId, playerMoney, bidPrice, highestPrice) - => playerId == "B" && playerMoney == 2000 && bidPrice == 3000 && highestPrice == 1000); + hub.Verify(nameof(IMonopolyResponses.PlayerTooPoorToBidEvent), + (PlayerTooPoorToBidEventArgs e) => e is { PlayerId: "B", PlayerMoney: 2000, BidPrice: 3000, HighestPrice: 1000 }); hub.VerifyNoElseEvent(); } @@ -164,10 +161,8 @@ public async Task 玩家不能喊出比當前拍賣金額更低的金額() // Assert // B 喊價 - hub.Verify( - nameof(IMonopolyResponses.PlayerBidFailEvent), - (playerId, blockId, bidPrice, highestPrice) - => playerId == B.Id && blockId == A1.Id && bidPrice == 800 && highestPrice == 1000); + hub.Verify(nameof(IMonopolyResponses.PlayerBidFailEvent), + (PlayerBidFailEventArgs e) => e is { PlayerId: "B", LandId: "A1", BidPrice: 800, HighestPrice: 1000 }); hub.VerifyNoElseEvent(); } @@ -212,10 +207,15 @@ public async Task 拍賣結算時流拍系統會以房地產價值的七成收 // Assert // 流拍 // 在流拍中,土地為系統所有,OwnerMoney值回傳0 - hub.Verify( - nameof(IMonopolyResponses.EndAuctionEvent), - (playerId, playerMoney, blockId, owner, ownerMoney) - => playerId == "A" && playerMoney == 3400 && blockId == "A1" && owner == null && ownerMoney == 0); + hub.Verify(nameof(IMonopolyResponses.EndAuctionEvent), + (EndAuctionEventArgs e) => e is + { + PlayerId: "A", + PlayerMoney: 3400, + LandId: "A1", + OwnerId: null, + OwnerMoney: 0 + }); hub.VerifyNoElseEvent(); } @@ -266,10 +266,15 @@ public async Task 拍賣結算時轉移金錢及地契() // Assert // 拍賣結算 - hub.Verify( - nameof(IMonopolyResponses.EndAuctionEvent), - (playerId, playerMoney, blockId, owner, ownerMoney) - => playerId == "A" && playerMoney == 1600 && blockId == "A1" && owner == "B" && ownerMoney == 1400); + hub.Verify(nameof(IMonopolyResponses.EndAuctionEvent), + (EndAuctionEventArgs e) => e is + { + PlayerId: "A", + PlayerMoney: 1600, + LandId: "A1", + OwnerId: "B", + OwnerMoney: 1400 + }); hub.VerifyNoElseEvent(); } @@ -317,10 +322,8 @@ public async Task 拍賣土地的玩家不能自己喊價() // Assert // A 喊價 - hub.Verify( - nameof(IMonopolyResponses.CurrentPlayerCannotBidEvent), - (playerId) - => playerId == "A"); + hub.Verify(nameof(IMonopolyResponses.CurrentPlayerCannotBidEvent), + (CurrentPlayerCannotBidEventArgs e) => e.PlayerId == "A"); hub.VerifyNoElseEvent(); } } \ No newline at end of file diff --git a/Test/ServerTests/AcceptanceTests/BuildHouseTest.cs b/Test/ServerTests/AcceptanceTests/BuildHouseTest.cs index 687b700..d50751e 100644 --- a/Test/ServerTests/AcceptanceTests/BuildHouseTest.cs +++ b/Test/ServerTests/AcceptanceTests/BuildHouseTest.cs @@ -1,5 +1,7 @@ +using Domain.Events; using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -56,10 +58,8 @@ public async Task 玩家在自己的土地蓋房子() // Assert // A 蓋房子 - hub.Verify( - nameof(IMonopolyResponses.PlayerBuildHouseEvent), - (playerId, blockId, playerMoney, house) - => playerId == "A" && blockId == "A1" && playerMoney == 1000 && house == 2); + hub.Verify(nameof(IMonopolyResponses.PlayerBuildHouseEvent), + (PlayerBuildHouseEventArgs e) => e is { PlayerId: "A", LandId: "A1", PlayerMoney: 1000, HouseCount: 2 }); hub.VerifyNoElseEvent(); } @@ -99,10 +99,8 @@ public async Task 土地最多蓋5間房子() // Assert // A 蓋房子 - hub.Verify( - nameof(IMonopolyResponses.HouseMaxEvent), - (playerId, blockId, house) - => playerId == "A" && blockId == "A1" && house == 5); + hub.Verify(nameof(IMonopolyResponses.HouseMaxEvent), + (HouseMaxEventArgs e) => e is { PlayerId: "A", LandId: "A1", HouseCount: 5 }); hub.VerifyNoElseEvent(); } @@ -140,10 +138,8 @@ public async Task 車站不能蓋房子() // Assert // A 蓋房子 - hub.Verify( - nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent), - (playerId, blockId) - => playerId == "A" && blockId == "Station1"); + hub.Verify(nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent), + (PlayerCannotBuildHouseEventArgs e) => e is { PlayerId: "A", LandId: "Station1" }); hub.VerifyNoElseEvent(); } @@ -186,10 +182,9 @@ public async Task 一回合內玩家不能重複蓋房子() // Assert // A 蓋房子 - hub.Verify( - nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent), - (playerId, blockId) - => playerId == "A" && blockId == "A1"); + hub.Verify(nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent), + (PlayerCannotBuildHouseEventArgs e) + => e is { PlayerId: "A", LandId: "A1" }); hub.VerifyNoElseEvent(); } @@ -230,10 +225,9 @@ public async Task 一回合內玩家買土地後不能馬上蓋房子() await hub.SendAsync(nameof(MonopolyHub.PlayerBuildHouse), gameId, "A"); // Assert - hub.Verify( - nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent), - (playerId, blockId) - => playerId == "A" && blockId == "A1"); + hub.Verify(nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent), + (PlayerCannotBuildHouseEventArgs e) + => e is { PlayerId: "A", LandId: "A1" }); hub.VerifyNoElseEvent(); } @@ -275,10 +269,8 @@ public async Task 已抵押的土地不能蓋房子() // Assert // A 蓋房子失敗 - hub.Verify( - nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent), - (playerId, blockId) - => playerId == "A" && blockId == "A2"); + hub.Verify(nameof(IMonopolyResponses.PlayerCannotBuildHouseEvent), + (PlayerCannotBuildHouseEventArgs e) => e is { PlayerId: "A", LandId: "A2" }); hub.VerifyNoElseEvent(); } } diff --git a/Test/ServerTests/AcceptanceTests/BuyBlockTest.cs b/Test/ServerTests/AcceptanceTests/BuyBlockTest.cs index cd20919..051197b 100644 --- a/Test/ServerTests/AcceptanceTests/BuyBlockTest.cs +++ b/Test/ServerTests/AcceptanceTests/BuyBlockTest.cs @@ -1,5 +1,6 @@ using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -53,9 +54,8 @@ public async Task 玩家在空地上可以購買土地() // Assert // A 購買土地 - hub.Verify( - nameof(IMonopolyResponses.PlayerBuyBlockEvent), - (playerId, blockId) => playerId == "A" && blockId == "F4"); + hub.Verify(nameof(IMonopolyResponses.PlayerBuyBlockEvent), + (PlayerBuyBlockEventArgs e) => e is { PlayerId: "A", LandId: "F4" }); hub.VerifyNoElseEvent(); } @@ -99,9 +99,8 @@ public async Task 金錢不夠無法購買土地() // Assert // A 購買土地金額不足 - hub.Verify( - nameof(IMonopolyResponses.PlayerBuyBlockInsufficientFundsEvent), - (playerId, blockId, landMoney) => playerId == "A" && blockId == "F4" && landMoney == 1000); + hub.Verify(nameof(IMonopolyResponses.PlayerBuyBlockInsufficientFundsEvent), + (PlayerBuyBlockInsufficientFundsEventArgs e) => e is { PlayerId: "A", LandId: "F4", Price: 1000 }); hub.VerifyNoElseEvent(); } @@ -154,9 +153,8 @@ public async Task 玩家在有地主的土地上不可以購買土地() // Assert // A 購買土地非空地 - hub.Verify( - nameof(IMonopolyResponses.PlayerBuyBlockOccupiedByOtherPlayerEvent), - (playerId, blockId) => playerId == "A" && blockId == "F4"); + hub.Verify(nameof(IMonopolyResponses.PlayerBuyBlockOccupiedByOtherPlayerEvent), + (PlayerBuyBlockOccupiedByOtherPlayerEventArgs e) => e is { PlayerId: "A", LandId: "F4" }); hub.VerifyNoElseEvent(); } diff --git a/Test/ServerTests/AcceptanceTests/EndRoundTest.cs b/Test/ServerTests/AcceptanceTests/EndRoundTest.cs index 1bf5ab5..4ea50ea 100644 --- a/Test/ServerTests/AcceptanceTests/EndRoundTest.cs +++ b/Test/ServerTests/AcceptanceTests/EndRoundTest.cs @@ -1,5 +1,6 @@ using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -60,10 +61,8 @@ public async Task 玩家沒有付過路費無法結束回合() // Assert // A 結束回合 - hub.Verify( - nameof(IMonopolyResponses.EndRoundFailEvent), - (playerId) - => playerId == "A"); + hub.Verify(nameof(IMonopolyResponses.EndRoundFailEvent), + (EndRoundFailEventArgs e) => e is { PlayerId: "A" }); hub.VerifyNoElseEvent(); } @@ -113,10 +112,8 @@ public async Task 玩家成功結束回合() // Assert // A 結束回合 - hub.Verify( - nameof(IMonopolyResponses.EndRoundEvent), - (playerId, nextPlayer) - => playerId == "A" && nextPlayer == "B"); + hub.Verify(nameof(IMonopolyResponses.EndRoundEvent), + (EndRoundEventArgs e) => e is { PlayerId: "A", NextPlayerId: "B" }); hub.VerifyNoElseEvent(); } @@ -167,14 +164,10 @@ public async Task 玩家10回合後沒贖回房地產失去房地產() // Assert // A 結束回合 // A1 抵押到期 - hub.Verify( - nameof(IMonopolyResponses.EndRoundEvent), - (playerId, nextPlayer) - => playerId == "A" && nextPlayer == "B"); - hub.Verify( - nameof(IMonopolyResponses.MortgageDueEvent), - (playerId, BlockId) - => playerId == "A" && BlockId == "A1"); + hub.Verify(nameof(IMonopolyResponses.EndRoundEvent), + (EndRoundEventArgs e) => e is { PlayerId: "A", NextPlayerId: "B" }); + hub.Verify(nameof(IMonopolyResponses.MortgageDueEvent), + (MortgageDueEventArgs e) => e is { PlayerId: "A", LandId: "A1" }); hub.VerifyNoElseEvent(); } @@ -231,10 +224,9 @@ public async Task 結束回合輪到下一個未破產玩家() // Assert // A 結束回合,輪到下一個未破產玩家 - hub.Verify( - nameof(IMonopolyResponses.EndRoundEvent), - (playerId, nextPlayer) - => playerId == "A" && nextPlayer == "C"); + hub.Verify(nameof(IMonopolyResponses.EndRoundEvent), + (EndRoundEventArgs e) + => e is { PlayerId: "A", NextPlayerId: "C" }); hub.VerifyNoElseEvent(); } @@ -290,18 +282,12 @@ public async Task 上一回合玩家剛到監獄這回合不能做任何事() // A 結束回合,輪到下一個玩家 B // B 在監獄,輪到下一個玩家 C - hub.Verify( - nameof(IMonopolyResponses.EndRoundEvent), - (playerId, nextPlayer) - => playerId == "A" && nextPlayer == "B"); - hub.Verify( - nameof(IMonopolyResponses.SuspendRoundEvent), - (playerId, suspendRounds) - => playerId == "B" && suspendRounds == 1); - hub.Verify( - nameof(IMonopolyResponses.EndRoundEvent), - (playerId, nextPlayer) - => playerId == "B" && nextPlayer == "C"); + hub.Verify(nameof(IMonopolyResponses.EndRoundEvent), + (EndRoundEventArgs e) => e is { PlayerId: "A", NextPlayerId: "B" }); + hub.Verify(nameof(IMonopolyResponses.SuspendRoundEvent), + (SuspendRoundEventArgs e) => e is { PlayerId: "B", SuspendRounds: 1 }); + hub.Verify(nameof(IMonopolyResponses.EndRoundEvent), + (EndRoundEventArgs e) => e is { PlayerId: "B", NextPlayerId: "C" }); hub.VerifyNoElseEvent(); } diff --git a/Test/ServerTests/AcceptanceTests/GameStartTest.cs b/Test/ServerTests/AcceptanceTests/GameStartTest.cs index 9a9324c..4c6f807 100644 --- a/Test/ServerTests/AcceptanceTests/GameStartTest.cs +++ b/Test/ServerTests/AcceptanceTests/GameStartTest.cs @@ -1,6 +1,7 @@ using Application.DataModels; using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -53,9 +54,9 @@ public async Task 房主成功開始遊戲() await hub.SendAsync(nameof(MonopolyHub.GameStart), gameId, "A"); // Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.GameStartEvent), - (gameState, currentPlayer) => (gameState, currentPlayer) == ("Gaming", "A") + (GameStartEventArgs e) => e is { GameStage: "Gaming", CurrentPlayerId: "A" } ); } @@ -88,9 +89,9 @@ public async Task 人數只有1人_房主開始遊戲失敗() await hub.SendAsync(nameof(MonopolyHub.GameStart), gameId, "A"); // Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.OnlyOnePersonEvent), - (gameState) => gameState == "Preparing" + (OnlyOnePersonEventArgs e) => e.GameStage == "Preparing" ); } @@ -130,9 +131,9 @@ public async Task 有人沒有準備_房主開始遊戲失敗() await hub.SendAsync(nameof(MonopolyHub.GameStart), gameId, "A"); // Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.SomePlayersPreparingEvent), - (gameState, players) => gameState == "Preparing" && players.OrderBy(x => x).SequenceEqual(new[] { "B" }.OrderBy(x => x)) + (SomePlayersPreparingEventArgs e) => e.GameStage == "Preparing" && e.PlayerIds.OrderBy(x => x).SequenceEqual(new[] { "B" }.OrderBy(x => x)) ); } } diff --git a/Test/ServerTests/AcceptanceTests/MortgageTest.cs b/Test/ServerTests/AcceptanceTests/MortgageTest.cs index 055c1c8..b1e146c 100644 --- a/Test/ServerTests/AcceptanceTests/MortgageTest.cs +++ b/Test/ServerTests/AcceptanceTests/MortgageTest.cs @@ -1,5 +1,6 @@ using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -51,10 +52,8 @@ public async Task 玩家抵押房地產() // Assert // A 抵押房地產 - hub.Verify( - nameof(IMonopolyResponses.PlayerMortgageEvent), - (playerId, playerMoney, blockId, deadLine) - => playerId == "A" && playerMoney == 5700 && blockId == "A1" && deadLine == 10); + hub.Verify(nameof(IMonopolyResponses.PlayerMortgageEvent), + (PlayerMortgageEventArgs e) => e is { PlayerId: "A", PlayerMoney: 5700, LandId: "A1", DeadLine: 10 }); hub.VerifyNoElseEvent(); } @@ -92,10 +91,9 @@ public async Task 玩家不能抵押已抵押房地產() // Assert // A 抵押房地產 - hub.Verify( - nameof(IMonopolyResponses.PlayerCannotMortgageEvent), - (playerId, playerMoney, blockId) - => playerId == "A" && playerMoney == 1000 && blockId == "A1"); + hub.Verify(nameof(IMonopolyResponses.PlayerCannotMortgageEvent), + (PlayerCannotMortgageEventArgs e) + => e is { PlayerId: "A", PlayerMoney: 1000, LandId: "A1" }); hub.VerifyNoElseEvent(); } @@ -129,10 +127,8 @@ public async Task 玩家抵押非自有房地產() // Assert // A 抵押房地產 - hub.Verify( - nameof(IMonopolyResponses.PlayerCannotMortgageEvent), - (playerId, playerMoney, blockId) - => playerId == "A" && playerMoney == 5000 && blockId == "A1"); + hub.Verify(nameof(IMonopolyResponses.PlayerCannotMortgageEvent), + (PlayerCannotMortgageEventArgs e) => e is { PlayerId: "A", PlayerMoney: 5000, LandId: "A1" }); hub.VerifyNoElseEvent(); } } diff --git a/Test/ServerTests/AcceptanceTests/PayTollTest.cs b/Test/ServerTests/AcceptanceTests/PayTollTest.cs index 9390cc8..048909f 100644 --- a/Test/ServerTests/AcceptanceTests/PayTollTest.cs +++ b/Test/ServerTests/AcceptanceTests/PayTollTest.cs @@ -1,5 +1,6 @@ using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -59,10 +60,8 @@ public async Task 玩家在別人的土地上付過路費() // Assert // A 付過路費 - hub.Verify( - nameof(IMonopolyResponses.PlayerPayTollEvent), - (playerId, playerMoney, ownerId, ownerMoney) - => playerId == "A" && playerMoney == 950 && ownerId == "B" && ownerMoney == 1050); + hub.Verify(nameof(IMonopolyResponses.PlayerPayTollEvent), + (PlayerPayTollEventArgs e) => e is { PlayerId: "A", PlayerMoney: 950, OwnerId: "B", OwnerMoney: 1050 }); hub.VerifyNoElseEvent(); } @@ -112,10 +111,8 @@ public async Task 地主在監獄中玩家無須付過路費() // Assert // A 付過路費 - hub.Verify( - nameof(IMonopolyResponses.PlayerDoesntNeedToPayTollEvent), - (playerId, playerMoney) - => playerId == "A" && playerMoney == 1000); + hub.Verify(nameof(IMonopolyResponses.PlayerDoesntNeedToPayTollEvent), + (PlayerDoesntNeedToPayTollEventArgs e) => e is { PlayerId: "A", PlayerMoney: 1000 }); hub.VerifyNoElseEvent(); } @@ -164,10 +161,8 @@ public async Task 地主在停車場玩家無須付過路費() // Assert // A 付過路費 - hub.Verify( - nameof(IMonopolyResponses.PlayerDoesntNeedToPayTollEvent), - (playerId, playerMoney) - => playerId == "A" && playerMoney == 1000); + hub.Verify(nameof(IMonopolyResponses.PlayerDoesntNeedToPayTollEvent), + (PlayerDoesntNeedToPayTollEventArgs e) => e is { PlayerId: "A", PlayerMoney: 1000 }); hub.VerifyNoElseEvent(); } @@ -215,10 +210,8 @@ public async Task 玩家在別人的土地上但餘額不足以付過路費() // Assert // A 付過路費 - hub.Verify( - nameof(IMonopolyResponses.PlayerTooPoorToPayTollEvent), - (playerId, playerMoney, toll) - => playerId == "A" && playerMoney == 30 && toll == 50); + hub.Verify(nameof(IMonopolyResponses.PlayerTooPoorToPayTollEvent), + (PlayerTooPoorToPayTollEventArgs e) => e is { PlayerId: "A", PlayerMoney: 30, Toll: 50 }); hub.VerifyNoElseEvent(); } @@ -265,10 +258,8 @@ public async Task 玩家在別人的車站上付過路費() // Assert // A 付過路費 - hub.Verify( - nameof(IMonopolyResponses.PlayerPayTollEvent), - (playerId, playerMoney, ownerId, ownerMoney) - => playerId == "A" && playerMoney == 2000 && ownerId == "B" && ownerMoney == 2000); + hub.Verify(nameof(IMonopolyResponses.PlayerPayTollEvent), + (PlayerPayTollEventArgs e) => e is { PlayerId: "A", PlayerMoney: 2000, OwnerId: "B", OwnerMoney: 2000 }); hub.VerifyNoElseEvent(); } diff --git a/Test/ServerTests/AcceptanceTests/PlayerJoinGameTest.cs b/Test/ServerTests/AcceptanceTests/PlayerJoinGameTest.cs index ad71e07..9965f15 100644 --- a/Test/ServerTests/AcceptanceTests/PlayerJoinGameTest.cs +++ b/Test/ServerTests/AcceptanceTests/PlayerJoinGameTest.cs @@ -5,6 +5,7 @@ using SharedLibrary; using System.Net.Http.Headers; using System.Net.Http.Json; +using SharedLibrary.ResponseArgs.Monopoly; namespace ServerTests.AcceptanceTests; @@ -37,10 +38,11 @@ public async Task 玩家建立連線成功() await CreateGameAsync("A", "A", "B", "C"); // Act - VerificationHub hub = await server.CreateHubConnectionAsync("1", "A"); + var hub = await server.CreateHubConnectionAsync("1", "A"); // Assert - hub.Verify(nameof(IMonopolyResponses.PlayerJoinGameEvent), id => id == "A"); + hub.Verify(nameof(IMonopolyResponses.PlayerJoinGameEvent), + (PlayerJoinGameEventArgs e) => e.PlayerId == "A"); } [TestMethod] diff --git a/Test/ServerTests/AcceptanceTests/PreparedTest.cs b/Test/ServerTests/AcceptanceTests/PreparedTest.cs index e9c14ae..7cdee15 100644 --- a/Test/ServerTests/AcceptanceTests/PreparedTest.cs +++ b/Test/ServerTests/AcceptanceTests/PreparedTest.cs @@ -1,6 +1,7 @@ using Application.DataModels; using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -53,9 +54,9 @@ public async Task 玩家成功準備() await hub.SendAsync(nameof(MonopolyHub.PlayerReady), gameId, "B"); // Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlayerReadyEvent), - (playerId, playerState) => (playerId, playerState) == ("B", "Normal") + (PlayerReadyEventArgs e) => e is { PlayerId: "B", PlayerState: "Normal" } ); } @@ -87,9 +88,8 @@ public async Task 玩家取消準備() await hub.SendAsync(nameof(MonopolyHub.PlayerReady), gameId, "A"); // Assert - hub.Verify( - nameof(IMonopolyResponses.PlayerReadyEvent), - (playerId, playerState) => (playerId, playerState) == ("A", "Ready") + hub.Verify(nameof(IMonopolyResponses.PlayerReadyEvent), + (PlayerReadyEventArgs e) => e is {PlayerId: "A", PlayerState: "Ready" } ); } @@ -128,9 +128,9 @@ public async Task 玩家未選擇位置按下準備() await hub.SendAsync(nameof(MonopolyHub.PlayerReady), gameId, "B"); // Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlayerCannotReadyEvent), - (playerId, playerState, roleId, locationId) => (playerId, playerState, roleId, locationId) == ("B", "Ready", "2", 0) + (PlayerCannotReadyEventArgs e) => e is { PlayerId: "B", PlayerState: "Ready", RoleId: "2", LocationId: 0 } ); } @@ -169,9 +169,9 @@ public async Task 玩家未選擇角色按下準備() await hub.SendAsync(nameof(MonopolyHub.PlayerReady), gameId, "B"); // Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlayerCannotReadyEvent), - (playerId, playerState, roleId, locationId) => (playerId, playerState, roleId, locationId) == ("B", "Ready", null, 2) + (PlayerCannotReadyEventArgs e) => e is { PlayerId: "B", PlayerState: "Ready", RoleId: null, LocationId: 2 } ); } } diff --git a/Test/ServerTests/AcceptanceTests/RedeemTest.cs b/Test/ServerTests/AcceptanceTests/RedeemTest.cs index 260cd85..1c4e2bd 100644 --- a/Test/ServerTests/AcceptanceTests/RedeemTest.cs +++ b/Test/ServerTests/AcceptanceTests/RedeemTest.cs @@ -1,5 +1,6 @@ using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -53,10 +54,8 @@ public async Task 玩家贖回房地產() // Assert // A 贖回房地產 - hub.Verify( - nameof(IMonopolyResponses.PlayerRedeemEvent), - (playerId, playerMoney, blockId) - => playerId == "A" && playerMoney == 2000 && blockId == "A1"); + hub.Verify(nameof(IMonopolyResponses.PlayerRedeemEvent), + (PlayerRedeemEventArgs e) => e is { PlayerId: "A", LandId: "A1", PlayerMoney: 2000 }); hub.VerifyNoElseEvent(); } @@ -98,10 +97,9 @@ public async Task 玩家餘額不足以贖回房地產() // Assert // A 贖回房地產 - hub.Verify( - nameof(IMonopolyResponses.PlayerTooPoorToRedeemEvent), - (playerId, playerMoney, blockId, redeemPrice) - => playerId == "A" && playerMoney == 2000 && blockId == "A1" && redeemPrice == 3000); + hub.Verify(nameof(IMonopolyResponses.PlayerTooPoorToRedeemEvent), + (PlayerTooPoorToRedeemEventArgs e) => + e is { PlayerId: "A", LandId: "A1", PlayerMoney: 2000, RedeemPrice: 3000 }); hub.VerifyNoElseEvent(); } } \ No newline at end of file diff --git a/Test/ServerTests/AcceptanceTests/RollDiceTest.cs b/Test/ServerTests/AcceptanceTests/RollDiceTest.cs index 4d7d50a..957f6d9 100644 --- a/Test/ServerTests/AcceptanceTests/RollDiceTest.cs +++ b/Test/ServerTests/AcceptanceTests/RollDiceTest.cs @@ -1,6 +1,7 @@ -using Application.Common; +using Domain.Events; using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -8,12 +9,12 @@ namespace ServerTests.AcceptanceTests; [TestClass] public class RollDiceTest { - private MonopolyTestServer server = default!; + private MonopolyTestServer _server = default!; [TestInitialize] public void Setup() { - server = new MonopolyTestServer(); + _server = new MonopolyTestServer(); } [TestMethod] @@ -26,21 +27,21 @@ public void Setup() public async Task 玩家擲骰後移動棋子() { // Arrange - var A = new { Id = "A" }; + var a = new { Id = "A" }; const string gameId = "1"; var monopolyBuilder = new MonopolyBuilder("1") .WithPlayer( - new PlayerBuilder(A.Id) + new PlayerBuilder(a.Id) .WithPosition("F4", Direction.Up) .Build() ) - .WithMockDice(new[] { 6 }) - .WithCurrentPlayer(new CurrentPlayerStateBuilder(A.Id).Build()); + .WithMockDice([6]) + .WithCurrentPlayer(new CurrentPlayerStateBuilder(a.Id).Build()); - monopolyBuilder.Save(server); + monopolyBuilder.Save(_server); - var hub = await server.CreateHubConnectionAsync(gameId, "A"); + var hub = await _server.CreateHubConnectionAsync(gameId, "A"); // Act await hub.SendAsync(nameof(MonopolyHub.PlayerRollDice), gameId, "A"); @@ -53,9 +54,8 @@ public async Task 玩家擲骰後移動棋子() // A 移動到 A2,方向為 Right,剩下 2 步 // A 移動到 A3,方向為 Down,剩下 1 步 // A 移動到 A4,方向為 Down,剩下 0 步 - hub.Verify( - nameof(IMonopolyResponses.PlayerRolledDiceEvent), - (playerId, diceCount) => playerId == "A" && diceCount == 6); + hub.Verify(nameof(IMonopolyResponses.PlayerRolledDiceEvent), + (PlayerRolledDiceEventArgs e) => e is { PlayerId: "A", DiceCount: 6 }); VerifyChessMovedEvent(hub, "A", "Start", "Right", 5); VerifyChessMovedEvent(hub, "A", "A1", "Right", 4); VerifyChessMovedEvent(hub, "A", "Station1", "Right", 3); @@ -77,7 +77,7 @@ public async Task 玩家擲骰後移動棋子到需要選擇方向的地方() { // Arrange var A = new { Id = "A" }; - + string[] expectedDirections = [ "Right", "Down", "Left" ]; const string gameId = "1"; var monopolyBuilder = new MonopolyBuilder("1") .WithPlayer( @@ -85,12 +85,12 @@ public async Task 玩家擲骰後移動棋子到需要選擇方向的地方() .WithPosition("F4", Direction.Up) .Build() ) - .WithMockDice(new[] { 2, 6 }) + .WithMockDice([2, 6]) .WithCurrentPlayer(new CurrentPlayerStateBuilder(A.Id).Build()); - monopolyBuilder.Save(server); + monopolyBuilder.Save(_server); - var hub = await server.CreateHubConnectionAsync(gameId, "A"); + var hub = await _server.CreateHubConnectionAsync(gameId, "A"); // Act await hub.SendAsync(nameof(MonopolyHub.PlayerRollDice), gameId, "A"); @@ -105,22 +105,25 @@ public async Task 玩家擲骰後移動棋子到需要選擇方向的地方() // A 移動到 A4,方向為 Down,剩下 2 步 // A 移動到 ParkingLot,方向為 Down,剩下 1 步 // A 需要選擇方向,可選擇的方向為 Right, Down, Left - hub.Verify( - nameof(IMonopolyResponses.PlayerRolledDiceEvent), - (playerId, diceCount) => playerId == "A" && diceCount == 8); + hub.Verify(nameof(IMonopolyResponses.PlayerRolledDiceEvent), + (PlayerRolledDiceEventArgs e) => e is { PlayerId: "A", DiceCount: 8 }); VerifyChessMovedEvent(hub, "A", "Start", "Right", 7); VerifyChessMovedEvent(hub, "A", "A1", "Right", 6); - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.ThroughStartEvent), - (playerId, gainMoney, totalMoney) => playerId == "A" && gainMoney == 3000 && totalMoney == 18000); + (PlayerThroughStartEventArgs e) => e is { PlayerId: "A", GainMoney: 3000, TotalMoney: 18000 }); VerifyChessMovedEvent(hub, "A", "Station1", "Right", 5); VerifyChessMovedEvent(hub, "A", "A2", "Right", 4); VerifyChessMovedEvent(hub, "A", "A3", "Down", 3); VerifyChessMovedEvent(hub, "A", "A4", "Down", 2); //VerifyChessMovedEvent(hub, "A", "ParkingLot", "Down", 1); - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlayerNeedToChooseDirectionEvent), - (playerId, directions) => playerId == "A" && directions.OrderBy(x => x).SequenceEqual(new[] { "Right", "Down", "Left" }.OrderBy(x => x))); + (PlayerNeedToChooseDirectionEventArgs e) => + { + return e.PlayerId == "A" && e.Directions.OrderBy(x => x) + .SequenceEqual(expectedDirections.OrderBy(x => x)); + }); hub.VerifyNoElseEvent(); } @@ -153,9 +156,9 @@ public async Task 玩家擲骰後移動棋子經過起點獲得獎勵金3000() .WithMockDice(new[] { 2, 2 }) .WithCurrentPlayer(new CurrentPlayerStateBuilder(A.Id).Build()); - monopolyBuilder.Save(server); + monopolyBuilder.Save(_server); - var hub = await server.CreateHubConnectionAsync(gameId, "A"); + var hub = await _server.CreateHubConnectionAsync(gameId, "A"); // Act await hub.SendAsync(nameof(MonopolyHub.PlayerRollDice), "1", "A"); @@ -167,19 +170,17 @@ public async Task 玩家擲骰後移動棋子經過起點獲得獎勵金3000() // A 移動到 Start,方向為 Right,剩下 1 步 // A 獲得獎勵金3000,共持有4000元 // A 移動到 A1,方向為 Right,剩下 0 步 - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlayerRolledDiceEvent), - (playerId, diceCount) => playerId == "A" && diceCount == 4); + (PlayerRolledDiceEventArgs e) => e is { PlayerId: "A", DiceCount: 4 }); VerifyChessMovedEvent(hub, "A", "Station4", "Up", 3); VerifyChessMovedEvent(hub, "A", "F4", "Up", 2); VerifyChessMovedEvent(hub, "A", "Start", "Right", 1); VerifyChessMovedEvent(hub, "A", "A1", "Right", 0); - hub.Verify( - nameof(IMonopolyResponses.ThroughStartEvent), - (playerId, gainMoney, totalMoney) => playerId == "A" && gainMoney == 3000 && totalMoney == 4000); - hub.Verify( - nameof(IMonopolyResponses.PlayerCanBuyLandEvent), - (playerId, blockId, landMoney) => playerId == "A" && blockId == "A1" && landMoney == 1000); + hub.Verify(nameof(IMonopolyResponses.ThroughStartEvent), + (PlayerThroughStartEventArgs e) => e is { PlayerId: "A", GainMoney: 3000, TotalMoney: 4000 }); + hub.Verify(nameof(IMonopolyResponses.PlayerCanBuyLandEvent), + (PlayerCanBuyLandEventArgs e) => e is { PlayerId: "A", LandId: "A1", Price: 1000 }); hub.VerifyNoElseEvent(); } @@ -209,9 +210,9 @@ public async Task 玩家擲骰後移動棋子到起點無法獲得獎勵金() .WithMockDice(new[] { 2, 1 }) .WithCurrentPlayer(new CurrentPlayerStateBuilder(A.Id).Build()); - monopolyBuilder.Save(server); + monopolyBuilder.Save(_server); - var hub = await server.CreateHubConnectionAsync(gameId, "A"); + var hub = await _server.CreateHubConnectionAsync(gameId, "A"); // Act await hub.SendAsync(nameof(MonopolyHub.PlayerRollDice), "1", "A"); @@ -222,15 +223,14 @@ public async Task 玩家擲骰後移動棋子到起點無法獲得獎勵金() // A 移動到 F4,方向為 Up,剩下 1 步 // A 移動到 Start,方向為 Right,剩下 0 步 // A 沒有獲得獎勵金,共持有1000元 - hub.Verify( - nameof(IMonopolyResponses.PlayerRolledDiceEvent), - (playerId, diceCount) => playerId == "A" && diceCount == 3); + hub.Verify(nameof(IMonopolyResponses.PlayerRolledDiceEvent), + (PlayerRolledDiceEventArgs e) => e is { PlayerId: "A", DiceCount: 3 }); VerifyChessMovedEvent(hub, "A", "Station4", "Up", 2); VerifyChessMovedEvent(hub, "A", "F4", "Up", 1); VerifyChessMovedEvent(hub, "A", "Start", "Right", 0); - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.CannotGetRewardBecauseStandOnStartEvent), - (playerId, totalMoney) => playerId == "A" && totalMoney == 1000); + (CannotGetRewardBecauseStandOnStartEventArgs e) => e.PlayerId == "A"); hub.VerifyNoElseEvent(); } @@ -259,27 +259,25 @@ public async Task 玩家擲骰後移動棋子到自己擁有地() .WithLandContract(A2.Id) .Build() ) - .WithMockDice(new[] { 1, 1 }) + .WithMockDice([1, 1]) .WithCurrentPlayer(new CurrentPlayerStateBuilder(A.Id).Build()) .WithLandHouse(A2.Id, A2.House); - monopolyBuilder.Save(server); + monopolyBuilder.Save(_server); - var hub = await server.CreateHubConnectionAsync(gameId, "A"); + var hub = await _server.CreateHubConnectionAsync(gameId, "A"); // Act await hub.SendAsync(nameof(MonopolyHub.PlayerRollDice), "1", "A"); // Assert // A 擲了 2 點 // A 移動到 A2,方向為 Right,剩下 0 步 // A 可以蓋房子 - hub.Verify( - nameof(IMonopolyResponses.PlayerRolledDiceEvent), - (playerId, diceCount) => playerId == "A" && diceCount == 2); + hub.Verify(nameof(IMonopolyResponses.PlayerRolledDiceEvent), + (PlayerRolledDiceEventArgs e) => e is { PlayerId: "A", DiceCount: 2 }); VerifyChessMovedEvent(hub, "A", "Station1", "Right", 1); VerifyChessMovedEvent(hub, "A", "A2", "Right", 0); - hub.Verify( - nameof(IMonopolyResponses.PlayerCanBuildHouseEvent), - (playerId, blockId, houseCount, upgradeMoney) => playerId == "A" && blockId == "A2" && houseCount == 4 && upgradeMoney == 1000); + hub.Verify(nameof(IMonopolyResponses.PlayerCanBuildHouseEvent), + (PlayerCanBuildHouseEventArgs e) => e is { PlayerId: "A", LandId: "A2", HouseCount: 4, Price: 1000 }); hub.VerifyNoElseEvent(); } @@ -314,26 +312,24 @@ public async Task 玩家擲骰後移動棋子到他人擁有地() .WithLandContract(A2.Id) .Build() ) - .WithMockDice(new[] { 2 }) + .WithMockDice([2]) .WithCurrentPlayer(new CurrentPlayerStateBuilder(A.Id).Build()); - monopolyBuilder.Save(server); + monopolyBuilder.Save(_server); - var hub = await server.CreateHubConnectionAsync(gameId, "A"); + var hub = await _server.CreateHubConnectionAsync(gameId, "A"); // Act await hub.SendAsync(nameof(MonopolyHub.PlayerRollDice), "1", "A"); // Assert // A 擲了 2 點 // A 移動到 A2,方向為 Right,剩下 0 步 // A 需要支付過路費 - hub.Verify( - nameof(IMonopolyResponses.PlayerRolledDiceEvent), - (playerId, diceCount) => playerId == "A" && diceCount == 2); + hub.Verify(nameof(IMonopolyResponses.PlayerRolledDiceEvent), + (PlayerRolledDiceEventArgs e) => e is { PlayerId: "A", DiceCount: 2 }); VerifyChessMovedEvent(hub, "A", "Station1", "Right", 1); VerifyChessMovedEvent(hub, "A", "A2", "Right", 0); - hub.Verify( - nameof(IMonopolyResponses.PlayerNeedsToPayTollEvent), - (playerId, ownId, toll) => playerId == "A" && ownId == "B" && toll == 50); + hub.Verify(nameof(IMonopolyResponses.PlayerNeedsToPayTollEvent), + (PlayerNeedsToPayTollEventArgs e) => e is { PlayerId: "A", OwnerId: "B", Toll: 50 }); hub.VerifyNoElseEvent(); } @@ -360,23 +356,21 @@ public async Task 玩家擲骰後移動棋子到空地() .WithMockDice(new[] { 2 }) .WithCurrentPlayer(new CurrentPlayerStateBuilder(A.Id).Build()); - monopolyBuilder.Save(server); + monopolyBuilder.Save(_server); - var hub = await server.CreateHubConnectionAsync(gameId, "A"); + var hub = await _server.CreateHubConnectionAsync(gameId, "A"); // Act await hub.SendAsync(nameof(MonopolyHub.PlayerRollDice), "1", "A"); // Assert // A 擲了 2 點 // A 移動到 A2,方向為 Right,剩下 0 步 // A 可以購買空地 - hub.Verify( - nameof(IMonopolyResponses.PlayerRolledDiceEvent), - (playerId, diceCount) => playerId == "A" && diceCount == 2); + hub.Verify(nameof(IMonopolyResponses.PlayerRolledDiceEvent), + (PlayerRolledDiceEventArgs e) => e is { PlayerId: "A", DiceCount: 2 }); VerifyChessMovedEvent(hub, "A", "Station1", "Right", 1); VerifyChessMovedEvent(hub, "A", "A2", "Right", 0); - hub.Verify( - nameof(IMonopolyResponses.PlayerCanBuyLandEvent), - (playerId, blockId, landMoney) => playerId == "A" && blockId == "A2" && landMoney == 1000); + hub.Verify(nameof(IMonopolyResponses.PlayerCanBuyLandEvent), + (PlayerCanBuyLandEventArgs e) => e is { PlayerId:"A", LandId: "A2", Price: 1000 }); hub.VerifyNoElseEvent(); } } \ No newline at end of file diff --git a/Test/ServerTests/AcceptanceTests/SelectDirectionTest.cs b/Test/ServerTests/AcceptanceTests/SelectDirectionTest.cs index 60196a9..6d5308c 100644 --- a/Test/ServerTests/AcceptanceTests/SelectDirectionTest.cs +++ b/Test/ServerTests/AcceptanceTests/SelectDirectionTest.cs @@ -1,6 +1,7 @@ using Application.Common; using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -56,10 +57,10 @@ public async Task 玩家選擇方向後在監獄停住() // A 選擇方向為 Left // A 停在 Jail,方向為 Left,剩下 0 步 // A 下一回合無法行動,暫停2回合 - hub.Verify(nameof(IMonopolyResponses.PlayerChooseDirectionEvent), - (playerId, direction) => playerId == A.Id && direction == "Left"); - hub.Verify(nameof(IMonopolyResponses.SuspendRoundEvent), - (playerId, suspendRounds) => playerId == A.Id && suspendRounds == 2); + hub.Verify(nameof(IMonopolyResponses.PlayerChooseDirectionEvent), + (PlayerChooseDirectionEventArgs e) => e is { PlayerId: "A", Direction: "Left" }); + hub.Verify(nameof(IMonopolyResponses.SuspendRoundEvent), + (SuspendRoundEventArgs e) => e is { PlayerId: "A", SuspendRounds: 2 }); hub.VerifyNoElseEvent(); var repo = server.GetRequiredService(); @@ -109,8 +110,8 @@ public async Task 玩家選擇方向後在停車場停住() // A 選擇方向為 Left // A 停在 ParkingLot,方向為 Left,剩下 0 步 - hub.Verify(nameof(IMonopolyResponses.PlayerChooseDirectionEvent), - (playerId, direction) => playerId == A.Id && direction == Direction.Left.ToString()); + hub.Verify(nameof(IMonopolyResponses.PlayerChooseDirectionEvent), + (PlayerChooseDirectionEventArgs e) => e.PlayerId == A.Id && e.Direction == Direction.Left.ToString()); hub.VerifyNoElseEvent(); diff --git a/Test/ServerTests/AcceptanceTests/SelectLocation.cs b/Test/ServerTests/AcceptanceTests/SelectLocation.cs index 8e1f11a..1007627 100644 --- a/Test/ServerTests/AcceptanceTests/SelectLocation.cs +++ b/Test/ServerTests/AcceptanceTests/SelectLocation.cs @@ -1,6 +1,7 @@ using Application.DataModels; using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -43,9 +44,9 @@ public async Task 玩家選擇沒人的位置() await hub.SendAsync(nameof(MonopolyHub.PlaySelectLocation), gameId, A.Id, A.selectLocationId); //Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlaySelectLocationEvent), - (playerId, locationId) => (playerId, locationId) == (A.Id, A.selectLocationId) + (PlaySelectLocationEventArgs e) => e is { PlayerId: "A", LocationId: 1 } ); hub.VerifyNoElseEvent(); } @@ -83,9 +84,9 @@ public async Task 玩家選擇有人的位置() await hub.SendAsync(nameof(MonopolyHub.PlaySelectLocation), gameId, A.Id, A.selectLocationId); //Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlayCannotSelectLocationEvent), - (playerId, locationId) => (playerId, locationId) == (A.Id, A.locationId) + (PlayCannotSelectLocationEventArgs e) => e is { PlayerId: "A", LocationId: 0 } ); hub.VerifyNoElseEvent(); } @@ -116,9 +117,9 @@ public async Task 有選位置的玩家更換到沒人的位置() await hub.SendAsync(nameof(MonopolyHub.PlaySelectLocation), gameId, A.Id, A.selectLocationId); //Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlaySelectLocationEvent), - (playerId, locationId) => (playerId, locationId) == (A.Id, A.selectLocationId) + (PlaySelectLocationEventArgs e) => e is { PlayerId: "A", LocationId: 2 } ); hub.VerifyNoElseEvent(); } diff --git a/Test/ServerTests/AcceptanceTests/SelectRoleTest.cs b/Test/ServerTests/AcceptanceTests/SelectRoleTest.cs index 384d588..7f34e2a 100644 --- a/Test/ServerTests/AcceptanceTests/SelectRoleTest.cs +++ b/Test/ServerTests/AcceptanceTests/SelectRoleTest.cs @@ -1,6 +1,7 @@ using Application.DataModels; using Server.Hubs; using SharedLibrary; +using SharedLibrary.ResponseArgs.Monopoly; using static ServerTests.Utils; namespace ServerTests.AcceptanceTests; @@ -41,9 +42,9 @@ public async Task 玩家選擇角色() await hub.SendAsync(nameof(MonopolyHub.PlayerSelectRole), gameId, "A", "1"); // Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlayerSelectRoleEvent), - (playerId, roleId) => (playerId, roleId) == ("A", "1") + (PlayerSelectRoleEventArgs e) => e is { PlayerId: "A", RoleId: "1" } ); } @@ -72,9 +73,9 @@ public async Task 玩家選擇角色後更換角色() await hub.SendAsync(nameof(MonopolyHub.PlayerSelectRole), gameId, "A", "2"); // Assert - hub.Verify( + hub.Verify( nameof(IMonopolyResponses.PlayerSelectRoleEvent), - (playerId, roleId) => (playerId, roleId) == ("A", "2") + (PlayerSelectRoleEventArgs e) => e is { PlayerId: "A", RoleId: "2" } ); } } diff --git a/Test/ServerTests/MonopolyTestServer.cs b/Test/ServerTests/MonopolyTestServer.cs index d423261..a376646 100644 --- a/Test/ServerTests/MonopolyTestServer.cs +++ b/Test/ServerTests/MonopolyTestServer.cs @@ -15,7 +15,6 @@ using SharedLibrary; using System.Collections.Concurrent; using System.IdentityModel.Tokens.Jwt; -using System.Reflection; using System.Security.Claims; using System.Security.Cryptography; using System.Text.Json; @@ -24,7 +23,7 @@ namespace ServerTests; internal class MonopolyTestServer : WebApplicationFactory { - public HttpClient Client { get; init; } + public HttpClient Client { get; } public MonopolyTestServer() { @@ -97,35 +96,34 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) internal class VerificationHub { - private readonly HubConnection Connection; + private readonly HubConnection _connection; - private readonly Dictionary> Queues; + private readonly Dictionary> _queues = new(); - public VerificationHub(HubConnection Connection) + public VerificationHub(HubConnection connection) { - this.Connection = Connection; - Queues = new(); + _connection = connection; ListenAllEvent(); } public async void VerifyDisconnection(int delay = 1000) { await Task.Delay(delay); - Assert.AreEqual(HubConnectionState.Disconnected, Connection.State); + Assert.AreEqual(HubConnectionState.Disconnected, _connection.State); } // 利用反射讀出所有HubResponse的Method,並且設置On function private void ListenAllEvent() { - Type interfaceType = typeof(IMonopolyResponses); - MethodInfo[] methods = interfaceType.GetMethods(); + var interfaceType = typeof(IMonopolyResponses); + var methods = interfaceType.GetMethods(); - foreach (MethodInfo method in methods) + foreach (var method in methods) { - ParameterInfo[] parameters = method.GetParameters(); - Queues.Add(method.Name, new()); + var parameters = method.GetParameters(); + _queues.Add(method.Name, new()); - Type[] parameterTypes = parameters.Select(x => x.ParameterType).ToArray(); - void handler(object?[] x) => Queues[method.Name].Enqueue(x!); - Connection.On(method.Name, parameterTypes, handler); + var parameterTypes = parameters.Select(x => x.ParameterType).ToArray(); + void handler(object?[] x) => _queues[method.Name].Enqueue(x!); + _connection.On(method.Name, parameterTypes, handler); } } @@ -136,7 +134,7 @@ private void Verify(string methodName, Func verify, int timeout) var startTime = DateTime.Now; while (true) { - if (Queues[methodName].TryDequeue(out var result)) + if (_queues[methodName].TryDequeue(out var result)) { var options = new JsonSerializerOptions() { @@ -148,35 +146,33 @@ private void Verify(string methodName, Func verify, int timeout) $"\n回傳結果為 {JsonSerializer.Serialize(result, options)}"); break; } - else + + // 如果已經斷開連線測試失敗 + if (_connection.State == HubConnectionState.Disconnected) { - // 如果已經斷開連線測試失敗 - if (Connection.State == HubConnectionState.Disconnected) - { - if (Queues[nameof(IMonopolyResponses.PlayerJoinGameFailedEvent)].TryPeek(out var errorMessages)) - Assert.Fail( - $""" - 已經斷開連線 - 訊息: - {string.Join("\n", errorMessages!)} - """); - } - // 計算已經等待的時間 - var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds; - if (elapsedMilliseconds >= timeout) - { + if (_queues[nameof(IMonopolyResponses.PlayerJoinGameFailedEvent)].TryPeek(out var errorMessages)) Assert.Fail( $""" - 超出預期時間 {timeout} ms,預期得到 Event【{methodName}】 - 可以嘗試檢查下面的問題: - 1. 在 EventBus 中,缺少 Event 的傳送 - 2. 在 Usecase 中,沒有使用 EventBus.PublishAsync - 3. 在 Domain 中,沒有 添加 Domain Event - """); - } - // 等待一段時間再繼續嘗試 - SpinWait.SpinUntil(() => false, 50); + 已經斷開連線 + 訊息: + {string.Join("\n", errorMessages!)} + """); + } + // 計算已經等待的時間 + var elapsedMilliseconds = (DateTime.Now - startTime).TotalMilliseconds; + if (elapsedMilliseconds >= timeout) + { + Assert.Fail( + $""" + 超出預期時間 {timeout} ms,預期得到 Event【{methodName}】 + 可以嘗試檢查下面的問題: + 1. 在 EventBus 中,缺少 Event 的傳送 + 2. 在 Usecase 中,沒有使用 EventBus.PublishAsync + 3. 在 Domain 中,沒有 添加 Domain Event + """); } + // 等待一段時間再繼續嘗試 + SpinWait.SpinUntil(() => false, 50); } } catch (KeyNotFoundException ex) @@ -203,7 +199,7 @@ 可以在 IMonopolyResponses 添加 【{methodName}】 以解決這個問題 public async Task SendAsync(string method, params object?[] args) { - await Connection.SendCoreAsync(method, args); + await _connection.SendCoreAsync(method, args); } public void Verify(string methodName, Func verify, int timeout = 1000) @@ -234,7 +230,7 @@ public void Verify(string methodName, Func(nameof(IMonopolyResponses.ChessMovedEvent), (PlayerId, BlockId, Direction, RemainingSteps) => - PlayerId == playerId && BlockId == blockId && Direction == direction && RemainingSteps == remainingSteps); + hub.Verify(nameof(IMonopolyResponses.ChessMovedEvent), (ChessMovedEventArgs e) => + e.PlayerId == playerId && e.BlockId == blockId && e.Direction == direction && e.RemainingSteps == remainingSteps); } public class MonopolyBuilder