Change challenge death handling, refatoring.

This commit is contained in:
Thanos paravantis 2016-02-02 17:07:04 +02:00
parent de1ee4f6cb
commit 96cc73fcb7
2 changed files with 48 additions and 30 deletions

View File

@ -208,7 +208,6 @@ public abstract class Challenge implements Listener
public void setLost(Player player, boolean invis) public void setLost(Player player, boolean invis)
{ {
if (isDone(player)) if (isDone(player))
return; return;
if (!Host.isCrumbling()) 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.Manager.GetCondition().Factory().Cloak("Completed", player, player, 7777, true, false);
} }
Host.looseLife(player, false); Host.handleFailure(player, true);
UtilInv.Clear(player); UtilInv.Clear(player);
} }

View File

@ -231,7 +231,7 @@ public class MineWare extends TeamGame implements IThrown
// _challenges.add(ChallengeTameTheWolf.class); // _challenges.add(ChallengeTameTheWolf.class);
} }
@EventHandler @EventHandler(priority = EventPriority.HIGHEST)
public void onTeamCreation(GameStateChangeEvent event) public void onTeamCreation(GameStateChangeEvent event)
{ {
if (event.GetState() == GameState.Recruit) if (event.GetState() == GameState.Recruit)
@ -598,7 +598,8 @@ public class MineWare extends TeamGame implements IThrown
UtilInv.Clear(player); UtilInv.Clear(player);
if (_challenge.hasAnyoneCompleted() && !_challenge.isCompleted(player)) if (_challenge.hasAnyoneCompleted() && !_challenge.isCompleted(player))
looseLife(player, true); //looseLife(player, true);
handleDeath(player);
if (_challenge.isCompleted(player)) if (_challenge.isCompleted(player))
AddGems(player, 3, "Completed Challenge", true, true); AddGems(player, 3, "Completed Challenge", true, true);
@ -890,47 +891,55 @@ public class MineWare extends TeamGame implements IThrown
Location death = player.getLocation().clone(); Location death = player.getLocation().clone();
_challenge.getLost().add(player); _challenge.getLost().add(player);
looseLife(event.getEntity(), true); handleDeath(event.getEntity());
_deathEffect.playDeath(player, death); _deathEffect.playDeath(player, death);
} }
public void looseLife(Player player, boolean isDeath) public void handleDeath(Player player)
{ {
if (!isDeath) if (_challenge == null)
Manager.addSpectator(player, true);
if (_challenge == null || _challenge.isCompleted(player))
return; return;
int lives = getLives(player);
int alive = 0; int alive = 0;
for (Player players : _lives.keySet()) for (Player players : _lives.keySet())
if (_lives.get(players) > 0) if (_lives.get(players) > 0)
alive++; alive++;
lives -= 1; int lives = looseLife(player);
_lives.put(player, lives);
if (lives > 0) if (lives <= 0 && alive > 2)
{
taskFailedMessage(player, lives);
if (isDeath)
Manager.addSpectator(player, true);
}
else
{ {
if (alive <= 3) if (alive <= 3)
_places.add(player); _places.add(player);
Scoreboard.ResetScore(player.getName()); Scoreboard.ResetScore(player.getName());
_chickenAttack.start(player);
if (isDeath && alive > 2) System.out.println("1");
_chickenAttack.start(player);
else
SetPlayerState(player, PlayerState.OUT);
} }
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) private void gameLostMessage(Player player)
@ -1349,7 +1358,10 @@ public class MineWare extends TeamGame implements IThrown
@Override @Override
public ArrayList<Player> GetPlayers(boolean aliveOnly) public ArrayList<Player> 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) if (entity instanceof Player)
{ {
Player player = (Player) entity; 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 else
{ {