From dbae65bf8204c4eb8e9fde78bf370f320848cc4f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 22 Dec 2019 15:20:50 +0100 Subject: [PATCH] Finishing SG.eu Points Wincondition implementation Signed-off-by: Lixfel --- .../countdown/TimeOverCountdown.java | 7 +- .../fightsystem/utils/FightScoreboard.java | 10 ++- .../winconditions/WinconditionAllDead.java | 18 ++--- .../WinconditionCaptainDead.java | 18 ++--- .../winconditions/WinconditionPoints.java | 74 +++++++++++++++++-- .../WinconditionRelativePercent.java | 13 ++-- .../winconditions/WinconditionTimeout.java | 3 +- 7 files changed, 103 insertions(+), 40 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java index 24e9d95..6b94ed9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java @@ -6,8 +6,11 @@ import org.bukkit.Bukkit; public class TimeOverCountdown extends Countdown { - public TimeOverCountdown() { + private final Runnable timeOver; + + public TimeOverCountdown(Runnable timeOver) { super(Config.TimeoutTime, "BLOCK_NOTE_BASS", false); + this.timeOver = timeOver; } @Override @@ -18,7 +21,7 @@ public class TimeOverCountdown extends Countdown { @Override public void countdownFinished() { Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!"); - FightSystem.setSpectateState(null); + timeOver.run(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index a987be6..f5ce957 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -5,6 +5,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.winconditions.WinconditionPercentSystem; +import de.steamwar.fightsystem.winconditions.WinconditionPoints; import de.steamwar.fightsystem.winconditions.WinconditionRelativePercent; import de.steamwar.fightsystem.winconditions.WinconditionWaterTechKO; import org.bukkit.Bukkit; @@ -12,16 +13,19 @@ import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; +import java.util.Objects; + public class FightScoreboard { private FightScoreboard(){} - private static final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard(); + private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); private static final Objective objective; private static int index = 0; static{ if(scoreboard.getObjective("AAA") == null) + //noinspection deprecation objective = scoreboard.registerNewObjective("AAA", "BBB"); else objective = scoreboard.getObjective("AAA"); @@ -30,6 +34,7 @@ public class FightScoreboard { public static void init(){ Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> { objective.unregister(); + //noinspection deprecation scoreboard.registerNewObjective("AAA", "BBB"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); @@ -75,6 +80,9 @@ public class FightScoreboard { }else if(Config.RelativePercent){ objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%").setScore(1); objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%").setScore(0); + }else if(Config.Points){ + objective.getScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints()).setScore(1); + objective.getScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints()).setScore(0); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java index 1549a49..a938f73 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java @@ -18,28 +18,22 @@ public class WinconditionAllDead extends PlayerWincondition { @EventHandler public void handlePlayerDeath(PlayerDeathEvent event) { - Player player = event.getEntity().getPlayer(); - - if(!isTarget(player)) - return; - - FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam.allPlayersOut()) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §cist gestorben!"); - FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); - } + handleDeath(event.getEntity().getPlayer(), " §cist gestorben!"); } @EventHandler public void handlePlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); + handleDeath(event.getPlayer(), " §chat den Kampf verlassen!"); + } + private void handleDeath(Player player, String message){ if(!isTarget(player)) return; FightTeam fightTeam = Fight.getPlayerTeam(player); + assert fightTeam != null; // Checked with isTarget if(fightTeam.allPlayersOut()) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus §6" + fightTeam.getPrefix() + fightTeam.getColoredName() + " §chat den Kampf verlassen!"); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message); FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java index f8c4956..3fb803e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java @@ -18,28 +18,22 @@ public class WinconditionCaptainDead extends PlayerWincondition { @EventHandler public void handlePlayerDeath(PlayerDeathEvent event) { - Player player = event.getEntity().getPlayer(); - - if(!isTarget(player)) - return; - - FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam.isPlayerLeader(player)) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §cist gestorben!"); - FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); - } + handleDeath(event.getEntity().getPlayer(), " §cist gestorben!"); } @EventHandler public void handlePlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); + handleDeath(event.getPlayer(), " §chat den Kampf verlassen!"); + } + private void handleDeath(Player player, String message){ if(!isTarget(player)) return; FightTeam fightTeam = Fight.getPlayerTeam(player); + assert fightTeam != null; // Checked with isTarget if(fightTeam.isPlayerLeader(player)) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + " §chat den Kampf verlassen!"); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message); FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 157c17a..893e081 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -1,10 +1,17 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; -public class WinconditionPoints { +public class WinconditionPoints extends PlayerWincondition { private static TeamPoints blue; private static TeamPoints red; @@ -13,22 +20,69 @@ public class WinconditionPoints { if(!Config.Points) return; + init(true); blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed()); red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue()); + new TimeOverCountdown(this::fightEnds); } - public TeamPoints getRed(){ + @EventHandler + public void handlePlayerDeath(PlayerDeathEvent event) { + handleDeath(event.getEntity().getPlayer(), " §cist gestorben!"); + } + + @EventHandler + public void handlePlayerQuit(PlayerQuitEvent event) { + handleDeath(event.getPlayer(), " §chat den Kampf verlassen!"); + } + + private void handleDeath(Player player, String message){ + if(!isTarget(player)) + return; + + FightTeam fightTeam = Fight.getPlayerTeam(player); + TeamPoints enemy = getEnemyByTeam(fightTeam); + assert fightTeam != null; // Checked by isTarget + if(fightTeam.isPlayerLeader(player)) { + enemy.points += 500; + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + message); + FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); + }else if(fightTeam.getPlayers().size() <= 5) + enemy.points += 300; + else + enemy.points += 200; + + } + + public static TeamPoints getRed(){ return red; } - public TeamPoints getBlue(){ + public static TeamPoints getBlue(){ return blue; } + private void fightEnds(){ + if(red.getPoints() > blue.getPoints()) + FightSystem.setSpectateState(blue.enemy); + else if(red.getPoints() < blue.getPoints()) + FightSystem.setSpectateState(red.enemy); + else + FightSystem.setSpectateState(null); + } + + private TeamPoints getEnemyByTeam(FightTeam team){ + if(team == blue.enemy) + return blue; + else + return red; + } + public static class TeamPoints extends PlayerWincondition { private final FightTeam enemy; private final WinconditionRelativePercent.TeamPercent enemyPercent; private final double factor; + private static final int maxPoints = 2000; private int points; @@ -39,14 +93,24 @@ public class WinconditionPoints { points = 0; if(enemyPercent.getBlockCount() < ownPercent.getBlockCount()) - factor = 20; + this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte else{ + double f = 10000 * ownPercent.getBlockCount() / enemyPercent.getBlockCount(); + if(f > 10000) + f = 10000; + else if(f < 4000) + f = 4000; + + this.factor = f; } } public int getPoints(){ - return points; + int damagePoints = (int)(enemyPercent.getPercent() * factor); + if(damagePoints > maxPoints) + damagePoints = maxPoints; + return points + damagePoints; } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index 3c4f84c..3dfe9a8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -62,20 +62,19 @@ public class WinconditionRelativePercent{ return Math.round(10000.0 * getPercent()) / 100.0; } - public final int getBlockCount(){ + final int getBlockCount(){ return blockCount; } - public int getCurrentBlocks(){ - return currentBlocks; - } - - private double getPercent(){ + double getPercent(){ int blocksDestroyed = blockCount - currentBlocks; return blocksDestroyed > 0 ? blocksDestroyed / (double) blockCount : 0; } private int currentBlocks(){ + if(FightSystem.isEntern()) + return currentBlocks; + int blocks = 0; for(int x = team.getCornerX(); x < team.getCornerX() + Config.SchemsizeX; x++){ for(int y = team.getCornerY(); y < team.getCornerY() + Config.SchemsizeY; y++){ @@ -91,7 +90,7 @@ public class WinconditionRelativePercent{ private void checkPercentDefeat(){ if(!Config.RelativePercent) return; - if(getPercent() >= Config.PercentWin){ + if(getPercent() * 100 >= Config.PercentWin){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!"); FightSystem.setSpectateState(Fight.getOpposite(team)); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java index 35e17ba..dd24980 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java @@ -1,5 +1,6 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.Config; @@ -8,6 +9,6 @@ public class WinconditionTimeout { if(!Config.Timeout) return; - new TimeOverCountdown(); + new TimeOverCountdown(() -> FightSystem.setSpectateState(null)); } }