From f9485da0e358073be9d69dfcce327b8288df953b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 24 Dec 2019 14:38:42 +0100 Subject: [PATCH] Adding new HeartRatioTimeoutWincondition Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 2 ++ FightSystem_Main/src/config.yml | 5 +--- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../steamwar/fightsystem/fight/FightTeam.java | 17 +++++++++++- .../WinconditionHeartRatioTimeout.java | 26 +++++++++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index fce6705..980ead4 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -77,6 +77,7 @@ public class Config { //Active win conditions public static final boolean Timeout; + public static final boolean HeartRatioTimeout; public static final boolean AllDead; public static final boolean CaptainDead; public static final boolean PercentSystem; @@ -155,6 +156,7 @@ public class Config { TeamChatDetection = config.getString("Output.TeamChatDetection"); Timeout = config.getBoolean("WinConditions.Timeout"); + HeartRatioTimeout = config.getBoolean("WinConditions.HeartRatioTimeout"); AllDead = config.getBoolean("WinConditions.AllDead"); CaptainDead = config.getBoolean("WinConditions.CaptainDead"); PercentSystem = config.getBoolean("WinConditions.PercentSystem"); diff --git a/FightSystem_Main/src/config.yml b/FightSystem_Main/src/config.yml index 46248f7..96ddc4f 100644 --- a/FightSystem_Main/src/config.yml +++ b/FightSystem_Main/src/config.yml @@ -37,6 +37,7 @@ Output: TeamChatDetection: + WinConditions: Timeout: boolean + HeartRatioTimeout: boolean AllDead: boolean CaptainDead: boolean PercentSystem: boolean @@ -53,10 +54,6 @@ WinConditionParams: - WATER - TNT - OBSIDIAN -Money: - Win: 0 - Lose: 0 - Draw: 0 Kits: MemberDefault: default LeaderDefault: default diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 88c6b6d..ac55a25 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -131,6 +131,7 @@ public class FightSystem extends JavaPlugin { setAllPlayersGM(GameMode.SURVIVAL); new WinconditionTimeout(); + new WinconditionHeartRatioTimeout(); new WinconditionEntern(); new WinconditionTechKO(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index e69ed25..146adb5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -350,7 +350,7 @@ public class FightTeam implements IFightTeam{ } } - public void replaceSync(boolean replace, Material target, Material replacement) { + void replaceSync(boolean replace, Material target, Material replacement) { if(!replace) return; @@ -393,4 +393,19 @@ public class FightTeam implements IFightTeam{ public Location getSpawn() { return spawn; } + + public double getHeartRatio(){ + int maximumHearts = 0; + double currentHearts = 0; + for(FightPlayer fightPlayer : players){ + maximumHearts += 20; + if(!fightPlayer.isLiving()) + continue; + + currentHearts += fightPlayer.getPlayer().getHealth(); + } + + assert maximumHearts != 0; + return currentHearts / maximumHearts; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java new file mode 100644 index 0000000..7f79a16 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java @@ -0,0 +1,26 @@ +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; + +public class WinconditionHeartRatioTimeout { + + public WinconditionHeartRatioTimeout() { + if(!Config.HeartRatioTimeout) + return; + + new TimeOverCountdown(() -> { + double blueHeartRatio = Fight.getBlueTeam().getHeartRatio(); + double redHeartRatio = Fight.getRedTeam().getHeartRatio(); + + if(blueHeartRatio > redHeartRatio) + FightSystem.setSpectateState(Fight.getBlueTeam()); + else if(blueHeartRatio < redHeartRatio) + FightSystem.setSpectateState(Fight.getRedTeam()); + else + FightSystem.setSpectateState(null); + }); + } +}