From e7cc3c7c5033f0b4bdc603e42e01e0c6a0e578ba Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 2 Jan 2019 11:19:29 +0200 Subject: [PATCH] Implement sumTeamDeaths, maxDeaths and deathPenalty. Improved calculating death penalty. Death count now checks if it must include teamDeaths. maxDeaths now is working, as deathHandicap will be set to minimal value from it and current deathCount. Change level and pointsToNextLevel calculation. Now it will remove deathCount * deathPenalty points from rawBlockCount and use new value to calculate current level and points till next one. --- .../level/calculators/CalcIslandLevel.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java index b6bc97e..0577f96 100644 --- a/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java +++ b/src/main/java/world/bentobox/level/calculators/CalcIslandLevel.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChunkSnapshot; @@ -214,12 +215,38 @@ public class CalcIslandLevel { task.cancel(); // Finalize calculations result.rawBlockCount += (long)(result.underWaterBlockCount * addon.getSettings().getUnderWaterMultiplier()); + // Set the death penalty - result.deathHandicap = addon.getPlayers().getDeaths(world, island.getOwner()); - // Set final score - result.level = (result.rawBlockCount / addon.getSettings().getLevelCost()) - result.deathHandicap - island.getLevelHandicap(); + if (this.addon.getSettings().isSumTeamDeaths()) + { + for (UUID uuid : this.island.getMemberSet()) + { + this.result.deathHandicap += this.addon.getPlayers().getDeaths(this.world, uuid); + } + } + else + { + this.result.deathHandicap = + this.addon.getPlayers().getDeaths(this.world, this.island.getOwner()); + } + + // Just lazy check for min death count. + this.result.deathHandicap = Math.min(this.result.deathHandicap, this.addon.getSettings().getMaxDeaths()); + + long blockAndDeathPoints = this.result.rawBlockCount; + + if (this.addon.getSettings().getDeathPenalty() > 0) + { + // Proper death penalty calculation. + blockAndDeathPoints -= this.result.deathHandicap * this.addon.getSettings().getDeathPenalty(); + } + + this.result.level = blockAndDeathPoints / this.addon.getSettings().getLevelCost() - this.island.getLevelHandicap(); + // Calculate how many points are required to get to the next level - result.pointsToNextLevel = addon.getSettings().getLevelCost() - (result.rawBlockCount % addon.getSettings().getLevelCost()); + this.result.pointsToNextLevel = this.addon.getSettings().getLevelCost() - + (blockAndDeathPoints % this.addon.getSettings().getLevelCost()); + // Report result.report = getReport(); // All done.