generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 前端「確認角色身分」5 秒後能夠收到 SignalR 訊息,並列印「確認角色身分結束」 * feat: 女巫使用毒藥
- Loading branch information
Showing
20 changed files
with
675 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/BackEnd/src/Application/UseCases/WitchUsePoisonUseCase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Wsa.Gaas.Werewolf.Application.Common; | ||
using Wsa.Gaas.Werewolf.Domain.Events; | ||
using Wsa.Gaas.Werewolf.Domain.Exceptions; | ||
|
||
namespace Wsa.Gaas.Werewolf.Application.UseCases | ||
{ | ||
public class WitchUsePoisonRequest | ||
{ | ||
public ulong DiscordVoiceChannelId { get; set; } | ||
public ulong PlayerId { get; set; } | ||
public ulong TargetPlayerId { get; set; } | ||
} | ||
|
||
public class WitchUsePoisonUseCase : UseCase<WitchUsePoisonRequest, WitchUsePoisonEvent> | ||
{ | ||
public WitchUsePoisonUseCase(IRepository repository, GameEventBus gameEventBus) : base(repository, gameEventBus) | ||
{ | ||
} | ||
|
||
public override async Task ExecuteAsync(WitchUsePoisonRequest request, IPresenter<WitchUsePoisonEvent> presenter, CancellationToken cancellationToken = default) | ||
{ | ||
// 查 | ||
var game = Repository.FindByDiscordChannelId(request.DiscordVoiceChannelId); | ||
|
||
if (game == null) | ||
{ | ||
throw new GameNotFoundException(request.DiscordVoiceChannelId); | ||
} | ||
|
||
// 改 | ||
var events = game.WitchUsePoison(request.PlayerId, request.TargetPlayerId); | ||
|
||
// 存 | ||
await Repository.SaveAsync(game); | ||
|
||
// 推 | ||
await presenter.PresentAsync(events, cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Wsa.Gaas.Werewolf.Domain.Objects; | ||
|
||
namespace Wsa.Gaas.Werewolf.Domain.Events | ||
{ | ||
public class WitchUsePoisonEvent : GameEvent | ||
{ | ||
public WitchUsePoisonEvent(Game data) : base(data) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/BackEnd/src/InterfaceAdapter/WebApi/Endpoints/WitchUsePoisonEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Wsa.Gaas.Werewolf.Application.UseCases; | ||
using Wsa.Gaas.Werewolf.Domain.Events; | ||
using Wsa.Gaas.Werewolf.WebApi.Common; | ||
|
||
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints | ||
{ | ||
|
||
public class WitchUsePoisonResponse | ||
{ | ||
public required string Message { get; set; } | ||
} | ||
|
||
public class WitchUsePoisonEndpoint : WebApiEndpoint<WitchUsePoisonRequest, WitchUsePoisonEvent, WitchUsePoisonResponse> | ||
{ | ||
public override void Configure() | ||
{ | ||
Post("/games/{DiscordVoiceChannelId}/players/{playerId}:usePoison"); | ||
AllowAnonymous(); | ||
} | ||
|
||
public override async Task<WitchUsePoisonResponse> ExecuteAsync(WitchUsePoisonRequest req, CancellationToken ct) | ||
{ | ||
await UseCase.ExecuteAsync(req, this, ct); | ||
|
||
if (ViewModel == null) | ||
{ | ||
throw new Exception("View Model is null"); | ||
} | ||
|
||
return ViewModel; // <= 把 ViewModel 轉 JSON | ||
} | ||
|
||
public override Task PresentAsync(WitchUsePoisonEvent gameEvent, CancellationToken cancellationToken = default) | ||
{ | ||
ViewModel = new WitchUsePoisonResponse | ||
{ | ||
Message = "Ok", | ||
}; | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/BackEnd/test/WebApiTests/ATDD/GameTests/WitchUsePoisonTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using FastEndpoints; | ||
using Wsa.Gaas.Werewolf.Application.Common; | ||
using Wsa.Gaas.Werewolf.Application.UseCases; | ||
using Wsa.Gaas.Werewolf.Domain.Objects.Roles; | ||
using Wsa.Gaas.Werewolf.Domain.Objects; | ||
using Wsa.Gaas.Werewolf.WebApi.Endpoints; | ||
using Wsa.Gaas.Werewolf.WebApiTests.ATDD.Common; | ||
using Moq; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Wsa.Gaas.Werewolf.WebApiTests.ATDD.GameTests | ||
{ | ||
public class WitchUsePoisonTests | ||
{ | ||
readonly WebApiTestServer _server = new(); | ||
|
||
[OneTimeSetUp] | ||
public async Task OneTimeSetup() | ||
{ | ||
await _server.StartAsync(); | ||
} | ||
|
||
[Test] | ||
public async Task WitchUsePoison() | ||
{ | ||
// Arrange | ||
var game = _server.CreateGameBuilder() | ||
.WithRandomDiscordVoiceChannel() | ||
.WithGameStatus(GameStatus.WitchRoundStarted) | ||
.WithRandomPlayers(9) | ||
.Build(); | ||
|
||
var witch = game.Players.First(x => x.Role is Witch); | ||
|
||
var targetPlayer = game.Players.First(x => x.IsDead == false); | ||
|
||
var request = new WitchUsePoisonRequest | ||
{ | ||
DiscordVoiceChannelId = game.DiscordVoiceChannelId, | ||
PlayerId = witch.UserId, | ||
TargetPlayerId = targetPlayer.UserId, | ||
}; | ||
|
||
// Act | ||
var response = await _server.Client.POSTAsync< | ||
WitchUsePoisonEndpoint, | ||
WitchUsePoisonRequest, | ||
WitchUsePoisonResponse>(request); | ||
|
||
// Assert 200 | ||
response.Response.EnsureSuccessStatusCode(); | ||
|
||
// | ||
var repository = _server.GetRequiredService<IRepository>(); | ||
|
||
var actualGame = repository.FindByDiscordChannelId(game.DiscordVoiceChannelId); | ||
|
||
var actualTargetPlayer = actualGame!.Players.First(x => x.UserId == targetPlayer.UserId); | ||
var actualWitch = actualGame!.Players.First(x => x.Role is Witch); | ||
|
||
// 新標記被女巫毒 | ||
((actualTargetPlayer.BuffStatus & BuffStatus.KilledByWitch) == BuffStatus.KilledByWitch) | ||
.Should().BeTrue(); | ||
|
||
// 女巫毒藥已使用 | ||
actualWitch.IsPoisonUsed.Should().BeTrue(); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.