Пример #1
0
        public void Attack(Unit other, Terrain[,] map, bool counter = true)
        {
            // If the enemy is not in range or we're dead, we don't attack
            if (!InRange(other) || Life <= 0)
            {
                return;
            }

            // We only attack if there is ammo left of if we have a secondary weapon (which has infinite ammo)
            if (MainWeapon != Weapon.None && Ammo > 0 || SecondaryWeapon != Weapon.None)
            {
                var dmg = UnitCreator.Damage(this, other);
                int basedamage;
                if (MainWeapon != Weapon.None && Ammo > 0 && dmg.Item1 > 0)
                {
                    Ammo--;
                    basedamage = dmg.Item1;
                }
                else
                {
                    basedamage = dmg.Item2;
                }
                if (basedamage > 0)
                {
                    var hit = (int)(basedamage
                                    * (Math.Ceiling((double)Life / 10f) / 10f)
                                    * ((100f + 0f) / (100f + 0f)));
                    other.Life -= hit;
                    if (other.Life <= 0)
                    {
                        other.Die();
                    }
                }
            }

            // Ennemy's counter-attack (if it's not already one)
            if (counter)
            {
                other.Attack(this, map, false);
            }
        }
Пример #2
0
 public int Damage(Unit other, Terrain[,] map)
 {
     if (MainWeapon != Weapon.None && Ammo > 0 || SecondaryWeapon != Weapon.None)
     {
         var dmg = UnitCreator.Damage(this, other);
         int basedamage;
         if (MainWeapon != Weapon.None && Ammo > 0 && dmg.Item1 > 0)
         {
             basedamage = dmg.Item1;
         }
         else
         {
             basedamage = dmg.Item2;
         }
         if (basedamage > 0)
         {
             return((int)(basedamage
                          * (Math.Ceiling((double)Life / 10f) / 10f)
                          * ((100f + 0f) / (100f + 0f))));
         }
     }
     return(0);
 }