Exemplo n.º 1
0
        /*
         * ROUND((A + B) / (100 + (A + B)) * (C + if(E, C,0) / 2) * C / (C + G) * D * 100 * H * F / (20 * 255))
         * A = Character Level
         * B = Cloak Level
         * C = ATK of attacker
         * D = Ability Damage Modifier
         * E = True/False, determines if the ability Crit
         * F = Random Number from 217 to 255
         * G = DEF of defender
         * H = Elemental damage modifier (Weaknesses/Strengths)
         */
        public static int CalculateDamage(Character attacker, Character defender, float damageModifier, Elements.Type elementType)
        {
            if (IsSuccessful(attacker.GetAccuracy().Value - defender.GetAvoidability().Value))
            {
                // (A + B) / (100 + (A + B))
                float levelFactor = (attacker.GetCloakLevel().Value + attacker.GetLevel().Value) / (100.0f + (attacker.GetCloakLevel().Value + attacker.GetLevel().Value));

                // (C + if(E, C,0) / 2)
                float critFactor = IsSuccessful(attacker.GetCrit().Value) ? attacker.GetAttack().Value + attacker.GetAttack().Value / 2.0f : attacker.GetAttack().Value;

                // C / (C + G) * D
                float             attackFactor = (float)(attacker.GetAttack().Value) / (attacker.GetAttack().Value + defender.GetDefense().Value) * damageModifier;
                Elements.Affinity defElmStatus = defender.CheckElement(elementType);

                // H
                float elementFactor = 1.0f;
                switch (defElmStatus)
                {
                case (Elements.Affinity.Immune):
                    // Take zero damage
                    elementFactor = 0.0f;
                    break;

                case (Elements.Affinity.Strong):
                    // Take half damage
                    elementFactor = _strengthMultiplier;
                    break;

                case (Elements.Affinity.Weak):
                    // Take extra damage
                    elementFactor = _weaknessMultiplier;
                    break;

                default:
                    break;
                }

                // F
                float randomFactor = Random.Range(217, 255);

                return((int)(levelFactor * critFactor * attackFactor * elementFactor * randomFactor * _magicFactor));
            }

            // The attack missed
            return(-1);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks how the element affects the character.
        /// </summary>
        /// <param name="element"></param>
        /// <returns>The affinity against that element</returns>
        public Elements.Affinity CheckElement(Elements.Type element)
        {
            Elements.Affinity elementStatus = Elements.Affinity.Neutral;

            // Strengths will overrule weaknesses. Immunities overrule both
            if (_immunities.Contains(element))
            {
                elementStatus = Elements.Affinity.Immune;
            }
            else if (_strengths.Contains(element))
            {
                elementStatus = Elements.Affinity.Strong;
            }
            else if (_weaknesses.Contains(element))
            {
                elementStatus = Elements.Affinity.Weak;
            }

            return(elementStatus);
        }