From 8070cc5579d3a8634365bb7158ecd60241ed8e9f Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 25 Apr 2013 07:53:21 +0200 Subject: [PATCH] Readd the powerboost for players and the proper maximum power per faction calculation. --- .../factions/cmd/CmdFactionsPowerBoost.java | 52 ++++++++++++++----- .../massivecraft/factions/entity/Faction.java | 27 ++++++++-- .../massivecraft/factions/entity/UPlayer.java | 29 +++++++++++ .../factions/mixin/PowerMixinDefault.java | 4 +- 4 files changed, 94 insertions(+), 18 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java index a311f70c..756ec521 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java @@ -2,7 +2,9 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARUPlayer; import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.entity.UPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.mcore.cmd.arg.ARDouble; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -13,8 +15,9 @@ public class CmdFactionsPowerBoost extends FCommand { this.addAliases("powerboost"); - this.addRequiredArg("faction"); - this.addRequiredArg("amount"); + this.addRequiredArg("p|f|player|faction"); + this.addRequiredArg("name"); + this.addRequiredArg("#"); this.addRequirements(ReqHasPerm.get(Perm.POWERBOOST.node)); } @@ -22,17 +25,42 @@ public class CmdFactionsPowerBoost extends FCommand @Override public void perform() { - Faction faction = this.arg(0, ARFaction.get(usender)); - if (faction == null) return; + String type = this.arg(0).toLowerCase(); + boolean doPlayer = true; + if (type.equals("f") || type.equals("faction")) + { + doPlayer = false; + } + else if (!type.equals("p") && !type.equals("player")) + { + msg("You must specify \"p\" or \"player\" to target a player or \"f\" or \"faction\" to target a faction."); + msg("ex. /f powerboost p SomePlayer 0.5 -or- /f powerboost f SomeFaction -5"); + return; + } - Double amount = this.arg(1, ARDouble.get()); - if (amount == null) return; + Double targetPower = this.arg(2, ARDouble.get()); + if (targetPower == null) return; - faction.setPowerBoost(amount); - - msg(""+faction.getName()+" now has a power bonus/penalty of "+amount+" to min and max power levels."); - - // TODO: Inconsistent. Why is there no boolean to toggle this logging of? - Factions.get().log(usender.getName()+" has set the power bonus/penalty for "+faction.getName()+" to "+amount+"."); + String target; + + if (doPlayer) + { + UPlayer targetPlayer = this.arg(1, ARUPlayer.getStartAny(sender)); + if (targetPlayer == null) return; + + targetPlayer.setPowerBoost(targetPower); + target = "Player \""+targetPlayer.getName()+"\""; + } + else + { + Faction targetFaction = this.arg(1, ARFaction.get(sender)); + if (targetFaction == null) return; + + targetFaction.setPowerBoost(targetPower); + target = "Faction \""+targetFaction.getName()+"\""; + } + + msg(""+target+" now has a power bonus/penalty of "+targetPower+" to min and max power levels."); + Factions.get().log(usender.getName()+" has set the power bonus/penalty for "+target+" to "+targetPower+"."); } } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 64b3ffe5..74f9fbeb 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -652,10 +652,14 @@ public class Faction extends Entity implements EconomyParticipator { ret += uplayer.getPower(); } - ret += this.getPowerBoost(); - ret = Math.min(ret, this.getPowerMax()); - ret = Math.max(ret, 0); + double factionPowerMax = UConf.get(this).factionPowerMax; + if (factionPowerMax > 0 && ret > factionPowerMax) + { + ret = factionPowerMax; + } + + ret += this.getPowerBoost(); return ret; } @@ -663,7 +667,22 @@ public class Faction extends Entity implements EconomyParticipator public double getPowerMax() { if (this.getFlag(FFlag.INFPOWER)) return 999999; - return UConf.get(this).factionPowerMax + this.getPowerBoost(); + + double ret = 0; + for (UPlayer uplayer : this.getUPlayers()) + { + ret += uplayer.getPowerMax(); + } + + double factionPowerMax = UConf.get(this).factionPowerMax; + if (factionPowerMax > 0 && ret > factionPowerMax) + { + ret = factionPowerMax; + } + + ret += this.getPowerBoost(); + + return ret; } public int getPowerRounded() diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index c4c68cd3..c5a83f24 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -44,6 +44,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato this.setFactionId(that.factionId); this.setRole(that.role); this.setTitle(that.title); + this.powerBoost = that.powerBoost; this.setPower(that.power); return this; @@ -86,6 +87,11 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // Null means the player has no title. private String title = null; + // Player usually do not have a powerboost. It defaults to 0. + // The powerBoost is a custom increase/decrease to default and maximum power. + // Note that player powerBoost and faction powerBoost are very similar. + private Double powerBoost = null; + // Each player has an individual power level. // The power level for online players is occasionally updated by a recurring task and the power should stay the same for offline players. // For that reason the value is to be considered correct when you pick it. Do not call the power update method. @@ -263,6 +269,29 @@ public class UPlayer extends SenderEntity implements EconomyParticipato this.changed(); } + // -------------------------------------------- // + // FIELD: powerBoost + // -------------------------------------------- // + + public double getPowerBoost() + { + Double ret = this.powerBoost; + if (ret == null) ret = 0D; + return ret; + } + + public void setPowerBoost(Double powerBoost) + { + if (powerBoost == null || powerBoost == 0) powerBoost = null; + this.powerBoost = powerBoost; + this.changed(); + } + + public boolean hasPowerBoost() + { + return this.getPowerBoost() != 0D; + } + // -------------------------------------------- // // FIELD: power // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/mixin/PowerMixinDefault.java b/src/com/massivecraft/factions/mixin/PowerMixinDefault.java index 03ab7ead..75acc66a 100644 --- a/src/com/massivecraft/factions/mixin/PowerMixinDefault.java +++ b/src/com/massivecraft/factions/mixin/PowerMixinDefault.java @@ -25,13 +25,13 @@ public class PowerMixinDefault implements PowerMixin @Override public double getMax(UPlayer uplayer) { - return UConf.get(uplayer).powerMax; + return UConf.get(uplayer).powerMax + uplayer.getPowerBoost(); } @Override public double getMin(UPlayer uplayer) { - return UConf.get(uplayer).powerMin; + return UConf.get(uplayer).powerMin + uplayer.getPowerBoost(); } @Override