PvP merge
This commit is contained in:
@@ -13,6 +13,7 @@ import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.Saves;
|
||||
import io.anuke.mindustry.game.Unlocks;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.input.DefaultKeybinds;
|
||||
import io.anuke.mindustry.input.DesktopInput;
|
||||
import io.anuke.mindustry.input.InputHandler;
|
||||
@@ -27,6 +28,10 @@ import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityQuery;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.util.Atlas;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Strings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -153,11 +158,24 @@ 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
|
||||
Call.onGameOver(event.winner);
|
||||
});
|
||||
});
|
||||
|
||||
//autohost for pvp sectors
|
||||
Events.on(WorldLoadEvent.class, event -> {
|
||||
if(state.mode.isPvp && !Net.active()){
|
||||
try{
|
||||
Net.host(port);
|
||||
players[0].isAdmin = true;
|
||||
}catch(IOException e){
|
||||
ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
|
||||
threads.runDelay(() -> state.set(State.menu));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Events.on(WorldLoadEvent.class, event -> threads.runGraphics(() -> Events.fire(new WorldLoadGraphicsEvent())));
|
||||
|
||||
Events.on(TileChangeEvent.class, event -> {
|
||||
|
||||
@@ -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;
|
||||
@@ -77,11 +78,26 @@ public class Logic extends Module{
|
||||
Events.fire(new WaveEvent());
|
||||
}
|
||||
|
||||
//this never triggers in PvP; only for checking sector game-overs
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -202,6 +202,7 @@ public class NetServer extends Module{
|
||||
return Integer.MAX_VALUE;
|
||||
});
|
||||
player.setTeam(min);
|
||||
Log.info("Auto-assigned player {0} to team {1}.", player.name, player.getTeam());
|
||||
}
|
||||
|
||||
connections.put(id, player);
|
||||
@@ -414,6 +415,15 @@ public class NetServer extends Module{
|
||||
Log.info("&y{0} has connected.", player.name);
|
||||
}
|
||||
|
||||
@Remote(called = Loc.both)
|
||||
public static void onGameOver(Team winner){
|
||||
threads.runGraphics(() -> ui.restart.show(winner));
|
||||
}
|
||||
|
||||
public boolean isWaitingForPlayers(){
|
||||
return state.mode.isPvp && playerGroup.size() < 2;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(threads.isEnabled() && !threads.isOnThread()) return;
|
||||
|
||||
|
||||
@@ -336,11 +336,13 @@ public class Renderer extends RendererModule{
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height){
|
||||
float lastX = camera.position.x, lastY = camera.position.y;
|
||||
super.resize(width, height);
|
||||
for(Player player : players){
|
||||
control.input(player.playerIndex).resetCursor();
|
||||
}
|
||||
camera.position.set(players[0].x, players[0].y, 0);
|
||||
camera.update();
|
||||
camera.position.set(lastX, lastY, 0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -257,13 +257,27 @@ public class World extends Module{
|
||||
|
||||
endMapLoad();
|
||||
|
||||
if(!headless && state.teams.get(players[0].getTeam()).cores.size == 0){
|
||||
ui.showError("$text.map.nospawn");
|
||||
threads.runDelay(() -> state.set(State.menu));
|
||||
invalidMap = true;
|
||||
if(!headless){
|
||||
if(state.teams.get(players[0].getTeam()).cores.size == 0){
|
||||
ui.showError("$text.map.nospawn");
|
||||
invalidMap = true;
|
||||
}else if(state.mode.isPvp){
|
||||
invalidMap = true;
|
||||
for(Team team : Team.all){
|
||||
if(state.teams.get(team).cores.size != 0 && team != players[0].getTeam()){
|
||||
invalidMap = false;
|
||||
}
|
||||
}
|
||||
if(invalidMap){
|
||||
ui.showError("$text.map.nospawn.pvp");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
invalidMap = false;
|
||||
}
|
||||
|
||||
if(invalidMap) threads.runDelay(() -> state.set(State.menu));
|
||||
|
||||
}
|
||||
|
||||
public void notifyChanged(Tile tile){
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Queue;
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.content.fx.UnitFx;
|
||||
import io.anuke.mindustry.entities.effect.ScorchDecal;
|
||||
@@ -727,12 +726,14 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
|
||||
//region utility methods
|
||||
|
||||
public void toggleTeam(){
|
||||
team = (team == Team.blue ? Team.red : Team.blue);
|
||||
}
|
||||
|
||||
/** Resets all values of the player.*/
|
||||
public void reset(){
|
||||
resetNoAdd();
|
||||
|
||||
add();
|
||||
}
|
||||
|
||||
public void resetNoAdd(){
|
||||
status.clear();
|
||||
team = Team.blue;
|
||||
inventory.clear();
|
||||
@@ -744,8 +745,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
boostHeat = drownTime = hitTime = 0f;
|
||||
mech = (isMobile ? Mechs.starterMobile : Mechs.starterDesktop);
|
||||
placeQueue.clear();
|
||||
|
||||
add();
|
||||
}
|
||||
|
||||
public boolean isShooting(){
|
||||
|
||||
@@ -27,7 +27,11 @@ public class EventType{
|
||||
}
|
||||
|
||||
public static class GameOverEvent implements Event{
|
||||
public final Team winner;
|
||||
|
||||
public GameOverEvent(Team winner){
|
||||
this.winner = winner;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,6 @@ public enum GameMode{
|
||||
pvp{{
|
||||
disableWaves = true;
|
||||
isPvp = true;
|
||||
hidden = true;
|
||||
enemyCoreBuildRadius = 600f;
|
||||
respawnTime = 60 * 10;
|
||||
}};
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +183,7 @@ public class NetworkIO{
|
||||
|
||||
Entities.clear();
|
||||
int id = stream.readInt();
|
||||
player.resetNoAdd();
|
||||
player.read(stream, TimeUtils.millis());
|
||||
player.resetID(id);
|
||||
player.add();
|
||||
@@ -258,7 +259,6 @@ public class NetworkIO{
|
||||
i += consecutives;
|
||||
}
|
||||
|
||||
player.reset();
|
||||
state.teams = new Teams();
|
||||
|
||||
byte teams = stream.readByte();
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.maps.Sector;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class RestartDialog extends FloatingDialog{
|
||||
private Team winner;
|
||||
|
||||
public RestartDialog(){
|
||||
super("$text.gameover");
|
||||
@@ -14,13 +16,25 @@ public class RestartDialog extends FloatingDialog{
|
||||
shown(this::rebuild);
|
||||
}
|
||||
|
||||
public void show(Team winner){
|
||||
this.winner = winner;
|
||||
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",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();
|
||||
|
||||
@@ -145,6 +145,11 @@ public class HudFragment extends Fragment{
|
||||
t.table("clear", top -> top.add("[orange]< " + Bundles.get("text.paused") + " >").pad(6).get().setFontScale(fontScale * 1.5f));
|
||||
});
|
||||
|
||||
parent.fill(t -> {
|
||||
t.visible(() -> netServer.isWaitingForPlayers() && !state.is(State.menu));
|
||||
t.table("clear", c -> c.margin(10).add("$text.waiting.players"));
|
||||
});
|
||||
|
||||
//'core is under attack' table
|
||||
parent.fill(t -> {
|
||||
float notifDuration = 240f;
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.netServer;
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.unitGroups;
|
||||
|
||||
@@ -204,7 +205,7 @@ public class CoreBlock extends StorageBlock{
|
||||
if(entity.progress >= 1f){
|
||||
Call.onUnitRespawn(tile, entity.currentUnit);
|
||||
}
|
||||
}else{
|
||||
}else if(!netServer.isWaitingForPlayers()){
|
||||
entity.warmup += Timers.delta();
|
||||
|
||||
if(entity.solid && entity.warmup > 60f && unitGroups[tile.getTeamID()].getByID(entity.droneID) == null && !Net.client()){
|
||||
@@ -241,7 +242,6 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
public class CoreEntity extends TileEntity implements SpawnerTrait{
|
||||
public Unit currentUnit;
|
||||
public float shieldHeat;
|
||||
int droneID = -1;
|
||||
boolean solid = true;
|
||||
float warmup;
|
||||
@@ -251,7 +251,7 @@ public class CoreBlock extends StorageBlock{
|
||||
|
||||
@Override
|
||||
public void updateSpawning(Unit unit){
|
||||
if(currentUnit == null){
|
||||
if(!netServer.isWaitingForPlayers() && currentUnit == null){
|
||||
currentUnit = unit;
|
||||
progress = 0f;
|
||||
unit.set(tile.drawx(), tile.drawy());
|
||||
|
||||
Reference in New Issue
Block a user