Readd the powerboost for players and the proper maximum power per faction calculation.

This commit is contained in:
Olof Larsson
2013-04-25 07:53:21 +02:00
parent 8382d39409
commit 8070cc5579
4 changed files with 94 additions and 18 deletions

View File

@ -652,10 +652,14 @@ public class Faction extends Entity<Faction> 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<Faction> 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()

View File

@ -44,6 +44,7 @@ public class UPlayer extends SenderEntity<UPlayer> 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<UPlayer> 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<UPlayer> 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
// -------------------------------------------- //