using Cielonos.MainGame.UI; using SLSUtilities.General; using UnityEngine; namespace Cielonos.MainGame.Characters { public partial class Player { private float deltaTime => selfTimeSm.DeltaTime; } public partial class Player { private void Regeneration() { float healthRegenRate = attributeSm["HealthRegeneration"] * deltaTime; if (healthRegenRate != 0) { attributeSm["Health"] += healthRegenRate; attributeSm["Health"] = Mathf.Min(attributeSm["Health"], attributeSm["MaximumHealth"]); PlayerCanvas.PlayerInfoUIArea.UpdateHealth(true); } float energyRegenRate = attributeSm["EnergyRegeneration"] * deltaTime; if (energyRegenRate != 0) { AddEnergy(energyRegenRate); } } public void AddEnergy(float amount) { if (amount == 0) return; if (amount > 0) { float current = attributeSm["Energy"]; float max = attributeSm["MaximumEnergy"]; float availableSpace = max - current; if (amount > availableSpace) { attributeSm["Energy"] = max; float conversionRate = attributeSm.Has("OverloadConversionRate") ? attributeSm["OverloadConversionRate"] : 1f; float overflowEnergy = (amount - availableSpace) * conversionRate; DistributeOverloadEnergy(overflowEnergy); } else { attributeSm["Energy"] += amount; } } else { attributeSm["Energy"] += amount; attributeSm["Energy"] = Mathf.Max(0, attributeSm["Energy"]); } PlayerCanvas.PlayerInfoUIArea.UpdateEnergy(true); eventSm.onEnergyChanged.Invoke(amount); } private void DistributeOverloadEnergy(float totalOverflowAmount) { if (totalOverflowAmount <= 0) return; var overloadSubmodules = new System.Collections.Generic.List(); if (inventorySc.equipmentSm.currentMainWeapon?.overloadSm != null) { overloadSubmodules.Add(inventorySc.equipmentSm.currentMainWeapon.overloadSm); } foreach (var equip in inventorySc.equipmentSm.currentSupportEquipments) { if (equip?.overloadSm != null) { overloadSubmodules.Add(equip.overloadSm); } } foreach (var equip in inventorySc.backpackSm.passiveEquipments) { if (equip?.overloadSm != null) { overloadSubmodules.Add(equip.overloadSm); } } if (overloadSubmodules.Count == 0) return; float totalWeight = 0; foreach (var sm in overloadSubmodules) { totalWeight += sm.currentWeight; } if (totalWeight <= 0) return; foreach (var sm in overloadSubmodules) { float assignedAmount = totalOverflowAmount * (sm.currentWeight / totalWeight); sm.ReceiveEnergy(assignedAmount); } } } }