Esempio n. 1
0
    /// <summary>
    /// Sets the damage of this SpellCast.
    /// For each hit of damage, roll for effect success.
    /// </summary>
    public virtual void SetDamage(int[] d)
    {
        damage = d;

        for (int i = 0; i < damage.Length; i++)
        {
            totalDamage += damage[i];

            for (int n = 0; n < spell.spellEffects.Count; n++)
            {
                Effect e = spell.spellEffects[i].GetEffect();

                if (e != null && !effects.Exists(f => f.effect == e) || (effects.Exists(f => f.effect == e) && e.IsStackable()))
                {
                    EffectInstance eff = e.CreateEventInstance(user, target, this);
                    eff.CheckSuccess();
                    effects.Add(eff);
                }
            }
        }
    }
Esempio n. 2
0
    public List <Effect> spellProperties;         // Used to modify the damage roll


    /// <summary>
    /// Returns an instance of this spell using the spell data to calculate damage and effects
    /// </summary>
    public SpellCast Cast(EntityController user, EntityController target)
    {
        // Result of the cast spell
        SpellCast result = new SpellCast();

        result.spell  = this;
        result.user   = user;
        result.target = target;

        // Check for MP. If MP is inadequate, don't proceed.
        result.success = CheckMP(user);

        if (result.success)
        {
            // Check for additional requirements. If they aren't met, don't proceed.
            result.success = CheckCanCast(user, target);

            if (result.success)
            {
                // Apply properties before dealing damage, as properties may affect damage or accuracy.
                List <EffectInstance> properties = new List <EffectInstance>();

                // Activate all properties on this spell
                foreach (Effect e in spellProperties)
                {
                    if (e != null && !properties.Exists(f => f.effect == e) || (properties.Exists(f => f.effect == e) && e.IsStackable()))
                    {
                        EffectInstance eff = e.CreateEventInstance(user, target, result);
                        eff.CheckSuccess();
                        eff.OnActivate();
                        properties.Add(eff);
                    }
                }

                // Get the user's active propeties. This will differ from the above list.
                List <EffectInstance> userProperties = user.GetProperties();

                foreach (EffectInstance ef in userProperties)
                {
                    ef.CheckSuccess();
                    ef.OnActivate();
                    properties.Add(ef);
                }

                // Check for spell hit. If spell misses, don't proceed.
                result.success = CheckSpellHit(user, target);

                if (result.success)
                {
                    // Calculate damage
                    CalculateDamage(user, target, result);

                    // If damage is 0, check to see if any effects were applied.
                    if (result.GetDamage() == 0)
                    {
                        result.success = result.GetEffectProcSuccess();
                    }
                }

                // Deactivate all properties
                foreach (EffectInstance e in properties)
                {
                    e.OnDeactivate();
                }

                // Clear properties from player
                user.ClearProperties();
            }
        }

        // Return spell cast.
        return(result);
    }