public void AddCommand(ServerBattleCommand cmd) { if (cmd == null) return; if (currentTurn == null) { currentTurn = new BattleTurn(this, cmd.turn); } if (cmd.turn != currentTurn.turnID) { Utils.Log("Invalid turn received: " + cmd.turn.ToString(), 0); } currentTurn.AddCommand(cmd); }
public void Update() { if (this.finished) return; if (this.loading) { if (Utils.GetTickCount() - loadTime > 1000 * 20) { this.Cancel(null, ServerBattle.HashFailure); } return; } if (turnEnd) { foreach (ServerPlayer player in _players) { if (player.turnState != BattleTurn.turnNext) return; } turnEnd = false; byte state = BattleTurn.turnNext; foreach (ServerPlayer player in _players) { ServerMessage msg = new ServerMessage(Protocol.netBattleTurn); msg.WriteByte(state); player.SendMessage(msg, 0); player.turnState = BattleTurn.turnWaiting; } actionTime = Utils.GetTickCount(); currentTurn = null; return; } if (currentTurn != null) { int result = currentTurn.Update(); switch (result) { case BattleTurn.turnTimeOut: Utils.Log("Battle time out...", 0); this.Cancel(null, winningSide); return; case BattleTurn.turnFinished: _turns.Add(currentTurn); actionTime = Utils.GetTickCount(); currentTurn.Finish(); turnEnd = true; break; } if (Utils.GetTickCount() - actionTime > 1000 * 60 * 4) { this.Cancel(null, ServerBattle.HashFailure); return; } } }
public ServerBattle(BattleRules Rules, byte battleMode) { this.finished = false; this.rules = Rules; this.timeStamp = Utils.GetTickCount(); this.seed = Utils.Random(99999); this.secondsPerTurn = Settings.BattleTimeOutinSeconds; this.currentTurn = null; this.battleMode = battleMode; this._players = new List<ServerPlayer>(); this.actionTime = Utils.GetTickCount(); this.loading = true; this.loadTime = this.actionTime; }