-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored round/game ending code, config options for times
Took 2 hours 23 minutes
- Loading branch information
1 parent
1d0c566
commit b668402
Showing
21 changed files
with
304 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/main/java/com/thekingelessar/assault/game/GameEndManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.thekingelessar.assault.game; | ||
|
||
import com.thekingelessar.assault.Assault; | ||
import com.thekingelessar.assault.game.player.GamePlayer; | ||
import com.thekingelessar.assault.game.player.PlayerMode; | ||
import com.thekingelessar.assault.game.team.GameTeam; | ||
import com.thekingelessar.assault.game.timertasks.TaskCountdownGameEnd; | ||
import com.thekingelessar.assault.game.world.WorldManager; | ||
import com.thekingelessar.assault.util.FireworkUtils; | ||
import com.thekingelessar.assault.util.Title; | ||
import com.thekingelessar.assault.util.Util; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
|
||
public class GameEndManager | ||
{ | ||
GameInstance gameInstance; | ||
|
||
public GameEndManager(GameInstance gameInstance) | ||
{ | ||
this.gameInstance = gameInstance; | ||
} | ||
|
||
// alertLastEnemyLeft | ||
|
||
// separate end of round and declare winners | ||
|
||
public enum WinState | ||
{ | ||
LOWEST_TIME, | ||
ATTACKERS_LEFT, | ||
DEFENDERS_LEFT, | ||
BUILDING_LEFT; | ||
} | ||
|
||
|
||
public void declareWinners(WinState winState) | ||
{ | ||
gameInstance.gameStage = GameStage.FINISHED; | ||
|
||
String winnerTitleString = gameInstance.winningTeam.color.chatColor + ChatColor.BOLD.toString() + "YOU" + ChatColor.WHITE + " WIN!"; | ||
String loserTitleString = gameInstance.winningTeam.color.getFormattedName(true, true, ChatColor.BOLD) + ChatColor.WHITE + " team wins!"; | ||
|
||
String subtitleString; | ||
|
||
switch (winState) | ||
{ | ||
case LOWEST_TIME: | ||
subtitleString = "Time: " + ChatColor.LIGHT_PURPLE + Util.secondsToMinutes(Util.round(gameInstance.winningTeam.finalAttackingTime, 2), false) + ChatColor.WHITE + " seconds"; | ||
break; | ||
|
||
case ATTACKERS_LEFT: | ||
subtitleString = "All of the " + gameInstance.getAttackingTeam().color.chatColor + "attackers" + ChatColor.RESET + " left!"; | ||
break; | ||
|
||
case DEFENDERS_LEFT: | ||
GameTeam disconnectedTeam = gameInstance.getRemainingTeam().getOppositeTeam(); | ||
subtitleString = "The " + disconnectedTeam.color.chatColor + "enemy team" + ChatColor.RESET + " disconnected!"; | ||
break; | ||
|
||
case BUILDING_LEFT: | ||
disconnectedTeam = gameInstance.getRemainingTeam().getOppositeTeam(); | ||
subtitleString = "The " + disconnectedTeam.color.chatColor + "enemy team" + ChatColor.RESET + " disconnected!"; | ||
break; | ||
|
||
default: | ||
throw new IllegalStateException("Unexpected value: " + winState); | ||
} | ||
|
||
Title winnerTitle = new Title(winnerTitleString, subtitleString, 0, 6, 1); | ||
Title loserTitle = new Title(loserTitleString, subtitleString, 0, 6, 1); | ||
|
||
for (Player player : gameInstance.winningTeam.getPlayers()) | ||
{ | ||
for (int i = 0; i < 5; i++) | ||
{ | ||
FireworkUtils.spawnRandomFirework(player.getLocation(), gameInstance.winningTeam.color); | ||
} | ||
|
||
winnerTitle.clearTitle(player); | ||
winnerTitle.send(player); | ||
|
||
PlayerMode playerMode = PlayerMode.setPlayerMode(player, PlayerMode.HAM, gameInstance); | ||
} | ||
|
||
for (Player player : gameInstance.winningTeam.getOppositeTeam().getPlayers()) | ||
{ | ||
loserTitle.clearTitle(player); | ||
loserTitle.send(player); | ||
|
||
PlayerMode playerMode = PlayerMode.setPlayerMode(player, PlayerMode.HAM, gameInstance); | ||
} | ||
|
||
gameInstance.taskCountdownGameEnd = new TaskCountdownGameEnd(240, 20, 20, gameInstance); | ||
gameInstance.taskCountdownGameEnd.runTaskTimer(Assault.INSTANCE, gameInstance.taskCountdownGameEnd.startDelay, gameInstance.taskCountdownGameEnd.tickDelay); | ||
|
||
gameInstance.updateScoreboards(); | ||
|
||
} | ||
|
||
public void cleanupGameInstance() | ||
{ | ||
for (GameTeam gameTeam : gameInstance.teams.values()) | ||
{ | ||
gameTeam.mapBase.destroyShops(); | ||
} | ||
|
||
for (BukkitRunnable taskTimer : gameInstance.allTimers) | ||
{ | ||
taskTimer.cancel(); | ||
} | ||
|
||
for (GameTeam gameTeam : gameInstance.teams.values()) | ||
{ | ||
gameTeam.buffList.clear(); | ||
|
||
for (Player player : gameTeam.getPlayers()) | ||
{ | ||
GamePlayer gamePlayer = gameTeam.getGamePlayer(player); | ||
gamePlayer.scoreboard.delete(); | ||
gameTeam.removeMember(player); | ||
} | ||
|
||
gameTeam.teamScoreboard.unregister(); | ||
} | ||
|
||
WorldManager.closeWorld(gameInstance.gameWorld); | ||
Assault.gameInstances.remove(gameInstance); | ||
} | ||
} |
Oops, something went wrong.