From 96cc73fcb770b0299b103af4e1b854d274571d24 Mon Sep 17 00:00:00 2001 From: Thanos paravantis Date: Tue, 2 Feb 2016 17:07:04 +0200 Subject: [PATCH] Change challenge death handling, refatoring. --- .../arcade/game/games/mineware/Challenge.java | 3 +- .../arcade/game/games/mineware/MineWare.java | 75 ++++++++++++------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java index dd00004cf..11ca81c93 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java @@ -208,7 +208,6 @@ public abstract class Challenge implements Listener public void setLost(Player player, boolean invis) { if (isDone(player)) - return; if (!Host.isCrumbling()) @@ -220,7 +219,7 @@ public abstract class Challenge implements Listener Host.Manager.GetCondition().Factory().Cloak("Completed", player, player, 7777, true, false); } - Host.looseLife(player, false); + Host.handleFailure(player, true); UtilInv.Clear(player); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java index a057bc2d7..8a8548103 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java @@ -231,7 +231,7 @@ public class MineWare extends TeamGame implements IThrown // _challenges.add(ChallengeTameTheWolf.class); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onTeamCreation(GameStateChangeEvent event) { if (event.GetState() == GameState.Recruit) @@ -598,7 +598,8 @@ public class MineWare extends TeamGame implements IThrown UtilInv.Clear(player); if (_challenge.hasAnyoneCompleted() && !_challenge.isCompleted(player)) - looseLife(player, true); + //looseLife(player, true); + handleDeath(player); if (_challenge.isCompleted(player)) AddGems(player, 3, "Completed Challenge", true, true); @@ -890,47 +891,55 @@ public class MineWare extends TeamGame implements IThrown Location death = player.getLocation().clone(); _challenge.getLost().add(player); - looseLife(event.getEntity(), true); + handleDeath(event.getEntity()); _deathEffect.playDeath(player, death); } - public void looseLife(Player player, boolean isDeath) + public void handleDeath(Player player) { - if (!isDeath) - Manager.addSpectator(player, true); - - if (_challenge == null || _challenge.isCompleted(player)) + if (_challenge == null) return; - int lives = getLives(player); int alive = 0; for (Player players : _lives.keySet()) if (_lives.get(players) > 0) alive++; - lives -= 1; - _lives.put(player, lives); + int lives = looseLife(player); - if (lives > 0) - { - taskFailedMessage(player, lives); - - if (isDeath) - Manager.addSpectator(player, true); - } - else + if (lives <= 0 && alive > 2) { if (alive <= 3) _places.add(player); Scoreboard.ResetScore(player.getName()); - - if (isDeath && alive > 2) - _chickenAttack.start(player); - else - SetPlayerState(player, PlayerState.OUT); + _chickenAttack.start(player); + System.out.println("1"); } + else + { + handleFailure(player, false); + System.out.println("2"); + } + } + + public int looseLife(Player player) + { + int lives = getLives(player); + lives -= 1; + _lives.put(player, lives); + return lives; + } + + public void handleFailure(Player player, boolean looseLife) + { + if (looseLife) + looseLife(player); + + taskFailedMessage(player, getLives(player)); + Manager.addSpectator(player, true); + SetPlayerState(player, PlayerState.OUT); } private void gameLostMessage(Player player) @@ -1349,7 +1358,10 @@ public class MineWare extends TeamGame implements IThrown @Override public ArrayList GetPlayers(boolean aliveOnly) { - return _playersTeam.GetPlayers(aliveOnly); + if (_playersTeam != null) + return _playersTeam.GetPlayers(aliveOnly); + else + return super.GetPlayers(aliveOnly); } /** @@ -1363,10 +1375,17 @@ public class MineWare extends TeamGame implements IThrown if (entity instanceof Player) { Player player = (Player) entity; - - if (_playersTeam.HasPlayer(player)) + + if (_playersTeam != null) { - return _playersTeam.IsAlive(player); + if (_playersTeam.HasPlayer(player)) + { + return _playersTeam.IsAlive(player); + } + else + { + return false; + } } else {