public Combat(Unit attacker, Unit defender, bool useRandomisedCombatEfficiency, List <Unit> antiAirUnits = null) { UseRandomisedCombatEfficiency = useRandomisedCombatEfficiency; Generator = new NormalDistribution(GameConstants.CombatEfficiencyMean, GameConstants.CombatEfficiencyDeviation); Attacker = new UnitCombatState(attacker, this); Defender = new UnitCombatState(defender, this); if (attacker.IsAirUnit()) { AttackType = AttackType.AirAttack; AntiAirUnits = antiAirUnits.Select((Unit x) => new UnitCombatState(x, this)).ToList(); foreach (var unit in AntiAirUnits) { unit.SetDamage(unit.Unit.Type.Stats.AirAttack.Value); } } else if (attacker.IsArtillery()) { AttackType = AttackType.ArtilleryAttack; } else { AttackType = AttackType.GroundAttack; } // Calculate the outcome right away Attack(); }
public void AttackUnit(Unit attacker, Unit defender) { if (!attacker.Deployed) { throw new GameException("Tried to attack with an undeployed unit"); } if (!defender.Deployed) { throw new GameException("Tried to attack an undeployed unit"); } if (!attacker.CanPerformAction) { throw new GameException("This unit cannot perform any more actions this turn"); } Combat outcome; if (attacker.IsAirUnit()) { List <Unit> antiAirUnits = Opponent.GetAntiAirUnits(defender); outcome = new Combat(attacker, defender, true, antiAirUnits); } else { int distance = attacker.Hex.GetDistance(defender.Hex); if (distance > attacker.Stats.Range) { throw new GameException("The target is out of range"); } outcome = new Combat(attacker, defender, true); } attacker.CanPerformAction = false; // Attacking a unit breaks entrenchment attacker.BreakEntrenchment(); attacker.Strength = outcome.AttackerStrength; defender.Strength = outcome.DefenderStrength; if (!attacker.IsAlive()) { OnUnitDeath(attacker); } if (!defender.IsAlive()) { Opponent.OnUnitDeath(defender); } }
public Combat(Unit attacker, Unit defender, bool useRandomisedCombatEfficiency, List<Unit> antiAirUnits = null) { UseRandomisedCombatEfficiency = useRandomisedCombatEfficiency; Generator = new NormalDistribution(GameConstants.CombatEfficiencyMean, GameConstants.CombatEfficiencyDeviation); Attacker = new UnitCombatState(attacker, this); Defender = new UnitCombatState(defender, this); if (attacker.IsAirUnit()) { AttackType = AttackType.AirAttack; AntiAirUnits = antiAirUnits.Select((Unit x) => new UnitCombatState(x, this)).ToList(); foreach (var unit in AntiAirUnits) unit.SetDamage(unit.Unit.Type.Stats.AirAttack.Value); } else if (attacker.IsArtillery()) AttackType = AttackType.ArtilleryAttack; else AttackType = AttackType.GroundAttack; // Calculate the outcome right away Attack(); }
public void AttackUnit(Unit attacker, Unit defender) { if (!attacker.Deployed) throw new GameException("Tried to attack with an undeployed unit"); if (!defender.Deployed) throw new GameException("Tried to attack an undeployed unit"); if (!attacker.CanPerformAction) throw new GameException("This unit cannot perform any more actions this turn"); Combat outcome; if (attacker.IsAirUnit()) { List<Unit> antiAirUnits = Opponent.GetAntiAirUnits(defender); outcome = new Combat(attacker, defender, true, antiAirUnits); } else { int distance = attacker.Hex.GetDistance(defender.Hex); if (distance > attacker.Stats.Range) throw new GameException("The target is out of range"); outcome = new Combat(attacker, defender, true); } attacker.CanPerformAction = false; // Attacking a unit breaks entrenchment attacker.BreakEntrenchment(); attacker.Strength = outcome.AttackerStrength; defender.Strength = outcome.DefenderStrength; if (!attacker.IsAlive()) OnUnitDeath(attacker); if (!defender.IsAlive()) Opponent.OnUnitDeath(defender); }