Пример #1
0
 /// <summary>
 /// Skeleton function. Calculates the damage dealt by the spell.
 /// </summary>
 public virtual void CalculateDamage(EntityController user, EntityController target, SpellCast cast)
 {
     int[]  result   = { 0 };
     bool[] critical = { true };
     cast.SetDamage(result);
     cast.SetCritical(critical);
 }
Пример #2
0
    /// <summary>
    /// Override for damage calculation that factors accuracy
    /// </summary>
    public override void CalculateDamage(EntityController user, EntityController target, SpellCast cast)
    {
        // Use the maximum number of htis
        int numHits = maxNumberOfHits;

        // If hit count is to be varied, randomize the number of hits here.
        if (varyHitCount)
        {
            if (minNumberOfHits > maxNumberOfHits)
            {
                minNumberOfHits = maxNumberOfHits;
            }

            // We may want to weight this eventually
            numHits = Random.Range(minNumberOfHits, maxNumberOfHits);
        }

        int[]  result = new int[numHits];
        bool[] crits  = new bool[numHits];

        // Run damage calculation for each hit
        for (int i = 0; i < result.Length; i++)
        {
            float critChance = (float)criticalHitChance;

            // Indicate if this hit is critical
            bool critical = canCritical && (Random.value < (1.0f / critChance));
            crits[i] = critical;

            // Get attack and defense modifications
            float atkMod = user.GetAttackModifier();
            float defMod = target.GetDefenseModifier();

            // Negate negative attack and positive defense mods if the hit is critical
            atkMod = critical && atkMod < 1.0f ? 1.0f : atkMod;
            defMod = critical && defMod > 1.0f ? 1.0f : defMod;

            // Calculate damage
            float damage = ((((2 * DAMAGE_CONSTANT) / 5 + 2) * spellPower *
                             (((float)user.GetAttack() * atkMod) / ((float)target.GetDefense() * defMod))) / 50.0f) + 1.0f;

            // Other modifier applied at the end. Includes critical hit and move specific modifiers
            var offenseModifiers = user.GetOffenseModifiers();
            var defenseModifiers = target.GetDefenseModifiers();

            // Modify the damage based on the active offensive and defensive modifiers
            foreach (float f in offenseModifiers)
            {
                damage *= f;
            }

            foreach (float d in defenseModifiers)
            {
                damage *= d;
            }

            damage *= Random.Range(0.85f, 1.0f);
            damage  = critical ? damage * 1.5f : damage;

            result[i] = (int)damage;
        }

        // Set the damage and critical
        cast.SetDamage(result);
        cast.SetCritical(crits);
    }