fix player rotation with different team sizes
This commit is contained in:
parent
4c01fda12c
commit
d0e4d01985
|
|
@ -35,6 +35,10 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var playerIndexPerTeam = new Dictionary<int, int>();
|
||||||
|
for (int i = 0; i < options.Teams.Count; i++)
|
||||||
|
playerIndexPerTeam[i] = 0;
|
||||||
|
|
||||||
return new ChristmasTreeGameModel
|
return new ChristmasTreeGameModel
|
||||||
{
|
{
|
||||||
Variant = options.Variant,
|
Variant = options.Variant,
|
||||||
|
|
@ -43,6 +47,7 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
Teams = options.Teams.ToList(),
|
Teams = options.Teams.ToList(),
|
||||||
CurrentTeamIndex = 0,
|
CurrentTeamIndex = 0,
|
||||||
CurrentPlayerIndexInTeam = 0,
|
CurrentPlayerIndexInTeam = 0,
|
||||||
|
PlayerIndexPerTeam = playerIndexPerTeam,
|
||||||
EnableContinueOnMiss = options.EnableContinueOnMiss,
|
EnableContinueOnMiss = options.EnableContinueOnMiss,
|
||||||
MaxContinueThrows = options.MaxContinueThrows,
|
MaxContinueThrows = options.MaxContinueThrows,
|
||||||
ContinueThrowsRemaining = 0,
|
ContinueThrowsRemaining = 0,
|
||||||
|
|
@ -348,23 +353,16 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
ChristmasTreeGameModel model,
|
ChristmasTreeGameModel model,
|
||||||
List<TriggerEvent> triggers)
|
List<TriggerEvent> triggers)
|
||||||
{
|
{
|
||||||
// Rotate to next team and player
|
// Advance current team's player index independently
|
||||||
int nextTeamIndex = (model.CurrentTeamIndex + 1) % model.Teams.Count;
|
var playerIndices = new Dictionary<int, int>(
|
||||||
int nextPlayerIndex = 0;
|
model.PlayerIndexPerTeam.Count > 0 ? model.PlayerIndexPerTeam
|
||||||
|
: Enumerable.Range(0, model.Teams.Count).ToDictionary(i => i, _ => 0));
|
||||||
|
|
||||||
if (nextTeamIndex == 0)
|
int currentTeamSize = Math.Max(1, model.Teams[model.CurrentTeamIndex].PlayerIds.Count);
|
||||||
{
|
playerIndices[model.CurrentTeamIndex] = (playerIndices[model.CurrentTeamIndex] + 1) % currentTeamSize;
|
||||||
// Wrapped around - increment player index within teams
|
|
||||||
// This assumes all teams have same number of players
|
int nextTeamIndex = (model.CurrentTeamIndex + 1) % model.Teams.Count;
|
||||||
// For varying team sizes, we track per-team player index
|
int nextPlayerIndex = playerIndices[nextTeamIndex];
|
||||||
nextPlayerIndex = (model.CurrentPlayerIndexInTeam + 1) %
|
|
||||||
Math.Max(1, model.Teams[nextTeamIndex].PlayerIds.Count);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nextPlayerIndex = model.CurrentPlayerIndexInTeam %
|
|
||||||
Math.Max(1, model.Teams[nextTeamIndex].PlayerIds.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
var nextPlayerId = model.Teams[nextTeamIndex].PlayerIds.Count > nextPlayerIndex
|
var nextPlayerId = model.Teams[nextTeamIndex].PlayerIds.Count > nextPlayerIndex
|
||||||
? model.Teams[nextTeamIndex].PlayerIds[nextPlayerIndex]
|
? model.Teams[nextTeamIndex].PlayerIds[nextPlayerIndex]
|
||||||
|
|
@ -373,7 +371,8 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
model = model with
|
model = model with
|
||||||
{
|
{
|
||||||
CurrentTeamIndex = nextTeamIndex,
|
CurrentTeamIndex = nextTeamIndex,
|
||||||
CurrentPlayerIndexInTeam = nextPlayerIndex
|
CurrentPlayerIndexInTeam = nextPlayerIndex,
|
||||||
|
PlayerIndexPerTeam = playerIndices
|
||||||
};
|
};
|
||||||
|
|
||||||
return (model, new ThrowResult
|
return (model, new ThrowResult
|
||||||
|
|
@ -643,16 +642,15 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear selection state and rotate to next player
|
// Clear selection state and rotate to next player
|
||||||
|
var playerIndices = new Dictionary<int, int>(
|
||||||
|
model.PlayerIndexPerTeam.Count > 0 ? model.PlayerIndexPerTeam
|
||||||
|
: Enumerable.Range(0, model.Teams.Count).ToDictionary(i => i, _ => 0));
|
||||||
|
|
||||||
|
int currentTeamSize = Math.Max(1, model.Teams[model.CurrentTeamIndex].PlayerIds.Count);
|
||||||
|
playerIndices[model.CurrentTeamIndex] = (playerIndices[model.CurrentTeamIndex] + 1) % currentTeamSize;
|
||||||
|
|
||||||
int nextTeamIndex = (model.CurrentTeamIndex + 1) % model.Teams.Count;
|
int nextTeamIndex = (model.CurrentTeamIndex + 1) % model.Teams.Count;
|
||||||
int nextPlayerIndex = model.CurrentPlayerIndexInTeam;
|
int nextPlayerIndex = playerIndices[nextTeamIndex];
|
||||||
if (nextTeamIndex == 0)
|
|
||||||
{
|
|
||||||
nextPlayerIndex = (nextPlayerIndex + 1) % Math.Max(1, model.Teams[nextTeamIndex].PlayerIds.Count);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
nextPlayerIndex = nextPlayerIndex % Math.Max(1, model.Teams[nextTeamIndex].PlayerIds.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
var nextPlayerId = model.Teams[nextTeamIndex].PlayerIds.Count > nextPlayerIndex
|
var nextPlayerId = model.Teams[nextTeamIndex].PlayerIds.Count > nextPlayerIndex
|
||||||
? model.Teams[nextTeamIndex].PlayerIds[nextPlayerIndex]
|
? model.Teams[nextTeamIndex].PlayerIds[nextPlayerIndex]
|
||||||
|
|
@ -663,7 +661,8 @@ public class ChristmasTreeGameLogicService : IGameLogicService
|
||||||
TeamTrees = teamTrees,
|
TeamTrees = teamTrees,
|
||||||
OpponentSelectingTeamIndex = null,
|
OpponentSelectingTeamIndex = null,
|
||||||
CurrentTeamIndex = nextTeamIndex,
|
CurrentTeamIndex = nextTeamIndex,
|
||||||
CurrentPlayerIndexInTeam = nextPlayerIndex
|
CurrentPlayerIndexInTeam = nextPlayerIndex,
|
||||||
|
PlayerIndexPerTeam = playerIndices
|
||||||
};
|
};
|
||||||
|
|
||||||
return GameActionResult.SuccessResult(
|
return GameActionResult.SuccessResult(
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,11 @@ public record ChristmasTreeGameModel : IGameModel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int CurrentPlayerIndexInTeam { get; set; }
|
public int CurrentPlayerIndexInTeam { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Player index per team (key = team index). Each team cycles independently.
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<int, int> PlayerIndexPerTeam { get; init; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether continue-on-miss variant is enabled.
|
/// Whether continue-on-miss variant is enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue