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)
{
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);
}

View File

@ -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<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)
{
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
{