/// <summary>
 /// Select a target for the spell from a list of candidates and cast the spell on it
 /// </summary>
 /// <param name="potentialTargets">The list of potential targets</param>
 public override void CastOn(List <UnitStack> potentialTargets)
 {
     if (potentialTargets.Count > 0)
     {
         // note: the spell doesn't work on holy units
         UnitStack toTarget = potentialTargets[0];
         int       qty      = toTarget.GetTotalQty();
         int       candidateQty;
         for (int i = 1; i < potentialTargets.Count; i++)
         {
             candidateQty = potentialTargets[i].GetTotalQty();
             if (toTarget.IsAffectedBy(this) ||
                 toTarget.GetUnitType().IsHoly() ||
                 (candidateQty > qty &&
                  !potentialTargets[i].IsAffectedBy(this) &&
                  !potentialTargets[i].GetUnitType().IsHoly()))
             {
                 toTarget = potentialTargets[i];
                 qty      = candidateQty;
             }
         }
         if (!toTarget.IsAffectedBy(this) && !toTarget.GetUnitType().IsHoly())
         {
             toTarget.AffectBySpell(this);
         }
     }
 }
 public void UpdateView()
 {
     _quantityField.text = _model.GetTotalQty().ToString();
     _healthField.text   = _model.GetTotalHealth().ToString();
     _mirrorImageField.gameObject.SetActive(_model.IsAffectedBy("Mirror Image"));
     _confusionField.gameObject.SetActive(_model.IsAffectedBy("Confusion"));
     _magicShieldField.gameObject.SetActive(_model.IsAffectedBy("Magic Shield"));
     _stoneSkinField.gameObject.SetActive(_model.IsAffectedBy("Stone Skin"));
 }
Exemple #3
0
    /// <summary>
    /// Calculate defender's armor value against the attack
    /// </summary>
    /// <param name="attack">Attack under consideration</param>
    /// <param name="defender">Defending unit stack</param>
    /// <param name="isCritical">Whether the attack was a critical success</param>
    /// <returns>Defender's armor value modified by attack's qualities</returns>
    public int CalculateArmorValue(Attack attack, UnitStack defender, bool isCritical)
    {
        // AP (armor piercing), GUNPOWDER and LIGHTNING attacks halve armor rating
        // FIRE attacks ignore armor
        // Critical hits ignore armor
        // STONE SKIN spell adds 2 to the armor value after the above rules were applied
        // ILLUSORY attacks ignore armor and ignore effects of STONE SKIN spell
        int result = defender.GetUnitType().GetArmor();

        if (attack.IsArmorPiercing() || attack.IsGunpowderAttack() || attack.HasQuality(AttackData.Quality.LIGHTNING))
        {
            result /= 2;
        }
        if (isCritical && IsUsingCriticals())
        {
            result = 0;
        }
        if (attack.IsFireAttack())
        {
            result = 0;
        }
        if (defender.IsAffectedBy("Stone Skin"))
        {
            result += 2;
        }
        if (attack.HasQuality(AttackData.Quality.ILLUSORY))
        {
            result = 0;
        }

        return(result);
    }
Exemple #4
0
 /// <summary>
 /// Select a target for the spell from a list of candidates and cast the spell on it
 /// </summary>
 /// <param name="potentialTargets">The list of potential targets</param>
 public override void CastOn(List <UnitStack> potentialTargets)
 {
     if (potentialTargets.Count > 0)
     {
         UnitStack toTarget = potentialTargets[0];
         int       qty      = toTarget.GetTotalQty();
         int       candidateQty;
         for (int i = 1; i < potentialTargets.Count; i++)
         {
             candidateQty = potentialTargets[i].GetTotalQty();
             if (toTarget.IsAffectedBy(this) || (candidateQty > qty && !potentialTargets[i].IsAffectedBy(this)))
             {
                 toTarget = potentialTargets[i];
                 qty      = candidateQty;
             }
         }
         toTarget.AffectBySpell(this);
     }
 }
Exemple #5
0
    /// <summary>
    /// Calculate defender's shield value against the attack
    /// </summary>
    /// <param name="attack">Attack under consideration</param>
    /// <param name="defender">Defending unit stack</param>
    /// <returns>Defender's shield value modified by attack's qualities</returns>
    public int CalculateShieldValue(Attack attack, UnitStack defender)
    {
        // Shields perform at 150% against SKIRMISH attacks
        // They perform at 200% against regular RANGED attacks
        // GUNPOWDER attacks ignore shields
        // MAGIC and LIGHTNING attacks halve the shield value
        // MAGIC SHIELD spell adds 2 to the shield value after the rules above were applied
        // ILLUSORY attacks ignore shields, including those created by MAGIC SHIELD spell
        int shieldRating = defender.GetUnitType().GetShield();
        int result       = shieldRating;

        if (attack.IsSkirmishAttack())
        {
            result += shieldRating / 2;
        }

        if (attack.IsRangedAttack())
        {
            result = 2 * shieldRating;
        }

        if (attack.HasQuality(AttackData.Quality.MAGIC) || attack.HasQuality(AttackData.Quality.LIGHTNING))
        {
            result = shieldRating / 2;
        }
        if (attack.HasQuality(AttackData.Quality.GUNPOWDER))
        {
            result = 0;
        }
        if (defender.IsAffectedBy("Magic Shield"))
        {
            result += 2;
        }
        if (attack.HasQuality(AttackData.Quality.ILLUSORY))
        {
            result = 0;
        }
        return(result);
    }