/// <summary> /// Tests if a refill is needed and processes it /// </summary> protected virtual void ProcessRefillHealth() { if (!RefillHealth) { return; } if (Time.time - _lastHitTime < CooldownAfterHit) { return; } if (_health.CurrentHealth < _health.MaximumHealth) { switch (RefillMode) { case RefillModes.Bursts: if (Time.time - _lastBurstTimestamp > DurationBetweenBursts) { _health.GetHealth(HealthPerBurst, this.gameObject); _lastBurstTimestamp = Time.time; } break; case RefillModes.Linear: _healthToGive += HealthPerSecond * Time.deltaTime; if (_healthToGive > 1f) { int givenHealth = (int)_healthToGive; _healthToGive -= givenHealth; _health.GetHealth(givenHealth, this.gameObject); } break; } } }
/// <summary> /// Triggered when something collides with the stimpack /// </summary> /// <param name="collider">Other.</param> protected override void Pick(GameObject picker) { Character character = picker.gameObject.MMGetComponentNoAlloc <Character>(); if (OnlyForPlayerCharacter && (character != null) && (_character.CharacterType != Character.CharacterTypes.Player)) { return; } Health characterHealth = picker.gameObject.MMGetComponentNoAlloc <Health>(); // else, we give health to the player if (characterHealth != null) { characterHealth.GetHealth(HealthToGive, gameObject); } }
/// <summary> /// When the item is used, we try to grab our character's Health component, and if it exists, we add our health bonus amount of health /// </summary> public override bool Use() { base.Use(); if (TargetInventory.Owner == null) { return(false); } Health characterHealth = TargetInventory.Owner.GetComponent <Health>(); if (characterHealth != null) { characterHealth.GetHealth(HealthBonus, TargetInventory.gameObject); return(true); } else { return(false); } }