public bool IsToxic(Location loc) { return(ToxicLocations.Any(x => x.Equals(loc))); }
public void NextRound() { Round += 1; DebugIndicatorCircles.Clear(); DebugIndicatorLines.Clear(); DebugIndicatorTexts.Clear(); for (int i = 1; i <= ToxRate; i++) { if (_NonToxicLocations.Any()) { Location newToxicLoc = _NonToxicLocations.First(); _NonToxicLocations.Remove(newToxicLoc); ToxicLocations.Add(newToxicLoc); } } RobotControllers.ForEach(x => x.TurnCompleted = false); // Process Round foreach (RobotController rc in RobotControllers.OrderBy(x => Rnd.Next())) { // Alte nachrichten des Robots löschen foreach (RadioMessage rm in RadioMessages.Where(x => x.RobotId == rc.Id).ToList()) { RadioMessages.Remove(rm); } rc.AttackLocation = null; rc.HasOutage = false; if (rc.Energy < 50) { rc.HasOutage = (Rnd.Next(0, 51) > rc.Energy); } rc.Energy += rc.RobotType.EnergyRegeneration; if (rc.Energy > rc.RobotType.MaxEnergy) { rc.Energy = rc.RobotType.MaxEnergy; } if (rc.Timeouts > 0) { rc.Timeouts--; } else if (!rc.HasOutage) { Stopwatch stopwatch = Stopwatch.StartNew(); try { rc.Robot.RunRound(); } catch (Exception) { rc.AttackLocation = null; rc.NewMoveLocation = null; rc.HasOutage = true; } stopwatch.Stop(); if (stopwatch.ElapsedMilliseconds > 100 && TimeoutsEnabled) { rc.Timeouts += (int)(stopwatch.ElapsedMilliseconds / 100); } } //radiomessages get processed immediately if (rc.RadioMessageData != null) { RadioMessages.Add(new RadioMessage() { Data = rc.RadioMessageData, Location = rc.Location, RobotId = rc.Id }); rc.RadioMessageData = null; } if (rc.NewMoveLocation != null) { if (!IsOnMap(rc.NewMoveLocation)) { throw new ApplicationException(); } rc.Direction = rc.Location.RouteTo(rc.NewMoveLocation).Direction1; rc.Location = rc.NewMoveLocation; rc.Energy -= rc.RobotType.MoveEnergyCost; rc.NewMoveLocation = null; } rc.TurnCompleted = true; } //correctForLocationOverPopulation(); // Attack & Degen foreach (RobotController rc in RobotControllers) { if (rc.AttackLocation != null) { var opponent = this.GetRobotController(rc.AttackLocation); if (opponent != null) { opponent.Health -= rc.RobotType.Damage; } rc.Direction = rc.Location.RouteTo(rc.AttackLocation).Direction1; rc.Energy -= rc.RobotType.AttackEnergyCost; //rc.AttackLocation = null; } if (this.IsToxic(rc.Location)) { rc.Health -= GameConstants.TOXIC_DAMAGE; } } // Death foreach (RobotController rc in RobotControllers.ToList()) { if (rc.Health <= 0) { rc.Health = 0; rc.AttackLocation = null; RobotControllers.Remove(rc); foreach (RadioMessage rm in RadioMessages.Where(x => x.RobotId == rc.Id).ToList()) { RadioMessages.Remove(rm); } DeadRobots.Add(rc); } } foreach (RobotController rc in RobotControllers) { //Regen if (!this.IsToxic(rc.Location)) { rc.Health += rc.RobotType.HealthRegeneration; if (rc.Health > rc.RobotType.MaxHealth) { rc.Health = rc.RobotType.MaxHealth; } } } DeadRobotRenderInfos = DeadRobots.Select(x => new RobotRenderInfo(x)).ToList(); RobotRenderInfos = RobotControllers.Select(x => new RobotRenderInfo(x)).ToList(); ReplayContainer.ReplayRounds.Add(new HexCode.Engine.Replays.ReplayRound() { Round = Round, RobotRenderInfos = RobotRenderInfos, DeadRobotRenderInfos = DeadRobotRenderInfos, RadioMessages = RadioMessages.ToList(), ToxicLocations = ToxicLocations.ToList(), }); if (!RobotControllers.Any(x => x.Team == Team.Blue) && !IsFinished) { WinnerTeam = Team.Red; IsFinished = true; } else if (!RobotControllers.Any(x => x.Team == Team.Red) && !IsFinished) { WinnerTeam = Team.Blue; IsFinished = true; } if (IsFinished) { ReplayContainer.WinnerTeam = WinnerTeam; ReplayContainer.Rounds = Round; //ReplayController.SaveReplay(ReplayContainer); } }