Skip to content

Commit

Permalink
feat: 女巫使用毒藥
Browse files Browse the repository at this point in the history
  • Loading branch information
ricksu978 committed Aug 19, 2023
1 parent a67cfc6 commit aa192b8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
41 changes: 41 additions & 0 deletions src/BackEnd/src/Domain/Objects/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,46 @@ internal List<GameEvent> AnnounceNightResult()
return events;
}

public WitchUsePoisonEvent WitchUsePoison(ulong witchUserId, ulong targetPlayerId)
{
var witch = Players.FirstOrDefault(x => x.UserId == witchUserId);

if (witch is null)
{
throw new PlayerNotFoundException(DiscordVoiceChannelId, witchUserId);
}

if (witch.Role is not Witch)
{
throw new PlayerNotWitchException("Player not witch");
}

if (witch.IsPoisonUsed)
{
throw new GameException("Witch poison is used");
}

// 找出被狼殺的玩家
var targetPlayer = Players.FirstOrDefault(x =>
x.UserId == targetPlayerId
);

if (targetPlayer == null)
{
throw new GameException("Target player not found");
}

if (targetPlayer.IsDead)
{
throw new GameException("Target player is dead");
}

// 標記被女巫毒
targetPlayer.BuffStatus |= BuffStatus.KilledByWitch;

// 標記毒藥已使用
witch.IsPoisonUsed = true;

return new WitchUsePoisonEvent(this);
}
}
1 change: 1 addition & 0 deletions src/BackEnd/src/Domain/Objects/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Player
public BuffStatus BuffStatus { get; internal set; }
public bool IsDead { get; internal set; }
public bool IsAntidoteUsed { get; internal set; }
public bool IsPoisonUsed { get; internal set; }

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private Player() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ public override async Task<WitchUsePoisonResponse> ExecuteAsync(WitchUsePoisonRe
{
await UseCase.ExecuteAsync(req, this, ct);

//if (ViewModel == null)
//{
// throw new Exception("View Model is null");
//}

// HTTP JSON Response
//return ViewModel; // <= 把 ViewModel 轉 JSON
return ViewModel;
}

if (ViewModel == null)
{
throw new Exception("View Model is null");
}

return ViewModel; // <= 把 ViewModel 轉 JSON
}

public override Task PresentAsync(WitchUsePoisonEvent gameEvent, CancellationToken cancellationToken = default)
{
Expand Down

0 comments on commit aa192b8

Please sign in to comment.