Ejemplo n.º 1
0
    /// <summary>
    /// Create a new unit stack with one of the chaos spawn version
    /// </summary>
    /// <param name="summoners">List of unit stacks capable of summoning chaos spawns</param>
    /// <returns>Unit stack created by the spell</returns>
    public override UnitStack Create(List <UnitStack> summoners)
    {
        if (_totalWeight == 0)
        {
            return(null);
        }
        int      randomNumber = Dice.RollDie(_totalWeight) - 1;
        UnitType unitType     = null;

        for (int i = 0; i < _convertedOutcomes.Count; i++)
        {
            if (randomNumber <= _convertedOutcomes[i].Value)
            {
                unitType = _convertedOutcomes[i].Key;
                break;
            }
            else
            {
                randomNumber -= _convertedOutcomes[i].Value;
            }
        }
        if (unitType != null)
        {
            UnitStack stack = new UnitStack(new Unit(unitType, 1), null);
            stack.AffectBySpell(this);

            FileLogger.Trace("SPAWN", unitType.GetName() + " is spawned.");

            return(stack);
        }
        return(null);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Select a unit stack from a list of existing ones and make an illusory clone of it
    /// </summary>
    /// <param name="existing">The list of existing unit stacks</param>
    public override UnitStack Create(List <UnitStack> existing)
    {
        if (existing.Count > 0)
        {
            UnitStack toClone = existing[0];
            int       qty     = toClone.GetTotalQty();
            int       candidateQty;
            for (int i = 1; i < existing.Count; i++)
            {
                candidateQty = existing[i].GetTotalQty();
                if (candidateQty > qty)
                {
                    toClone = existing[i];
                    qty     = candidateQty;
                }
            }

            UnitType illusion = new UnitType(toClone.GetUnitType());
            illusion.SetShield(0);
            illusion.SetArmor(0);
            illusion.SetHitPoints(1);
            illusion.AddAttackQuality(AttackData.Quality.ILLUSORY);

            Unit      mirrorImage = new Unit(illusion, toClone.GetTotalQty());
            UnitStack stack       = new UnitStack(mirrorImage, toClone.GetProvinceToRetreat());
            stack.AffectBySpell(this);

            return(stack);
        }
        return(null);
    }
Ejemplo n.º 3
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)
     {
         // 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);
         }
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Choose a unit stack from the list of potential targets 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       wounds   = toTarget.GetWoundPoints();
         int       candidateWounds;
         for (int i = 1; i < potentialTargets.Count; i++)
         {
             candidateWounds = potentialTargets[i].GetWoundPoints();
             if (candidateWounds > wounds)
             {
                 toTarget = potentialTargets[i];
                 wounds   = candidateWounds;
             }
         }
         if (wounds > 0)
         {
             toTarget.Heal();
             toTarget.AffectBySpell(this);
         }
     }
 }