PvP game over condition

This commit is contained in:
Anuken 2018-10-13 17:33:23 -04:00
parent 28b4ddfc72
commit 870f5caca9
7 changed files with 56 additions and 28 deletions

View File

@ -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.

View File

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

View File

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

View File

@ -27,7 +27,11 @@ public class EventType{
}
public static class GameOverEvent implements Event{
public final Team winner;
public GameOverEvent(Team winner){
this.winner = winner;
}
}
/**

View File

@ -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");
}
}

View File

@ -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();

View File

@ -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", "<x> <y>", "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();
}
}
}