private void RegenHealth(int i, HealthComponent.Component healthComponent, HealthRegenComponent.Component regenComponent, HealthRegenData regenData) { if (healthComponent.Health >= healthComponent.MaxHealth) { return; } regenData.NextRegenTimer -= Time.deltaTime; if (regenData.NextRegenTimer <= 0) { regenData.NextRegenTimer += regenComponent.RegenInterval; // Send command to regen entity. var commandSender = toRegen.ModifyHealthCommandSenders[i]; var modifyHealthRequest = new HealthComponent.ModifyHealth.Request( toRegen.EntityId[i].EntityId, new HealthModifier() { Amount = regenComponent.RegenAmount }); commandSender.RequestsToSend.Add(modifyHealthRequest); } toRegen.RegenData[i] = regenData; }
private HealthModifiedInfo HandleModifyHealthRequest(HealthModifier modifier, ref HealthComponent.Component healthComp) { var newHealth = Mathf.Clamp(healthComp.Health + modifier.Amount, 0, healthComp.MaxHealth); var died = newHealth <= 0; var healthModifiedInfo = new HealthModifiedInfo( modifier: modifier, healthBefore: healthComp.Health, healthAfter: newHealth, died: died); healthComp.Health = newHealth; return(healthModifiedInfo); }