コード例 #1
0
    // Applies incoming damage
    public override int TakeDamage(Vector2Int locationOfAttack, int damage)
    {
        int oldHealth = Health;

        if (damage >= 0) // Damage
        {
            // Do we have defense?
            if (statusEffects.TryGetValue(BattleManager.StatusEffectEnum.defense, out StatusEffectDataHolder val))
            {
                int oldDamage = damage;
                damage -= val.EffectValue;
                ApplyStatusEffect(BattleManager.StatusEffectEnum.defense, -1 * oldDamage); // Deal damage to defense
            }

            if (damage > 0)
            {
                AudioManager.PlayPlayerHit();
                Splatter.Play(locationOfAttack);
                StartCoroutine(HitColoration());
                Health -= damage;
            }
        }
        else // healing
        {
            Health -= damage;
            if (Health > maxHealth)
            {
                Health = maxHealth;
            }
        }

        if (Health <= 0)
        {
            SaveGameSystem.instance?.DeleteGame();
            GameOverScreen.PlayerDeath();
        }

        return(oldHealth - Health);
    }