diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index f2373614..6cfb54bc 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -5147,26 +5147,26 @@ public class PlayerCharacter extends AbstractCharacter { forceRespawn(this); return; } - if(!this.timestamps.containsKey("stamTick")){ - this.timestamps.put("stamTick", System.currentTimeMillis()); - }else{ - if(this.containsEffect(441156479) || this.containsEffect(441156455)) { - if(System.currentTimeMillis() - this.timestamps.get("stamTick") > 5000){ - boolean worked = false; - while(!worked) { - float old = this.stamina.get(); - float mod = old + 4; - if (mod > this.staminaMax) - mod = this.staminaMax; - - worked = this.stamina.compareAndSet(old, mod); - } - this.timestamps.put("stamTick", System.currentTimeMillis()); - } - }else{ - this.timestamps.put("stamTick", System.currentTimeMillis()); - } - } + //if(!this.timestamps.containsKey("stamTick")){ + // this.timestamps.put("stamTick", System.currentTimeMillis()); + //}else{ + // if(this.containsEffect(441156479) || this.containsEffect(441156455)) { + // if(System.currentTimeMillis() - this.timestamps.get("stamTick") > 5000){ + // boolean worked = false; + // while(!worked) { + // float old = this.stamina.get(); + // float mod = old + 4; + // if (mod > this.staminaMax) + // mod = this.staminaMax; +// + // worked = this.stamina.compareAndSet(old, mod); + // } + // this.timestamps.put("stamTick", System.currentTimeMillis()); + // } + // }else{ + // this.timestamps.put("stamTick", System.currentTimeMillis()); + // } + //} if (this.isAlive() && this.isActive && this.enteredWorld) { @@ -5177,7 +5177,8 @@ public class PlayerCharacter extends AbstractCharacter { } else { this.combatStats.update(); } - this.doRegen(); + //this.doRegen(); + this.combatStats.regenerate(); } if (this.getStamina() < 10) { diff --git a/src/engine/objects/PlayerCombatStats.java b/src/engine/objects/PlayerCombatStats.java index 85097df6..da87d188 100644 --- a/src/engine/objects/PlayerCombatStats.java +++ b/src/engine/objects/PlayerCombatStats.java @@ -887,4 +887,142 @@ public class PlayerCombatStats { return HIT_VALUE_MAP.get(key); } + + public void regenerate(){ + healthRegen(this.owner); + manaRegen(this.owner); + staminaRegen(this.owner); + staminaConsume(this.owner); + this.owner.syncClient(); + } + public static void healthRegen(PlayerCharacter pc){ + if(!pc.timestamps.containsKey("LASTHEALTHREGEN")) + pc.timestamps.put("LASTHEALTHREGEN",System.currentTimeMillis()); + + float stateMultiplier = 1.0f; + if(pc.isSit()) + stateMultiplier = 2.0f; + + long deltaTime = System.currentTimeMillis() - pc.timestamps.get("LASTHEALTHREGEN"); + float current = pc.health.get(); + float onePercent = pc.healthMax * 0.01f; + float mod = current + ((deltaTime * 0.001f) * onePercent * stateMultiplier); + if(pc.bonuses != null) + mod *= 1 + pc.bonuses.getFloatPercentAll(Enum.ModType.HealthRecoverRate, Enum.SourceType.None); + + boolean worked = false; + if(mod > pc.healthMax) + mod = pc.healthMax; + + while (!worked) { + worked = pc.health.compareAndSet(current, mod); + } + + pc.timestamps.put("LASTHEALTHREGEN",System.currentTimeMillis()); + } + + public static void manaRegen(PlayerCharacter pc){ + if(!pc.timestamps.containsKey("LASTMANAREGEN")) + pc.timestamps.put("LASTMANAREGEN",System.currentTimeMillis()); + + float stateMultiplier = 1.0f; + if(pc.isSit()) + stateMultiplier = 2.0f; + + long deltaTime = System.currentTimeMillis() - pc.timestamps.get("LASTMANAREGEN"); + float current = pc.mana.get(); + float onePercent = pc.manaMax * 0.01f; + float mod = current + ((deltaTime * 0.001f) * onePercent * stateMultiplier); + if(pc.bonuses != null) + mod *= 1 + pc.bonuses.getFloatPercentAll(Enum.ModType.ManaRecoverRate, Enum.SourceType.None); + + boolean worked = false; + if(mod > pc.manaMax) + mod = pc.manaMax; + + while (!worked) { + worked = pc.mana.compareAndSet(current, mod); + } + + pc.timestamps.put("LASTMANAREGEN",System.currentTimeMillis()); + } + + public static void staminaRegen(PlayerCharacter pc){ + //cannot regen is moving, swimming or flying + if(pc.isFlying() && pc.isSwimming() && pc.isMoving()) { + pc.timestamps.put("LASTSTAMINAREGEN",System.currentTimeMillis()); + return; + } + + if(!pc.timestamps.containsKey("LASTSTAMINAREGEN")) + pc.timestamps.put("LASTSTAMINAREGEN",System.currentTimeMillis()); + + float stateMultiplier = 1.0f; + if(pc.isSit()) + stateMultiplier = 2.0f; + + long deltaTime = System.currentTimeMillis() - pc.timestamps.get("LASTSTAMINAREGEN"); + float current = pc.stamina.get(); + float mod = current + ((deltaTime * 0.001f) * stateMultiplier); + if(pc.bonuses != null) + mod *= 1 + pc.bonuses.getFloatPercentAll(Enum.ModType.StaminaRecoverRate, Enum.SourceType.None); + + boolean worked = false; + if(mod > pc.staminaMax) + mod = pc.staminaMax; + + while (!worked) { + worked = pc.stamina.compareAndSet(current, mod); + } + + pc.timestamps.put("LASTSTAMINACONSUME",System.currentTimeMillis()); + } + + public static void staminaConsume(PlayerCharacter pc){ + //no natural consumption if not moving, swimming or flying + if(!pc.isFlying() && !pc.isSwimming() && !pc.isMoving()) { + pc.timestamps.put("LASTSTAMINACONSUME",System.currentTimeMillis()); + return; + } + //no stamina consumption for TravelStance + if(pc.containsEffect(441156479) || pc.containsEffect(441156455)) { + pc.timestamps.put("LASTSTAMINACONSUME",System.currentTimeMillis()); + return; + } + float stateMultiplier = 1.0f; + if(pc.isSwimming() || pc.isFlying()) + stateMultiplier = 1.5f; + + if(!pc.timestamps.containsKey("LASTSTAMINACONSUME")) + pc.timestamps.put("LASTSTAMINACONSUME",System.currentTimeMillis()); + + long deltaTime = System.currentTimeMillis() - pc.timestamps.get("LASTSTAMINACONSUME"); + float current = pc.stamina.get(); + float mod = current - ((deltaTime *0.001f) * 0.6f * stateMultiplier); + boolean worked = false; + if(mod <= 0) + mod = 0; + if(mod == 0){ + healthConsume(pc, (int) (deltaTime * 0.6f * 2.5f)); + }else { + while (!worked) { + worked = pc.stamina.compareAndSet(current,mod); + } + } + pc.timestamps.put("LASTSTAMINACONSUME",System.currentTimeMillis()); + } + + public static void healthConsume(PlayerCharacter pc, int amount){ + boolean worked = false; + float current = pc.health.get(); + float mod = current = amount; + if(mod <= 0){ + pc.killCharacter("water"); + return; + } + while(!worked){ + worked = pc.health.compareAndSet(current,mod); + } + } + }