Browse Source

updated regen system

lakebane
FatBoy-DOTC 7 days ago
parent
commit
2e1dd27332
  1. 249
      src/engine/objects/PlayerCharacter.java
  2. 3
      src/engine/workthreads/UpdateThread.java

249
src/engine/objects/PlayerCharacter.java

@ -5146,6 +5146,9 @@ public class PlayerCharacter extends AbstractCharacter { @@ -5146,6 +5146,9 @@ public class PlayerCharacter extends AbstractCharacter {
@Override
public void updateRegen() {
if(true)
return;
float healthRegen = 0f;
float manaRegen = 0f;
float stamRegen = 0f;
@ -5686,4 +5689,250 @@ public class PlayerCharacter extends AbstractCharacter { @@ -5686,4 +5689,250 @@ public class PlayerCharacter extends AbstractCharacter {
this.dirtyLoad = dirtyLoad;
dirtyLock.writeLock().unlock();
}
public void RunRegen(){
//this.updateRegen();
Long lastRegen;
if(this.timestamps.containsKey("LastRegen"))
lastRegen = this.timestamps.get("LastRegen");
else
lastRegen = System.currentTimeMillis();
float secondsDifference = (System.currentTimeMillis() - lastRegen) / 1000.0f;
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_RUN) * 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 (!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 || secondsDifference > 2.5f)
this.syncClient();
// Reset this char's frame time.
this.lastUpdateTime = System.currentTimeMillis();
this.lastStamUpdateTime = System.currentTimeMillis();
}
public static float getRegenRate(PlayerCharacter player, ModType type){
float regenRate = 1 + player.getRegenModifier(type);
player.updateMovementState();
switch (player.movementState) {
case IDLE:
if(player.walkMode){
switch(type){
case HealthRecoverRate:
regenRate = MBServerStatics.HEALTH_REGEN_WALK * regenRate;
break;
case ManaRecoverRate:
regenRate = MBServerStatics.MANA_REGEN_WALK * regenRate;
break;
case StaminaRecoverRate:
regenRate = MBServerStatics.STAMINA_REGEN_WALK * regenRate;
break;
}
}else{
}
break;
case RUNNING:
if(player.walkMode){
}else{
}
break;
case SWIMMING:
break;
case SITTING:
break;
case FLYING:
break;
}
return regenRate;
}
}

3
src/engine/workthreads/UpdateThread.java

@ -29,7 +29,8 @@ public class UpdateThread implements Runnable { @@ -29,7 +29,8 @@ public class UpdateThread implements Runnable {
try {
for(PlayerCharacter player : SessionManager.getAllActivePlayerCharacters()){
player.update(true);
//player.update(true);
player.RunRegen();
}
} catch (Exception e) {
Logger.error("UPDATE ERROR");

Loading…
Cancel
Save