Exemple #1
0
    /// <summary>
    /// Modify a stat on this character
    /// </summary>
    /// <param name="name">Name of stat to be modified</param>
    /// <param name="amount">How much it will be modified</param>
    /// <param name="percent">Is 'amount' a percentage?</param>
    /// <param name="permanent">If true, effect maximum. This is used for things like leveling up</param>
    /// <param name="tag">What caused the modification. Examples: spell, melee, enviroment, reaction, self, status</param>
    public void ModifyStat(string name, int amount, bool percent = false, bool permanent = false, string tag = "")
    {
        // To do: add delegates to detect when a certain stat is modified, and by how much. Also, delegate should be able to modify how much it's modified
        // To do: find way to increase max hp in combat, without it being permanent
        _Stat stat = null;

        foreach (_Stat temp in stats)
        {
            if (stat.name.ToLower().Replace(" ", "") == name.ToLower().Replace(" ", ""))
            {
                stat = temp;
            }
        }

        if (stat == null)
        {
            stat = new _Stat(name);
            stats.Add(stat);
        }

        if (percent)
        {
            stat.current = (int)(stat.current * (amount / 100f));
        }
        else
        {
            stat.current += amount;
        }
    }
Exemple #2
0
    public void TakeDamage(int damage)
    {
        damage -= armor.GetValue();
        damage  = Mathf.Clamp(damage, 0, int.MaxValue);
        Debug.Log(gameObject.name + " takes " + damage + " damage!");
        currenHealth -= damage;

        if (OnHealthChanged != null)
        {
            OnHealthChanged(maxHealth, currenHealth);
        }

        if (currenHealth <= 0)
        {
            Die();
        }
    }