From cb5ab26924c1f5a6b9a4d6c349ee8bece85f99a1 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 12 Jan 2025 19:37:24 -0600 Subject: [PATCH] recovery system fully synced to client --- src/engine/objects/PlayerCharacter.java | 42 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index 3b34d43c..dd53d76f 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -5871,10 +5871,12 @@ public class PlayerCharacter extends AbstractCharacter { this.resetRegenUpdateTime(); return; } - regenerateHealth(); - regenerateMana(); - regenerateStamina(); - consumeStamina(); + this.updateMovementState(); + this.regenerateHealth(); + this.regenerateMana(); + this.regenerateStamina(); + this.consumeStamina(); + this.syncClient(); } catch (Exception e) { Logger.error(e); } finally { @@ -5944,17 +5946,26 @@ public class PlayerCharacter extends AbstractCharacter { this.timestamps.put("LastRegenMana",currentTime); } public void regenerateStamina(){ - if(this.isMoving()) + + Long currentTime = System.currentTimeMillis(); + + if(this.isMoving() || this.isFlying() || !this.canBreathe) { + this.timestamps.put("LastRegenStamina",currentTime); return; + } + Long regenTime; - Long currentTime = System.currentTimeMillis(); + regenTime = this.timestamps.getOrDefault("LastRegenStamina", currentTime); float secondsPassed = (currentTime - regenTime) / 1000f; - float rate = RecoveryType.getRecoveryType(this).staminaRate; - rate *= this.getRegenModifier(ModType.StaminaRecoverRate); // Adjust rate with modifiers + float secondsToRecover1 = RecoveryType.getRecoveryType(this).staminaRate; - float staminaRegenerated = secondsPassed / rate; // Stamina regenerates 1 point per `rate` seconds + float ratio = secondsPassed / secondsToRecover1; + //rate *= this.getRegenModifier(ModType.StaminaRecoverRate); // Adjust rate with modifiers + + //float staminaRegenerated = secondsPassed / rate; // Stamina regenerates 1 point per `rate` seconds + float staminaRegenerated = secondsPassed * ratio; // Stamina regenerates 1 point per `rate` seconds boolean workedStamina = false; float old, mod; @@ -5967,7 +5978,7 @@ public class PlayerCharacter extends AbstractCharacter { mod = 0; workedStamina = this.stamina.compareAndSet(old, mod); } - //ChatManager.chatSystemInfo(this, "STAM: " + this.stamina.get() + " / " + this.staminaMax); + ChatManager.chatSystemInfo(this, "STAM: " + this.stamina.get() + " / " + this.staminaMax); this.timestamps.put("LastRegenStamina", currentTime); } public void consumeStamina(){ @@ -5977,7 +5988,8 @@ public class PlayerCharacter extends AbstractCharacter { float secondsPassed = (currentTime - regenTime) / 1000f; float consumption; - if(!this.isMoving() && !this.isFlying()) { + + if(!this.isMoving() && !this.isFlying() && this.canBreathe) { this.timestamps.put("LastConsumeStamina",currentTime); return; } @@ -5986,8 +5998,10 @@ public class PlayerCharacter extends AbstractCharacter { }else{ consumption = 0.65f * secondsPassed; } - if(!this.canBreathe || this.isFlying()) - consumption *= 2; + if(this.canBreathe) + consumption = 1.5f * secondsPassed; + else if(this.isFlying()) + consumption = 2.0f * secondsPassed; boolean workedStamina = false; float old,mod; @@ -5998,7 +6012,7 @@ public class PlayerCharacter extends AbstractCharacter { mod = 0; workedStamina = this.stamina.compareAndSet(old, mod); } - //ChatManager.chatSystemInfo(this, "CONSUMED STAM: " + consumption); + ChatManager.chatSystemInfo(this, "STAM: " + this.stamina.get() + " / " + this.staminaMax); this.timestamps.put("LastConsumeStamina",currentTime); }