Players now lose power over time while they are offline. New conf.json setting "powerOfflineLossPerDay" (default 1.0) is how much power they lose; note that this power loss actually occurs frequently in very tiny amounts as time passes, not just once per day. New conf.json setting "powerOfflineLossLimit" (default 0.0) which will stop offline power loss once a player's power drops to the specified amount.

As an example, the default 1.0 power loss per day offline is roughly 0.0417 power loss per hour, 0.00695 per minute, and so forth.
This commit is contained in:
Brettflan
2011-09-22 06:33:34 -05:00
parent fa21358a23
commit 28e881d905
2 changed files with 22 additions and 2 deletions

View File

@@ -190,6 +190,7 @@ public class FPlayer {
}
public void setLastLoginTime(long lastLoginTime) {
losePowerFromBeingOffline();
this.lastLoginTime = lastLoginTime;
this.lastPowerUpdateTime = lastLoginTime;
if (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) {
@@ -404,8 +405,11 @@ public class FPlayer {
}
protected void updatePower() {
if (this.isOffline() && !Conf.powerRegenOffline) {
return;
if (this.isOffline()) {
losePowerFromBeingOffline();
if (!Conf.powerRegenOffline) {
return;
}
}
long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime;
@@ -414,6 +418,20 @@ public class FPlayer {
int millisPerMinute = 60*1000;
this.alterPower(millisPassed * Conf.powerPerMinute / millisPerMinute);
}
protected void losePowerFromBeingOffline() {
if (Conf.powerOfflineLossPerDay > 0.0 && this.power > Conf.powerOfflineLossLimit) {
long now = System.currentTimeMillis();
long millisPassed = now - this.lastPowerUpdateTime;
this.lastPowerUpdateTime = now;
double loss = millisPassed * Conf.powerOfflineLossPerDay / (24*60*60*1000);
if (this.power - loss < Conf.powerOfflineLossLimit) {
loss = this.power;
}
this.alterPower(-loss);
}
}
public void onDeath() {
this.updatePower();