Re-structuring
This commit is contained in:
@@ -48,7 +48,6 @@ public class ServerControl implements ApplicationListener{
|
||||
private final FileHandle logFolder = Core.files.local("logs/");
|
||||
|
||||
private FileHandle currentLogFile;
|
||||
private int gameOvers;
|
||||
private boolean inExtraRound;
|
||||
private Task lastTask;
|
||||
|
||||
@@ -58,8 +57,6 @@ public class ServerControl implements ApplicationListener{
|
||||
"shufflemode", "normal",
|
||||
"bans", "",
|
||||
"admins", "",
|
||||
"sector_x", 2,
|
||||
"sector_y", 1,
|
||||
"shuffle", true,
|
||||
"crashreport", false,
|
||||
"port", port,
|
||||
@@ -128,57 +125,31 @@ public class ServerControl implements ApplicationListener{
|
||||
warn("&lyIt is highly advised to specify which version you're using by building with gradle args &lc-Pbuildversion=&lm<build>&ly.");
|
||||
}
|
||||
|
||||
Events.on(SectorCompleteEvent.class, event -> {
|
||||
info("Sector complete.");
|
||||
world.sectors.completeSector(world.getSector().x, world.getSector().y);
|
||||
world.sectors.save();
|
||||
gameOvers = 0;
|
||||
inExtraRound = true;
|
||||
Core.settings.put("sector_x", world.getSector().x + 1);
|
||||
Core.settings.save();
|
||||
|
||||
Call.onInfoMessage("[accent]Sector conquered![]\n" + roundExtraTime + " seconds until deployment in next sector.");
|
||||
|
||||
playSectorMap();
|
||||
});
|
||||
|
||||
Events.on(GameOverEvent.class, event -> {
|
||||
if(inExtraRound) return;
|
||||
info("Game over!");
|
||||
|
||||
if(Core.settings.getBool("shuffle")){
|
||||
if(world.getSector() == null){
|
||||
if(world.maps.all().size > 0){
|
||||
Array<Map> maps = world.maps.customMaps().size == 0 ? world.maps.defaultMaps() : world.maps.customMaps();
|
||||
if(world.maps.all().size > 0){
|
||||
Array<Map> maps = world.maps.customMaps().size == 0 ? world.maps.defaultMaps() : world.maps.customMaps();
|
||||
|
||||
Map previous = world.getMap();
|
||||
Map map = previous;
|
||||
if(maps.size > 1){
|
||||
while(map == previous) map = maps.random();
|
||||
}
|
||||
|
||||
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.");
|
||||
|
||||
info("Selected next map to be {0}.", map.name);
|
||||
|
||||
Map fmap = map;
|
||||
|
||||
play(true, () -> world.loadMap(fmap));
|
||||
Map previous = world.getMap();
|
||||
Map map = previous;
|
||||
if(maps.size > 1){
|
||||
while(map == previous) map = maps.random();
|
||||
}
|
||||
}else{
|
||||
Call.onInfoMessage("[SCARLET]Sector has been lost.[]\nRe-deploying in " + roundExtraTime + " seconds.");
|
||||
if(gameOvers >= 2){
|
||||
Core.settings.put("sector_y", Core.settings.getInt("sector_y") < 0 ? Core.settings.getInt("sector_y") + 1 : Core.settings.getInt("sector_y") - 1);
|
||||
Core.settings.save();
|
||||
gameOvers = 0;
|
||||
}
|
||||
gameOvers ++;
|
||||
playSectorMap();
|
||||
info("Re-trying sector map: {0} {1}", Core.settings.getInt("sector_x"), Core.settings.getInt("sector_y"));
|
||||
|
||||
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.");
|
||||
|
||||
info("Selected next map to be {0}.", map.name);
|
||||
|
||||
Map fmap = map;
|
||||
|
||||
play(true, () -> world.loadMap(fmap));
|
||||
}
|
||||
}else{
|
||||
netServer.kickAll(KickReason.gameover);
|
||||
@@ -259,8 +230,8 @@ public class ServerControl implements ApplicationListener{
|
||||
logic.play();
|
||||
|
||||
}else{
|
||||
info("&fiNo map specified. Loading sector {0}, {1}.", Core.settings.getInt("sector_x"), Core.settings.getInt("sector_y"));
|
||||
playSectorMap(false);
|
||||
//TODO
|
||||
info("TODO play generated map");
|
||||
}
|
||||
|
||||
info("Map loaded.");
|
||||
@@ -337,17 +308,6 @@ public class ServerControl implements ApplicationListener{
|
||||
}
|
||||
});
|
||||
|
||||
handler.register("setsector", "<x> <y>", "Sets the next sector to be played. Does not affect current game.", arg -> {
|
||||
try{
|
||||
Core.settings.put("sector_x", Integer.parseInt(arg[0]));
|
||||
Core.settings.put("sector_y", Integer.parseInt(arg[1]));
|
||||
Core.settings.save();
|
||||
info("Sector position set.");
|
||||
}catch(NumberFormatException e){
|
||||
err("Invalid coordinates.");
|
||||
}
|
||||
});
|
||||
|
||||
handler.register("fillitems", "[team]", "Fill the core with 2000 items.", arg -> {
|
||||
if(!state.is(State.playing)){
|
||||
err("Not playing. Host first.");
|
||||
@@ -705,21 +665,6 @@ public class ServerControl implements ApplicationListener{
|
||||
}
|
||||
}
|
||||
|
||||
private void playSectorMap(){
|
||||
playSectorMap(true);
|
||||
}
|
||||
|
||||
private void playSectorMap(boolean wait){
|
||||
int x = Core.settings.getInt("sector_x"), y = Core.settings.getInt("sector_y");
|
||||
if(world.sectors.get(x, y) == null){
|
||||
world.sectors.createSector(x, y);
|
||||
}
|
||||
|
||||
world.sectors.get(x, y).completedMissions = 0;
|
||||
|
||||
play(wait, () -> world.loadSector(world.sectors.get(x, y)));
|
||||
}
|
||||
|
||||
private void play(boolean wait, Runnable run){
|
||||
inExtraRound = true;
|
||||
Runnable r = () -> {
|
||||
|
||||
Reference in New Issue
Block a user