// Converts unit data from messages to actual units for the game state // Also generates IDs for units // The reinforcement point calculation is also justified as it is only used in multiplayer and is not used in singleplayer games void InitialiseArmy(BaseArmy army) { List <Unit> units = new List <Unit>(); if (army.Units.Count == 0) { throw new ServerClientException("You cannot play a game with an empty base army"); } int pointsSpent = 0; foreach (var unitConfiguration in army.Units) { if (unitConfiguration.FactionId != PlayerState.Faction.Id) { throw new ServerClientException("Tried to deploy an army with units from another faction"); } Unit unit = new Unit(PlayerState, Game.GetUnitId(), unitConfiguration, Server); pointsSpent += unit.Points; units.Add(unit); } int pointsAvailable = Game.GameConfiguration.Points; if (pointsSpent > pointsAvailable) { throw new ServerClientException("You have spent too many points"); } int reinforcementPoints = (int)(GameConstants.ReinforcementPointsPenaltyFactor * (pointsAvailable - pointsSpent) + GameConstants.ReinforcementPointsBaseRatio * pointsAvailable); PlayerState.InitialiseArmy(units, reinforcementPoints); }
private JoinGameRequest(BaseArmy army, bool isPrivate, string owner, string privateKey) { Army = army; IsPrivate = isPrivate; Owner = owner; PrivateKey = privateKey; }
public GameStart(GameConfiguration gameConfiguration, BaseArmy myArmy, BaseArmy enemyArmy, string opponent, int reinforcementPoints) { GameConfiguration = gameConfiguration; MyArmy = myArmy; EnemyArmy = enemyArmy; Opponent = opponent; ReinforcementPoints = reinforcementPoints; }
public static JoinGameRequest JoinPrivateGame(BaseArmy army, string privateKey) { return(new JoinGameRequest(army, false, null, privateKey)); }
public static JoinGameRequest JoinPublicGame(BaseArmy army, string owner) { return(new JoinGameRequest(army, false, owner, null)); }
public CreateGameRequest(BaseArmy army, bool isPrivate, GameConfiguration gameConfiguration) { Army = army; IsPrivate = isPrivate; GameConfiguration = gameConfiguration; }