Ejemplo n.º 1
0
 public UnitCombatState(Unit unit, Combat combat)
 {
     Unit = unit;
     UnitStrength = unit.Strength;
     BaseDamage = null;
     CombatEfficiency = combat.GetCombatEfficiency();
     TotalDamageDealt = 0.0;
     DamageDivisor = 1;
 }
Ejemplo n.º 2
0
 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);
 }