diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index 5fa96fb9..8d774396 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -5622,16 +5622,189 @@ public class PlayerCharacter extends AbstractCharacter { this.resetRegenUpdateTime(); return; } + float healthRegen = 0f; + float manaRegen = 0f; + float stamRegen = 0f; + boolean updateClient = false; + // Early exit if char is dead or disconnected + if ((this.isAlive() == false) + || (this.isActive() == false) || this.getLoc().x == 0 && this.getLoc().z == 0) + return; + // Calculate Regen amount from last simulation tick + switch (this.movementState) { + case IDLE: + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_IDLE) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * (getRegenModifier(ModType.HealthRecoverRate)); + if (this.isCasting() || this.isItemCasting()) + healthRegen *= .75f; + // Characters regen mana when in only walk mode and idle + if (this.walkMode) + manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_IDLE) * getRegenModifier(ModType.ManaRecoverRate)); + else if (!this.isCasting() && !this.isItemCasting()) + manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_IDLE) * getRegenModifier(ModType.ManaRecoverRate)); + else + manaRegen = 0; + if (!PlayerCharacter.CanBreathe(this)) + stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; + else if ((!this.isCasting() && !this.isItemCasting()) || this.lastMovementState.equals(MovementState.FLYING)) + stamRegen = MBServerStatics.STAMINA_REGEN_IDLE * getRegenModifier(ModType.StaminaRecoverRate); + else + stamRegen = 0; + break; + case SITTING: + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_SIT) + MBServerStatics.HEALTH_REGEN_SIT_STATIC) * getRegenModifier(ModType.HealthRecoverRate); + manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_SIT) * (getRegenModifier(ModType.ManaRecoverRate)); + stamRegen = MBServerStatics.STAMINA_REGEN_SIT * getRegenModifier(ModType.StaminaRecoverRate); + break; + case RUNNING: + if (this.walkMode == true) { + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); + manaRegen = this.manaMax * MBServerStatics.MANA_REGEN_WALK * getRegenModifier(ModType.ManaRecoverRate); + stamRegen = MBServerStatics.STAMINA_REGEN_WALK; + } else { + healthRegen = 0; + manaRegen = 0; + if (this.combat == true) + stamRegen = MBServerStatics.STAMINA_REGEN_RUN_COMBAT; + else + stamRegen = MBServerStatics.STAMINA_REGEN_RUN_NONCOMBAT; + } + break; + case FLYING: + float seventyFive = this.staminaMax * .75f; + float fifty = this.staminaMax * .5f; + float twentyFive = this.staminaMax * .25f; + if (this.getDesiredAltitude() == 0 && this.getAltitude() <= 10) { + if (this.isCombat()) + stamRegen = 0; + else + stamRegen = MBServerStatics.STAMINA_REGEN_IDLE * getRegenModifier(ModType.StaminaRecoverRate); + } else if (!this.useFlyMoveRegen()) { + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_IDLE) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * (getRegenModifier(ModType.HealthRecoverRate)); + if (this.isCasting() || this.isItemCasting()) + healthRegen *= .75f; + // Characters regen mana when in only walk mode and idle + if (this.walkMode) + manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_IDLE + (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); + else if (!this.isCasting() && !this.isItemCasting()) + manaRegen = (this.manaMax * MBServerStatics.MANA_REGEN_IDLE + (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); + else + manaRegen = 0; + if (!this.isItemCasting() && !this.isCasting() || this.getTakeOffTime() != 0) + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_IDLE; + else + stamRegen = -1f; + } else if (this.walkMode == true) { + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); + manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_WALK) + (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_WALK; + } else { + healthRegen = 0; + manaRegen = 0; + if (this.isCombat()) + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN_COMBAT; + else + stamRegen = MBServerStatics.STAMINA_REGEN_FLY_RUN; + } + float oldStamina = this.stamina.get(); + if (FastMath.between(oldStamina, 0, twentyFive) && !this.wasTripped25) { + updateClient = true; + this.wasTripped25 = true; + this.wasTripped50 = false; + this.wasTripped75 = false; + } else if (FastMath.between(oldStamina, twentyFive, fifty) && !this.wasTripped50) { + updateClient = true; + this.wasTripped25 = false; + this.wasTripped50 = true; + this.wasTripped75 = false; + } else if (FastMath.between(oldStamina, fifty, seventyFive) && !this.wasTripped75) { + updateClient = true; + this.wasTripped25 = false; + this.wasTripped50 = false; + this.wasTripped75 = true; + } + break; + case SWIMMING: + if (this.walkMode == true) { + healthRegen = ((this.healthMax * MBServerStatics.HEALTH_REGEN_WALK) + MBServerStatics.HEALTH_REGEN_IDLE_STATIC) * getRegenModifier(ModType.HealthRecoverRate); + manaRegen = ((this.manaMax * MBServerStatics.MANA_REGEN_WALK) + (this.getSpiMod() * .015f)) * (getRegenModifier(ModType.ManaRecoverRate)); + stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; + } else { + healthRegen = 0; + manaRegen = 0; + stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; + if (this.combat == true) + stamRegen += MBServerStatics.STAMINA_REGEN_RUN_COMBAT; + else + stamRegen += MBServerStatics.STAMINA_REGEN_RUN_NONCOMBAT; + } + break; + } + // Are we drowning? + if ((this.getStamina() <= 0) + && (PlayerCharacter.CanBreathe(this) == false)) + healthRegen = (this.healthMax * -.03f); + // Multiple regen values by current deltaTime + // Logger.info("", healthRegen + ""); + healthRegen *= getDeltaTime(); + manaRegen *= getDeltaTime(); + stamRegen *= getStamDeltaTime(); + boolean workedHealth = false; + boolean workedMana = false; + boolean workedStamina = false; + float old, mod; + while (!workedHealth || !workedMana || !workedStamina) { + if (!this.isAlive() || !this.isActive()) + return; + if(this.isCasting){ + manaRegen = 0; + workedMana = true; + } + if (!workedHealth) { + old = this.health.get(); + mod = old + healthRegen; + if (mod > this.healthMax) + mod = healthMax; + else if (mod <= 0) { + if (this.isAlive.compareAndSet(true, false)) + killCharacter("Water"); + return; + } + workedHealth = this.health.compareAndSet(old, mod); + } + if (!workedStamina) { + old = this.stamina.get(); + mod = old + stamRegen; + if (mod > this.staminaMax) + mod = staminaMax; + else if (mod < 0) + mod = 0; + workedStamina = this.stamina.compareAndSet(old, mod); + } + if (!workedMana) { + old = this.mana.get(); + mod = old + manaRegen; + if (mod > this.manaMax) + mod = manaMax; + else if (mod < 0) + mod = 0; + workedMana = this.mana.compareAndSet(old, mod); + } + } + if (updateClient) + this.syncClient(); + // Reset this char's frame time. + this.lastUpdateTime = System.currentTimeMillis(); + this.lastStamUpdateTime = System.currentTimeMillis(); //this.updateMovementState(); - boolean updateHealth = this.regenerateHealth(); - boolean updateMana = this.regenerateMana(); - boolean updateStamina = this.regenerateStamina(); - boolean consumeStamina = this.consumeStamina(); + ///boolean updateHealth = this.regenerateHealth(); + //boolean updateMana = this.regenerateMana(); + //boolean updateStamina = this.regenerateStamina(); + //boolean consumeStamina = this.consumeStamina(); if (this.timestamps.get("SyncClient") + 5000L < System.currentTimeMillis()) { - if (updateHealth || updateMana || updateStamina || consumeStamina) { + //if (updateHealth || updateMana || updateStamina || consumeStamina) { this.syncClient(); this.timestamps.put("SyncClient", System.currentTimeMillis()); - } + //} } } @@ -5642,7 +5815,7 @@ public class PlayerCharacter extends AbstractCharacter { float secondsPassed = (currentTime - regenTime) / 1000f; float onePercent = this.healthMax * 0.01f; float rate = 1.0f / RecoveryType.getRecoveryType(this).healthRate; - //rate *= this.getRegenModifier(ModType.HealthRecoverRate); + rate *= this.getRegenModifier(ModType.HealthRecoverRate); rate *= this.combatStats.healthRegen; if(this.isMoving() && !this.walkMode) @@ -5650,6 +5823,7 @@ public class PlayerCharacter extends AbstractCharacter { float healthRegenerated = onePercent * rate * secondsPassed; //ChatManager.chatSystemInfo(this,"HEALTH REGENERATED: " + healthRegenerated + " SECONDS PASSED: " + secondsPassed); + ChatManager.chatSystemInfo(this,"HEALTH : " + Math.round(this.health.get()) + " / " + this.healthMax); boolean workedHealth = false; float old = this.health.get(); float mod = old + healthRegenerated;