Improved shuffle command for dedicated server
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Sat Feb 10 12:37:44 EST 2018
|
#Sat Feb 10 12:55:55 EST 2018
|
||||||
version=beta
|
version=beta
|
||||||
androidBuildCode=153
|
androidBuildCode=155
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
code=3.3
|
code=3.3
|
||||||
build=custom build
|
build=custom build
|
||||||
|
|||||||
@@ -38,6 +38,14 @@ public class Maps implements Disposable{
|
|||||||
return defaultMaps;
|
return defaultMaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Array<Map> getCustomMaps(){
|
||||||
|
array.clear();
|
||||||
|
for(Map map : list()){
|
||||||
|
if(map.custom) array.add(map);
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
public Array<Map> getAllMaps(){
|
public Array<Map> getAllMaps(){
|
||||||
array.clear();
|
array.clear();
|
||||||
for(Map map : list()){
|
for(Map map : list()){
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ import io.anuke.mindustry.net.Packets.ChatPacket;
|
|||||||
import io.anuke.mindustry.net.Packets.KickReason;
|
import io.anuke.mindustry.net.Packets.KickReason;
|
||||||
import io.anuke.mindustry.ui.fragments.DebugFragment;
|
import io.anuke.mindustry.ui.fragments.DebugFragment;
|
||||||
import io.anuke.mindustry.world.Map;
|
import io.anuke.mindustry.world.Map;
|
||||||
import io.anuke.ucore.core.Effects;
|
import io.anuke.ucore.core.*;
|
||||||
import io.anuke.ucore.core.Events;
|
|
||||||
import io.anuke.ucore.core.Sounds;
|
|
||||||
import io.anuke.ucore.core.Timers;
|
|
||||||
import io.anuke.ucore.modules.Module;
|
import io.anuke.ucore.modules.Module;
|
||||||
import io.anuke.ucore.util.CommandHandler;
|
import io.anuke.ucore.util.CommandHandler;
|
||||||
import io.anuke.ucore.util.CommandHandler.Command;
|
import io.anuke.ucore.util.CommandHandler.Command;
|
||||||
@@ -37,10 +34,12 @@ import static io.anuke.ucore.util.Log.*;
|
|||||||
|
|
||||||
public class ServerControl extends Module {
|
public class ServerControl extends Module {
|
||||||
private final CommandHandler handler = new CommandHandler("");
|
private final CommandHandler handler = new CommandHandler("");
|
||||||
private boolean shuffle = true;
|
private ShuffleMode mode = ShuffleMode.both;
|
||||||
private boolean shuffleCustom = false;
|
|
||||||
|
|
||||||
public ServerControl(){
|
public ServerControl(){
|
||||||
|
Settings.defaults("shufflemode", "normal");
|
||||||
|
mode = ShuffleMode.valueOf(Settings.getString("shufflemode"));
|
||||||
|
|
||||||
Effects.setScreenShakeProvider((a, b) -> {});
|
Effects.setScreenShakeProvider((a, b) -> {});
|
||||||
Effects.setEffectProvider((a, b, c, d, e) -> {});
|
Effects.setEffectProvider((a, b, c, d, e) -> {});
|
||||||
Sounds.setHeadless(true);
|
Sounds.setHeadless(true);
|
||||||
@@ -72,8 +71,10 @@ public class ServerControl extends Module {
|
|||||||
state.set(State.menu);
|
state.set(State.menu);
|
||||||
Net.closeServer();
|
Net.closeServer();
|
||||||
|
|
||||||
if(shuffle) {
|
if(mode != ShuffleMode.off) {
|
||||||
Array<Map> maps = shuffleCustom ? world.maps().getAllMaps() : world.maps().getDefaultMaps();
|
Array<Map> maps = mode == ShuffleMode.both ? world.maps().getAllMaps() :
|
||||||
|
mode == ShuffleMode.normal ? world.maps().getDefaultMaps() : world.maps().getCustomMaps();
|
||||||
|
|
||||||
Map previous = world.getMap();
|
Map previous = world.getMap();
|
||||||
Map map = previous;
|
Map map = previous;
|
||||||
while(map == previous || !map.visible) map = maps.random();
|
while(map == previous || !map.visible) map = maps.random();
|
||||||
@@ -213,27 +214,13 @@ public class ServerControl extends Module {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.register("shuffle", "<on/off> <custom>", "Enable or disable automatic random map shuffling after gameovers.", arg -> {
|
handler.register("shuffle", "<normal/custom/both/off>", "Set map shuffling.", arg -> {
|
||||||
String s = arg[0];
|
|
||||||
String custom = arg[1];
|
|
||||||
if(s.equalsIgnoreCase("on")){
|
|
||||||
shuffle = true;
|
|
||||||
info("Map shuffling enabled.");
|
|
||||||
}else if(s.equalsIgnoreCase("off")){
|
|
||||||
shuffle = false;
|
|
||||||
info("Map shuffling disabled.");
|
|
||||||
}else{
|
|
||||||
err("Incorrect enable/disable usage.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(custom.equalsIgnoreCase("on")){
|
try{
|
||||||
shuffleCustom = true;
|
mode = ShuffleMode.valueOf(arg[0]);
|
||||||
info("Custom map shuffling enabled.");
|
info("Shuffle mode set to '{0}'.", arg[0]);
|
||||||
}else if(custom.equalsIgnoreCase("off")){
|
}catch (Exception e){
|
||||||
shuffleCustom = false;
|
err("Unknown shuffle mode '{0}'.", arg[0]);
|
||||||
info("Custom map shuffling disabled.");
|
|
||||||
}else{
|
|
||||||
err("Incorrect enable/disable custom map usage.");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -349,4 +336,8 @@ public class ServerControl extends Module {
|
|||||||
state.set(State.menu);
|
state.set(State.menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ShuffleMode{
|
||||||
|
normal, custom, both, off
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user