public int GetAttribute(GameManager.Attributes attr) { if (attr == GameManager.Attributes.Health) { return(this.health); } if (attr == GameManager.Attributes.Stamina) { return(this.stamina); } if (attr == GameManager.Attributes.Spirits) { return(this.spirits); } return(-1); }
public void UpdateAttribute(GameManager.Attributes attr, int inc) { if (attr == GameManager.Attributes.Health) { // Check whether the player has shield charges. // If so, reduce a charge and don't deal damage. LifeUpgrade lifeUpgradeScript = GetComponentInChildren <LifeUpgrade> (); if (lifeUpgradeScript.HasShieldActive() && inc < 0) { lifeUpgradeScript.BreakShield(); return; } int val = this.health + inc; if (inc < 0) { this.animator.SetTrigger("tookDamage"); if (this.health > 0) { PlaySoundHurt(); } } if (val > this.maxHealth) { this.health = this.maxHealth; } else if (val < 0) { this.health = 0; } else { this.health += inc; } } if (attr == GameManager.Attributes.Stamina) { int val = this.stamina + inc; if (val > this.maxStamina) { this.stamina = this.maxStamina; } else if (val < 0) { this.stamina = 0; } else { this.stamina = val; } } if (attr == GameManager.Attributes.Spirits) { int val = this.spirits + inc; if (val > this.maxSpirits) { this.spirits = this.maxSpirits; } else if (val < 0) { this.spirits = 0; } else { this.spirits = val; } } }