Esempio n. 1
0
    public void Attack(GameObject victim)
    {
        attackerStats = owner.GetComponent <FighterStats>();
        targetStats   = victim.GetComponent <FighterStats>();

        if (magicAttack && attackerStats.magic < magicCost)
        {
            Invoke("SkipTurnContinueGame", 2);
        }
        else
        {
            float multiplier = Random.Range(minAttackMultiplier, maxAttackMultiplier);

            if (attackerStats.magic >= magicCost && magicAttack)
            {
                if (magicCost > 0)
                {
                    attackerStats.updateMagicFill(magicCost);
                }
                damage = multiplier * attackerStats.magicRange;
            }
            else
            {
                damage = multiplier * attackerStats.melee;
            }

            float defenseMultiplier = Random.Range(minDefenseMultiplier, maxDefenseMultiplier);
            damage = Mathf.Max(0, damage - (defenseMultiplier * targetStats.defense));
            owner.GetComponent <Animator>().Play(animationName);
            targetStats.ReceiveDamage(Mathf.CeilToInt(damage));
        }
    }