From 870f5caca9c852d5fa8c093c2a672e6e274d96f0 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 13 Oct 2018 17:33:23 -0400 Subject: [PATCH] PvP game over condition --- core/assets/bundles/bundle.properties | 8 ++++++ core/src/io/anuke/mindustry/core/Control.java | 4 +-- core/src/io/anuke/mindustry/core/Logic.java | 19 ++++++++++++- .../io/anuke/mindustry/game/EventType.java | 4 +++ core/src/io/anuke/mindustry/game/Team.java | 5 ++++ .../mindustry/ui/dialogs/RestartDialog.java | 16 ++++++++++- .../anuke/mindustry/server/ServerControl.java | 28 +++---------------- 7 files changed, 56 insertions(+), 28 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index d80cdd13f8..df4b91c089 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -12,6 +12,7 @@ text.linkfail=Failed to open link!\nThe URL has been copied to your cliboard. text.editor.web=The web version does not support the editor!\nDownload the game to use it. text.web.unsupported=The web version does not support this feature! Download the game to use it. text.gameover=Your core has been destroyed +text.pvp.gameover=The[accent] {0}[] team is victorious! text.sector.gameover=This sector has been lost. Re-deploy? text.sector.retry=Retry text.highscore=[accent]New highscore! @@ -653,6 +654,13 @@ block.rtg-generator.name=RTG Generator block.spectre.name=Spectre block.meltdown.name=Meltdown +team.blue.name=blue +team.red.name=red +team.orange.name=orange +team.none.name=gray +team.green.name=green +team.purple.name=purple + unit.alpha-drone.name=Alpha Drone unit.spirit.name=Spirit Drone unit.spirit.description=The starter drone unit. Spawns in the core by default. Automatically mines ores, collects items and repairs blocks. diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index aac708c169..62c37521be 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -153,8 +153,8 @@ public class Control extends Module{ threads.runGraphics(() -> { Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y); - ui.restart.show(); - state.set(State.menu); + //the restart dialog can show info for any number of scenarios + ui.restart.show(event); }); }); diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index 81b610333e..5eca69ac4d 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -6,6 +6,7 @@ import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.GameMode; +import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Teams; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.type.ItemStack; @@ -81,7 +82,23 @@ public class Logic extends Module{ private void checkGameOver(){ if(!state.mode.isPvp && state.teams.get(defaultTeam).cores.size == 0 && !state.gameOver){ state.gameOver = true; - Events.fire(new GameOverEvent()); + Events.fire(new GameOverEvent(waveTeam)); + }else if(state.mode.isPvp){ + Team alive = null; + + for(Team team : Team.all){ + if(state.teams.get(team).cores.size > 0){ + if(alive != null){ + return; + } + alive = team; + } + } + + if(alive != null && !state.gameOver){ + state.gameOver = true; + Events.fire(new GameOverEvent(alive)); + } } } diff --git a/core/src/io/anuke/mindustry/game/EventType.java b/core/src/io/anuke/mindustry/game/EventType.java index 7bc5201664..da7c7ebe31 100644 --- a/core/src/io/anuke/mindustry/game/EventType.java +++ b/core/src/io/anuke/mindustry/game/EventType.java @@ -27,7 +27,11 @@ public class EventType{ } public static class GameOverEvent implements Event{ + public final Team winner; + public GameOverEvent(Team winner){ + this.winner = winner; + } } /** diff --git a/core/src/io/anuke/mindustry/game/Team.java b/core/src/io/anuke/mindustry/game/Team.java index 7fce5dc6fb..1fd94ae2d1 100644 --- a/core/src/io/anuke/mindustry/game/Team.java +++ b/core/src/io/anuke/mindustry/game/Team.java @@ -1,6 +1,7 @@ package io.anuke.mindustry.game; import com.badlogic.gdx.graphics.Color; +import io.anuke.ucore.util.Bundles; public enum Team{ none(Color.DARK_GRAY), @@ -18,4 +19,8 @@ public enum Team{ this.color = color; intColor = Color.rgba8888(color); } + + public String localized(){ + return Bundles.get("team." + name() + ".name"); + } } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/RestartDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/RestartDialog.java index 1a7707d09b..3c76279c04 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/RestartDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/RestartDialog.java @@ -1,12 +1,14 @@ package io.anuke.mindustry.ui.dialogs; import io.anuke.mindustry.core.GameState.State; +import io.anuke.mindustry.game.EventType.GameOverEvent; import io.anuke.mindustry.maps.Sector; import io.anuke.ucore.util.Bundles; import static io.anuke.mindustry.Vars.*; public class RestartDialog extends FloatingDialog{ + private GameOverEvent event; public RestartDialog(){ super("$text.gameover"); @@ -14,13 +16,25 @@ public class RestartDialog extends FloatingDialog{ shown(this::rebuild); } + public void show(GameOverEvent event){ + this.event = event; + show(); + } + void rebuild(){ buttons().clear(); content().clear(); buttons().margin(10); - if(world.getSector() == null){ + if(state.mode.isPvp){ + content().add(Bundles.format("text.gameover.pvp", event.winner.localized())).pad(6); + buttons().addButton("$text.menu", () -> { + hide(); + state.set(State.menu); + logic.reset(); + }).size(130f, 60f); + }else if(world.getSector() == null){ if(control.isHighScore()){ content().add("$text.highscore").pad(6); content().row(); diff --git a/server/src/io/anuke/mindustry/server/ServerControl.java b/server/src/io/anuke/mindustry/server/ServerControl.java index 5c5485d256..0a4b58a8ac 100644 --- a/server/src/io/anuke/mindustry/server/ServerControl.java +++ b/server/src/io/anuke/mindustry/server/ServerControl.java @@ -43,7 +43,6 @@ public class ServerControl extends Module{ private final CommandHandler handler = new CommandHandler(""); private int gameOvers; private boolean inExtraRound; - private Team winnerTeam; private Task lastTask; public ServerControl(String[] args){ @@ -121,8 +120,8 @@ public class ServerControl extends Module{ while(map == previous) map = maps.random(); } - Call.onInfoMessage((state.mode.isPvp && winnerTeam != null - ? "[YELLOW]The " + winnerTeam.name() + " team is victorious![]" : "[SCARLET]Game over![]") + Call.onInfoMessage((state.mode.isPvp + ? "[YELLOW]The " + event.winner.name() + " team is victorious![]" : "[SCARLET]Game over![]") + "\nNext selected map:[accent] "+map.name+"[]" + (map.meta.author() != null ? " by[accent] " + map.meta.author() + "[]" : "") + "."+ "\nNew game begins in " + roundExtraTime + " seconds."); @@ -650,7 +649,7 @@ public class ServerControl extends Module{ info("&lyCore destroyed."); inExtraRound = false; - Events.fire(new GameOverEvent()); + Events.fire(new GameOverEvent(Team.red)); }); handler.register("traceblock", " ", "Prints debug info about a block", arg -> { @@ -882,29 +881,10 @@ public class ServerControl extends Module{ } } - private void checkPvPGameOver(){ - Team alive = null; - - for(Team team : Team.all){ - if(state.teams.get(team).cores.size > 0){ - if(alive != null){ - return; - } - alive = team; - } - } - - if(alive != null && !state.gameOver){ - state.gameOver = true; - winnerTeam = alive; - Events.fire(new GameOverEvent()); - } - } - @Override public void update(){ if(!inExtraRound && state.mode.isPvp){ - checkPvPGameOver(); + // checkPvPGameOver(); } } }