From e30c652759c758a4ca7f00d44cdb0c9e4a39b41e Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 22 Apr 2013 17:20:34 +0200 Subject: [PATCH] Moving the power configuration from MConf to UConf. --- src/com/massivecraft/factions/ConfServer.java | 24 --------- .../massivecraft/factions/entity/FPlayer.java | 52 ++++++++++++------- .../massivecraft/factions/entity/Faction.java | 12 +++-- .../massivecraft/factions/entity/UConf.java | 24 +++++++++ .../listeners/FactionsListenerMain.java | 3 +- 5 files changed, 66 insertions(+), 49 deletions(-) diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index 1ac9b42f..ef633b4f 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -30,30 +30,6 @@ public class ConfServer extends SimpleConfig public static double autoLeaveRoutineRunsEveryXMinutes = 5.0; public static boolean removePlayerDataWhenBanned = true; - // -------------------------------------------- // - // POWER - // -------------------------------------------- // - - public static double powerMax = 10.0; - public static double powerMin = -10.0; - public static double powerStarting = 10.0; // New players start out with this power level - - public static double powerPerDeath = -4.0; // A death makes you lose 4 power - - public static double powerPerHourOnline = 10.0; - public static double powerPerHourOffline = 0.0; - - // players will no longer lose power from being offline once their power drops to this amount or less - public static double powerLimitGainOnline = 10.0; - public static double powerLimitGainOffline = 0.0; - public static double powerLimitLossOnline = -10.0; - public static double powerLimitLossOffline = 0.0; - - public static boolean scaleNegativePower = false; // Power regeneration rate increase as power decreases - public static double scaleNegativeDivisor = 40.0; // Divisor for inverse power regeneration curve - - 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) - // -------------------------------------------- // // HOMES // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/FPlayer.java b/src/com/massivecraft/factions/entity/FPlayer.java index 9f3fcf00..bbc8691f 100644 --- a/src/com/massivecraft/factions/entity/FPlayer.java +++ b/src/com/massivecraft/factions/entity/FPlayer.java @@ -29,6 +29,7 @@ import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.money.Money; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.store.SenderEntity; +import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.TimeUnit; import com.massivecraft.mcore.util.Txt; @@ -70,7 +71,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // Note: we do not check role or title here since they mean nothing without a faction. // TODO: This line looks obnoxious, investigate it. - if (this.getPowerRounded() != this.getPowerMaxRounded() && this.getPowerRounded() != (int) Math.round(ConfServer.powerStarting)) return false; + if (this.getPowerRounded() != this.getPowerMaxRounded() && this.getPowerRounded() != (int) Math.round(UConf.get(this).powerStarting)) return false; if (this.hasPowerBoost()) return false; @@ -354,7 +355,9 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public double getPower() { this.recalculatePower(); - return this.power; + Double ret = this.power; + if (ret == null) ret = UConf.get(this).powerStarting; + return ret; } public void setPower(double power) @@ -368,7 +371,7 @@ public class FPlayer extends SenderEntity implements EconomyParticipato power = Math.max(power, this.getPowerMin()); // Nochange - if (this.power == power) return; + if (MUtil.equals(this.power, Double.valueOf(power))) return; this.power = power; this.setLastPowerUpdateTime(now); @@ -377,12 +380,12 @@ public class FPlayer extends SenderEntity implements EconomyParticipato public double getPowerMax() { - return ConfServer.powerMax + this.getPowerBoost(); + return UConf.get(this).powerMax + this.getPowerBoost(); } public double getPowerMin() { - return ConfServer.powerMin + this.getPowerBoost(); + return UConf.get(this).powerMin + this.getPowerBoost(); } public void recalculatePower() @@ -411,30 +414,39 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // Note that we updated this.setLastPowerUpdateTime(now); - // We consider dead players to be offline. + // We consider dead players and players in other universes offline. if (online) { Player thisPlayer = this.getPlayer(); - if (thisPlayer != null && thisPlayer.isDead()) - { - online = false; - } + online = (thisPlayer != null && !thisPlayer.isDead() && FPlayer.get(thisPlayer) == this); + } + + // Cache and prepare + UConf uconf = UConf.get(this); + double powerCurrent; + if (this.power != null) + { + powerCurrent = this.power; + } + else + { + powerCurrent = uconf.powerStarting; } // Depending on online state pick the config values - double powerPerHour = online ? ConfServer.powerPerHourOnline : ConfServer.powerPerHourOffline; - double powerLimitGain = online ? ConfServer.powerLimitGainOnline : ConfServer.powerLimitGainOffline; - double powerLimitLoss = online ? ConfServer.powerLimitLossOnline : ConfServer.powerLimitLossOffline; + double powerPerHour = online ? uconf.powerPerHourOnline : uconf.powerPerHourOffline; + double powerLimitGain = online ? uconf.powerLimitGainOnline : uconf.powerLimitGainOffline; + double powerLimitLoss = online ? uconf.powerLimitLossOnline : uconf.powerLimitLossOffline; // Apply the negative divisor thingy - if (ConfServer.scaleNegativePower && this.power < 0) + if (uconf.scaleNegativePower && powerCurrent < 0) { - powerPerHour += (Math.sqrt(Math.abs(this.power)) * Math.abs(this.power)) / ConfServer.scaleNegativeDivisor; + powerPerHour += (Math.sqrt(Math.abs(powerCurrent)) * Math.abs(powerCurrent)) / uconf.scaleNegativeDivisor; } // Calculate delta and target double powerDelta = powerPerHour * millisPassed / TimeUnit.MILLIS_PER_HOUR; - double powerTarget = this.power + powerDelta; + double powerTarget = powerCurrent + powerDelta; // Check Gain and Loss limits if (powerDelta >= 0) @@ -442,10 +454,10 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // Gain if (powerTarget > powerLimitGain) { - if (this.power > powerLimitGain) + if (powerCurrent > powerLimitGain) { // Did already cross --> Just freeze - powerTarget = this.power; + powerTarget = powerCurrent; } else { @@ -459,10 +471,10 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // Loss if (powerTarget < powerLimitLoss) { - if (this.power < powerLimitLoss) + if (powerCurrent < powerLimitLoss) { // Did already cross --> Just freeze - powerTarget = this.power; + powerTarget = powerCurrent; } else { diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 99f25574..21949d95 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -677,10 +677,12 @@ public class Faction extends Entity implements EconomyParticipator { ret += fplayer.getPower(); } - if (ConfServer.powerFactionMax > 0 && ret > ConfServer.powerFactionMax) + + if (UConf.get(this).powerFactionMax > 0 && ret > UConf.get(this).powerFactionMax) { - ret = ConfServer.powerFactionMax; + ret = UConf.get(this).powerFactionMax; } + return ret + this.getPowerBoost(); } @@ -696,10 +698,12 @@ public class Faction extends Entity implements EconomyParticipator { ret += fplayer.getPowerMax(); } - if (ConfServer.powerFactionMax > 0 && ret > ConfServer.powerFactionMax) + + if (UConf.get(this).powerFactionMax > 0 && ret > UConf.get(this).powerFactionMax) { - ret = ConfServer.powerFactionMax; + ret = UConf.get(this).powerFactionMax; } + return ret + this.getPowerBoost(); } diff --git a/src/com/massivecraft/factions/entity/UConf.java b/src/com/massivecraft/factions/entity/UConf.java index 47c19e99..c0ebcc27 100644 --- a/src/com/massivecraft/factions/entity/UConf.java +++ b/src/com/massivecraft/factions/entity/UConf.java @@ -40,4 +40,28 @@ public class UConf extends Entity public int factionMemberLimit = 0; + // -------------------------------------------- // + // POWER + // -------------------------------------------- // + + public double powerMax = 10.0; + public double powerMin = -10.0; + public double powerStarting = 10.0; // New players start out with this power level + + public double powerPerDeath = -4.0; // A death makes you lose 4 power + + public double powerPerHourOnline = 10.0; + public double powerPerHourOffline = 0.0; + + // players will no longer lose power from being offline once their power drops to this amount or less + public double powerLimitGainOnline = 10.0; + public double powerLimitGainOffline = 0.0; + public double powerLimitLossOnline = -10.0; + public double powerLimitLossOffline = 0.0; + + public boolean scaleNegativePower = false; // Power regeneration rate increase as power decreases + public double scaleNegativeDivisor = 40.0; // Divisor for inverse power regeneration curve + + public 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) + } diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index adab408e..4724cc89 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -53,6 +53,7 @@ import com.massivecraft.factions.entity.BoardColls; import com.massivecraft.factions.entity.FPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.UConf; import com.massivecraft.factions.event.FactionsEventPowerChange; import com.massivecraft.factions.event.FactionsEventPowerChange.PowerChangeReason; import com.massivecraft.factions.util.VisualizeUtil; @@ -106,7 +107,7 @@ public class FactionsListenerMain implements Listener } // ... Event ... - double newPower = fplayer.getPower() + ConfServer.powerPerDeath; + double newPower = fplayer.getPower() + UConf.get(fplayer).powerPerDeath; FactionsEventPowerChange powerChangeEvent = new FactionsEventPowerChange(null, fplayer, PowerChangeReason.DEATH, newPower); powerChangeEvent.run(); if (powerChangeEvent.isCancelled()) return;