示例#1
0
        // Calculates how damage will be dealt to this entity
        // Returns the amount of damage done
        public int DealDamage(BattleStats attacker, AttackData currentAttack)
        {
            int attackPower  = 0;
            int defensePower = 0;

            // If the attacker is the player, we are attacking an enemy
            if (attacker.battleData is CharacterData)
            {
                if (currentAttack.attackType == AttackType.PHYSICAL)
                {
                    // Because the attack is physical, we calculate the math based on physical power
                    attackPower  = attacker.ReturnModdedStat("BaseAttack") + currentAttack.attackPower + attacker.ReturnModdedStat("PhysicalAttack");
                    defensePower = ReturnModdedStat("PhysicalDefense");
                }
                else if (currentAttack.attackType == AttackType.SPECIAL)
                {
                    // Because the attack is special, we calculate the math based on special power
                    attackPower  = attacker.ReturnModdedStat("BaseAttack") + currentAttack.attackPower + attacker.ReturnModdedStat("SpecialAttack");
                    defensePower = ReturnModdedStat("SpecialDefense");

                    // We also deduct SP from the user as well
                    attacker.CurrentSP -= currentAttack.attackCost;
                }
            }
            // If the attacker is an enemy, we are attacking a party member
            else if (attacker.battleData is EnemyData)
            {
                if (currentAttack.attackType == AttackType.PHYSICAL)
                {
                    // Because the attack is physical, we calculate the math based on physical power
                    attackPower  = currentAttack.attackPower + attacker.ReturnModdedStat("PhysicalAttack");
                    defensePower = ReturnModdedStat("BaseDefense") + ReturnModdedStat("PhysicalDefense");
                }
                else if (currentAttack.attackType == AttackType.SPECIAL)
                {
                    // Because the attack is special, we calculate the math based on special power
                    attackPower  = currentAttack.attackPower + attacker.ReturnModdedStat("SpecialAttack");
                    defensePower = ReturnModdedStat("BaseDefense") + ReturnModdedStat("SpecialDefense");

                    // We also deduct SP from the user as well
                    attacker.CurrentSP -= currentAttack.attackCost;
                }
            }

            // Modifies the total attack power depending on the affinity of the attack
            switch (GetAttackEffectiveness(currentAttack))
            {
            case AffinityValues.RESISTANT:
                attackPower /= 2;
                break;

            case AffinityValues.WEAK:
                attackPower *= 2;
                break;

            case AffinityValues.NULL:
                attackPower *= 0;
                break;
            }

            // We then calculate the final damage, clamping the damage to 0 and infinity (cannot be negative)
            int finalDamage = (int)Mathf.Clamp(attackPower - defensePower, 0, Mathf.Infinity);

            currentHP -= finalDamage;

            // We then return the total damage output
            return(finalDamage);
        }