From 28e881d905c55bdd6596c17bb14fb2c884d98b71 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 22 Sep 2011 06:33:34 -0500 Subject: [PATCH] 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. --- src/com/massivecraft/factions/Conf.java | 2 ++ src/com/massivecraft/factions/FPlayer.java | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 49257bab..e1d78b70 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -28,6 +28,8 @@ public class Conf { public static double powerPerMinute = 0.2; // Default health rate... it takes 5 min to heal one power public static double powerPerDeath = 4.0; // A death makes you lose 4 power public static boolean powerRegenOffline = false; // does player power regenerate even while they're offline? + public static double powerOfflineLossPerDay = 1.0; // players will lose this much power per day offline + public static double powerOfflineLossLimit = 0.0; // players will no longer lose power from being offline once their power drops to this amount or less public static double powerFactionMax = 0.0; // if greater than 0, the cap on how much power a faction can have (additional power from players beyond that will act as a "buffer" of sorts) public static String prefixAdmin = "**"; diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index a51f0e6c..17336fdf 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -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();