Refactor onChallengeUpdate method.

This commit is contained in:
Thanos paravantis 2016-03-19 16:14:56 +02:00
parent 4c8292e7c9
commit 115508cf72

View File

@ -144,7 +144,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private Challenge _challenge; private Challenge _challenge;
private ArrayList<Block> _lastChallengeBlocks; private ArrayList<Block> _lastChallengeBlocks;
private long _challengeTime; private long _delay;
private String _restrictCommand = "restrict"; private String _restrictCommand = "restrict";
private String _skipCommand = "skip"; private String _skipCommand = "skip";
@ -322,23 +322,21 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (!IsLive()) if (!IsLive())
return; return;
if (_challenge == null) if (_challenge == null) // Triggered after the first challenge ends.
{
if (!UtilTime.elapsed(_delay, 1500))
{ {
if (!UtilTime.elapsed(_challengeTime, 1500))
return; return;
}
resetDeadPlayers();
_challenge = selectChallenge(); _challenge = selectChallenge();
resetDeadPlayers();
keepSearchingWhenNull(); keepSearchingWhenNull();
resetLastChallengeMap(); resetLastChallengeMap();
_deathEffect.removeSpawnedEntities(); _deathEffect.removeSpawnedEntities();
setupChallengeSpawnLocations(); setupChallengeSpawnLocations();
_challenge.createMap(); _challenge.createMap();
_challenge.markSpawnLocations(); // Debug _challenge.markSpawnLocations(); // Debug
@ -351,20 +349,27 @@ public class BawkBawkBattles extends TeamGame implements IThrown
challengeWithRooms.assignRooms(); challengeWithRooms.assignRooms();
} }
_challengeTime = System.currentTimeMillis(); _delay = System.currentTimeMillis();
_settings.setWaiting(true); _settings.setWaiting(true);
} }
else if (_settings.isWaiting()) else if (_settings.isWaiting()) // Triggered when a challenge should start.
{
if (!UtilTime.elapsed(_delay, 1000))
{ {
if (!UtilTime.elapsed(_challengeTime, 1000))
return; return;
if (!_settings.areMessagesBeingSent() && !_settings.areMessagesSent())
{
addEffectsToPlayers();
startChallengeDescriptionThread();
} }
else if (_settings.areMessagesSent())
displayDescriptionAndStartChallenge();
}
else // Triggered when a challenge should end.
{
checkChallengeEnd();
}
}
private void displayDescriptionAndStartChallenge()
{
if (_settings.areMessagesSent())
{ {
removeEffectsFromPlayers(); removeEffectsFromPlayers();
@ -377,8 +382,14 @@ public class BawkBawkBattles extends TeamGame implements IThrown
Manager.getPluginManager().registerEvents(_challenge, Manager.getPlugin()); Manager.getPluginManager().registerEvents(_challenge, Manager.getPlugin());
_settings.markMessagesAsSent(false); _settings.markMessagesAsSent(false);
} }
else if (!_settings.areMessagesBeingSent())
{
addEffectsToPlayers();
startChallengeDescriptionThread();
} }
else }
private void checkChallengeEnd()
{ {
if (_challenge.canFinish()) if (_challenge.canFinish())
{ {
@ -405,7 +416,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
updateChallengeTimer(); updateChallengeTimer();
} }
} }
}
private void announceCrumbling() private void announceCrumbling()
{ {
@ -418,39 +428,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
} }
} }
private ArrayList<Location> getBestSpawnLocations()
{
ArrayList<Location> available = setupChallengeSpawnLocations();
ArrayList<Location> selected = new ArrayList<Location>();
for (int i = 0; i < available.size(); i++)
{
Location furthest = null;
double furthestDist = 0;
for (Location spawn : available)
{
if (selected.contains(spawn))
continue;
double dist = 0;
for (Location loc : selected)
dist += loc.distance(spawn);
if (furthest == null || furthestDist < dist)
{
furthest = spawn;
furthestDist = dist;
}
}
selected.add(furthest);
}
return selected;
}
private void resetDeadPlayers() private void resetDeadPlayers()
{ {
for (Player player : GetPlayers(false)) for (Player player : GetPlayers(false))
@ -614,7 +591,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
public void endCurrentChallenge() public void endCurrentChallenge()
{ {
_challengeTime = System.currentTimeMillis(); _delay = System.currentTimeMillis();
resetPlayersOnChallengeEnding(); resetPlayersOnChallengeEnding();
@ -1386,7 +1363,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (event.GetState() != GameState.Live) if (event.GetState() != GameState.Live)
return; return;
_challengeTime = System.currentTimeMillis(); _delay = System.currentTimeMillis();
_chickenAttack = new ChickenAttack(this, _chickenAttackCenter); _chickenAttack = new ChickenAttack(this, _chickenAttackCenter);
} }
@ -1545,9 +1522,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
return _challenge; return _challenge;
} }
public long getChallengeTime() public long getCurrentDelay()
{ {
return _challengeTime; return _delay;
} }
@Override @Override