Files
Giants/Src/Giants.Core/Src/Commands/PrepareMatchCommand.cs
mcmuzzle a1a1d94a14
All checks were successful
check main state / build (9.0.x) (push) Successful in 1m26s
Ajout de la base de PrepareMatchCommand avec un test
2025-04-17 11:06:21 +02:00

59 lines
1.5 KiB
C#

using Giants.Core.Enums;
using Giants.Core.Exceptions;
namespace Giants.Core.Commands;
public class PrepareMatchCommand : BaseMatchCommand<PrepareMatchResult>
{
public required IList<int> PlayerIDs { get; init; }
protected override PrepareMatchResult LocalMatchExecute(Match match)
{
if (PlayerIDs.Count < 3 || PlayerIDs.Count > 5 || null == match)
return new PrepareMatchResult();
//Gestion des assets des joueurs
for (int i = 0; i < PlayerIDs.Count; i++)
{
match.SetPlayer(i, PlayerIDs[i]);
//marqueurs tribaux
int nbMarker = NbMarkerPerPlayer(PlayerIDs.Count);
for (int t = 0; t < Match.MaxTribalMarker; t++)
{
if (t < nbMarker)
{
match.AddTribalMarkerToPlayer(i);
}
else
{
var piece = match.GetPlayerTribalTokenFromBox(i);
match.AssignPiece(piece, PiecePosition.Urne);
}
}
}
return new PrepareMatchResult()
{
Success = true,
Match = match
};
}
private static int NbMarkerPerPlayer(int nbTotalPlayer)
{
return nbTotalPlayer switch
{
3 => 7,
4 => 6,
5 => 5,
_ => throw new DataConversionException("Wrong player count for NbMarkerPerPlayer")
};
}
}
public class PrepareMatchResult : BaseCommandResult
{
public Match? Match { get; init; }
}