Example #1
0
    public DamageDetails TakeDamage(Move move, Pokemon attacker)
    {
        //Crtic hit prob
        float critical = 1f;

        if (Random.value * 100f <= criticalHitRate)
        {
            critical = 1.5f;
        }

        //Type efectivenes
        float type = TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type1) * TypeChart.GetEffectiveness(move.Base.Type, this.Base.Type2);

        //STAB
        float stab = attacker.CalculateStab(move);

        float modifiers = Random.Range(0.85f, 1f) * type * critical * stab;

        var damageDetails = new DamageDetails()
        {
            Effectiveness = type,
            Critical      = critical,
            Fainted       = false
        };

        //Determinamos la categoría del movimiento:
        float attack  = (move.Base.Category == MoveCategory.Special) ? attacker.SpAttack : attacker.Attack;
        float defense = (move.Base.Category == MoveCategory.Special) ? attacker.SpDefense : attacker.Defense;

        //Formula real:
        float a      = ((2 * attacker.Level) / 5) + 2;
        float d      = ((a * move.Base.Power * (attack / defense)) / 50f) + 2;
        int   damage = Mathf.FloorToInt(d * modifiers);

        UpdateHP(damage);
        return(damageDetails);
    }