public void ApplyDamage(float amount) { Vital shield = GetVital(VitalType.ShieldPoints); Vital hull = GetVital(VitalType.HullPoints); if (hull.current <= 0f) { return; } if (shield.current >= amount) { shield.Update(-amount); } else if (shield.current > 0) { amount -= shield.current; shield.Update(-shield.current); hull.Update(-amount); } else { hull.Update(-amount); } OnVitalChanged?.Invoke(VitalType.ShieldPoints, shield.inPercent); OnVitalChanged?.Invoke(VitalType.HullPoints, hull.inPercent); }
void OnVitalChange(VitalType v, float current) { OnVitalChanged?.Invoke(v, current); //hook in audio here if (v == VitalType.HullPoints && current <= 0f) { OnShipDestroyed(); } }
public void Update(int amount) { this.current += amount; if (this.current < 0) { this.current = 0; } else if (this.current > _getMax()) { this.current = _getMax(); } OnVitalChanged?.Invoke(type, amount); }
public void SetCurrent(int current) { //cache old int change = current - this.current; this.current = current; if (this.current < 0) { this.current = 0; } else if (this.current > _getMax()) { this.current = _getMax(); } OnVitalChanged?.Invoke(type, change); }