Search in sources :

Example 1 with Difficulty

use of io.anuke.mindustry.game.Difficulty in project Mindustry by Anuken.

the class LevelDialog method setup.

void setup() {
    Table maps = new Table();
    pane = new ScrollPane(maps);
    pane.setFadeScrollBars(false);
    int maxwidth = 4;
    Table selmode = new Table();
    ButtonGroup<TextButton> group = new ButtonGroup<>();
    selmode.add("$text.level.mode").padRight(15f);
    for (GameMode mode : GameMode.values()) {
        TextButton[] b = { null };
        b[0] = Elements.newButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode);
        b[0].update(() -> b[0].setChecked(state.mode == mode));
        group.add(b[0]);
        selmode.add(b[0]).size(130f, 54f);
    }
    selmode.addButton("?", this::displayGameModeHelp).size(50f, 54f).padLeft(18f);
    content().add(selmode);
    content().row();
    Difficulty[] ds = Difficulty.values();
    float s = 50f;
    Table sdif = new Table();
    sdif.add("$setting.difficulty.name").padRight(15f);
    sdif.defaults().height(s + 4);
    sdif.addImageButton("icon-arrow-left", 10 * 3, () -> {
        state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
    }).width(s);
    sdif.addButton("", () -> {
    }).update(t -> {
        t.setText(state.difficulty.toString());
        t.setTouchable(Touchable.disabled);
    }).width(180f);
    sdif.addImageButton("icon-arrow-right", 10 * 3, () -> {
        state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() + 1, ds.length)]);
    }).width(s);
    content().add(sdif);
    content().row();
    int i = 0;
    for (Map map : world.maps().list()) {
        if (!map.visible && !debug)
            continue;
        if (i % maxwidth == 0) {
            maps.row();
        }
        Table inset = new Table("pane-button");
        inset.add("[accent]" + Bundles.get("map." + map.name + ".name", map.name)).pad(3f);
        inset.row();
        inset.label((() -> {
            try {
                return Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name));
            } catch (Exception e) {
                Settings.defaults("hiscore" + map.name, 1);
                return Bundles.format("text.level.highscore", 0);
            }
        })).pad(3f);
        inset.pack();
        float images = 154f;
        Stack stack = new Stack();
        Image back = new Image("white");
        back.setColor(map.backgroundColor);
        ImageButton image = new ImageButton(new TextureRegion(map.texture), "togglemap");
        image.row();
        image.add(inset).width(images + 6);
        TextButton[] delete = new TextButton[1];
        if (map.custom) {
            image.row();
            delete[0] = image.addButton("Delete", () -> {
                Timers.run(1f, () -> {
                    ui.showConfirm("$text.level.delete.title", Bundles.format("text.level.delete", Bundles.get("map." + map.name + ".name", map.name)), () -> {
                        world.maps().removeMap(map);
                        reload();
                        Core.scene.setScrollFocus(pane);
                    });
                });
            }).width(images + 16).padBottom(-10f).grow().get();
        }
        Vector2 hit = new Vector2();
        image.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                image.localToStageCoordinates(hit.set(x, y));
                if (delete[0] != null && (delete[0].getClickListener().isOver() || delete[0].getClickListener().isPressed() || (Core.scene.hit(hit.x, hit.y, true) != null && Core.scene.hit(hit.x, hit.y, true).isDescendantOf(delete[0])))) {
                    return;
                }
                selectedMap = map;
                hide();
                control.playMap(selectedMap);
            }
        });
        image.getImageCell().size(images);
        stack.add(back);
        stack.add(image);
        maps.add(stack).width(170).top().pad(4f);
        maps.marginRight(26);
        i++;
    }
    content().add(pane).uniformX();
    shown(() -> {
        // this is necessary for some reason?
        Timers.run(2f, () -> {
            Core.scene.setScrollFocus(pane);
        });
    });
}
Also used : Map(io.anuke.mindustry.world.Map) Core(io.anuke.ucore.core.Core) Bundles(io.anuke.ucore.util.Bundles) Settings(io.anuke.ucore.core.Settings) Stack(io.anuke.ucore.scene.ui.layout.Stack) Elements(io.anuke.ucore.scene.utils.Elements) InputEvent(io.anuke.ucore.scene.event.InputEvent) ClickListener(io.anuke.ucore.scene.event.ClickListener) io.anuke.ucore.scene.ui(io.anuke.ucore.scene.ui) Vector2(com.badlogic.gdx.math.Vector2) GameMode(io.anuke.mindustry.game.GameMode) Table(io.anuke.ucore.scene.ui.layout.Table) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Difficulty(io.anuke.mindustry.game.Difficulty) Mathf(io.anuke.ucore.util.Mathf) Timers(io.anuke.ucore.core.Timers) Vars(io.anuke.mindustry.Vars) Touchable(io.anuke.ucore.scene.event.Touchable) Table(io.anuke.ucore.scene.ui.layout.Table) Difficulty(io.anuke.mindustry.game.Difficulty) Stack(io.anuke.ucore.scene.ui.layout.Stack) GameMode(io.anuke.mindustry.game.GameMode) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Vector2(com.badlogic.gdx.math.Vector2) InputEvent(io.anuke.ucore.scene.event.InputEvent) Map(io.anuke.mindustry.world.Map) ClickListener(io.anuke.ucore.scene.event.ClickListener)

Example 2 with Difficulty

use of io.anuke.mindustry.game.Difficulty in project Mindustry by Anuken.

the class ServerControl method registerCommands.

private void registerCommands() {
    handler.register("help", "Displays this command list.", arg -> {
        info("Commands:");
        for (Command command : handler.getCommandList()) {
            print("   &y" + command.text + (command.paramText.isEmpty() ? "" : " ") + command.paramText + " - &lm" + command.description);
        }
    });
    handler.register("version", "Displays server version info.", arg -> {
        info("&lmVersion: &lyMindustry {0} {1} / {2}", Version.code, Version.type, Version.buildName);
    });
    handler.register("exit", "Exit the server application.", arg -> {
        info("Shutting down server.");
        Net.dispose();
        Gdx.app.exit();
    });
    handler.register("stop", "Stop hosting the server.", arg -> {
        Net.closeServer();
        state.set(State.menu);
        netServer.reset();
        Log.info("Stopped server.");
    });
    handler.register("host", "[mapname] [mode]", "Open the server with a specific map.", arg -> {
        if (state.is(State.playing)) {
            err("Already hosting. Type 'stop' to stop hosting first.");
            return;
        }
        Map result = null;
        if (arg.length > 0) {
            String search = arg[0];
            for (Map map : world.maps().list()) {
                if (map.name.equalsIgnoreCase(search))
                    result = map;
            }
            if (result == null) {
                err("No map with name &y'{0}'&lr found.", search);
                return;
            }
        } else {
            while (result == null || !result.visible) result = world.maps().getAllMaps().random();
            Log.info("&ly&fiNo map specified, so &lb{0}&ly was chosen randomly.", result.name);
        }
        GameMode mode;
        try {
            mode = arg.length < 2 ? GameMode.waves : GameMode.valueOf(arg[1]);
        } catch (IllegalArgumentException e) {
            err("No gamemode '{0}' found.", arg[1]);
            return;
        }
        info("Loading map...");
        state.mode = mode;
        logic.reset();
        world.loadMap(result);
        state.set(State.playing);
        info("Map loaded.");
        host();
    });
    handler.register("maps", "Display all available maps.", arg -> {
        Log.info("Maps:");
        for (Map map : world.maps().getAllMaps()) {
            Log.info("  &ly{0}: &lb&fi{1} / {2}x{3}", map.name, map.custom ? "Custom" : "Default", map.getWidth(), map.getHeight());
        }
    });
    handler.register("status", "Display server status.", arg -> {
        if (state.is(State.menu)) {
            info("&lyStatus: &rserver closed");
        } else {
            info("&lyStatus: &lcPlaying on map &fi{0}&fb &lb/&lc Wave {1} &lb/&lc {2}", Strings.capitalize(world.getMap().name), state.wave, Strings.capitalize(state.difficulty.name()));
            if (state.enemies > 0) {
                info("&ly{0} enemies remaining.", state.enemies);
            } else {
                info("&ly{0} seconds until next wave.", (int) (state.wavetime / 60));
            }
            if (playerGroup.size() > 0) {
                info("&lyPlayers: {0}", playerGroup.size());
                for (Player p : playerGroup.all()) {
                    print("   &y" + p.name);
                }
            } else {
                info("&lyNo players connected.");
            }
            info("&lbFPS: {0}", (int) (60f / Timers.delta()));
        }
    });
    handler.register("players", "Display player info.", arg -> {
        if (state.is(State.menu)) {
            info("&lyServer is closed.");
        } else {
            if (playerGroup.size() > 0) {
                info("&lyPlayers: {0}", playerGroup.size());
                for (Player p : playerGroup.all()) {
                    print("   &y{0} / Connection {1} / IP: {2}", p.name, p.clientid, Net.getConnection(p.clientid).address);
                }
            } else {
                info("&lyNo players connected.");
            }
        }
    });
    handler.register("say", "<message...>", "Send a message to all players.", arg -> {
        if (!state.is(State.playing)) {
            err("Not hosting. Host a game first.");
            return;
        }
        netCommon.sendMessage("[GRAY][[Server]:[] " + arg[0]);
        info("&lyServer: &lb{0}", arg[0]);
    });
    handler.register("difficulty", "<difficulty>", "Set game difficulty.", arg -> {
        try {
            Difficulty diff = Difficulty.valueOf(arg[0]);
            state.difficulty = diff;
            info("Difficulty set to '{0}'.", arg[0]);
        } catch (IllegalArgumentException e) {
            err("No difficulty with name '{0}' found.", arg[0]);
        }
    });
    handler.register("friendlyfire", "<on/off>", "Enable or disable friendly fire", arg -> {
        String s = arg[0];
        if (s.equalsIgnoreCase("on")) {
            NetEvents.handleFriendlyFireChange(true);
            state.friendlyFire = true;
            info("Friendly fire enabled.");
        } else if (s.equalsIgnoreCase("off")) {
            NetEvents.handleFriendlyFireChange(false);
            state.friendlyFire = false;
            info("Friendly fire disabled.");
        } else {
            err("Incorrect command usage.");
        }
    });
    handler.register("shuffle", "<normal/custom/both/off>", "Set map shuffling.", arg -> {
        try {
            mode = ShuffleMode.valueOf(arg[0]);
            Settings.putString("shufflemode", arg[0]);
            Settings.save();
            info("Shuffle mode set to '{0}'.", arg[0]);
        } catch (Exception e) {
            err("Unknown shuffle mode '{0}'.", arg[0]);
        }
    });
    handler.register("kick", "<username...>", "Kick a person by name.", arg -> {
        if (!state.is(State.playing)) {
            err("Not hosting a game yet. Calm down.");
            return;
        }
        Player target = null;
        for (Player player : playerGroup.all()) {
            if (player.name.equalsIgnoreCase(arg[0])) {
                target = player;
                break;
            }
        }
        if (target != null) {
            netServer.kick(target.clientid, KickReason.kick);
            info("It is done.");
        } else {
            info("Nobody with that name could be found...");
        }
    });
    handler.register("ban", "<username...>", "Ban a person by name.", arg -> {
        if (!state.is(State.playing)) {
            err("Can't ban people by name with no players.");
            return;
        }
        Player target = null;
        for (Player player : playerGroup.all()) {
            if (player.name.equalsIgnoreCase(arg[0])) {
                target = player;
                break;
            }
        }
        if (target != null) {
            String ip = Net.getConnection(target.clientid).address;
            netServer.admins.banPlayerIP(ip);
            netServer.admins.banPlayerID(netServer.admins.getTrace(ip).uuid);
            netServer.kick(target.clientid, KickReason.banned);
            info("Banned player by IP and ID: {0} / {1}", ip, netServer.admins.getTrace(ip).uuid);
        } else {
            info("Nobody with that name could be found.");
        }
    });
    handler.register("bans", "List all banned IPs and IDs.", arg -> {
        Array<PlayerInfo> bans = netServer.admins.getBanned();
        if (bans.size == 0) {
            Log.info("No ID-banned players have been found.");
        } else {
            Log.info("&lyBanned players [ID]:");
            for (PlayerInfo info : bans) {
                Log.info(" &ly {0} / Last known name: '{1}'", info.id, info.lastName);
            }
        }
        Array<String> ipbans = netServer.admins.getBannedIPs();
        if (ipbans.size == 0) {
            Log.info("No IP-banned players have been found.");
        } else {
            Log.info("&lmBanned players [IP]:");
            for (String string : ipbans) {
                PlayerInfo info = netServer.admins.findByIP(string);
                Log.info(" &lm '{0}' / Last known name: '{1}' / ID: '{2}'", string, info.lastName, info.id);
            }
        }
    });
    handler.register("banip", "<ip>", "Ban a person by IP.", arg -> {
        if (netServer.admins.banPlayerIP(arg[0])) {
            info("Banned player by IP: {0}.", arg[0]);
            for (Player player : playerGroup.all()) {
                if (Net.getConnection(player.clientid).address.equals(arg[0])) {
                    netServer.kick(player.clientid, KickReason.banned);
                    break;
                }
            }
        } else {
            err("That IP is already banned!");
        }
    });
    handler.register("banid", "<id>", "Ban a person by their unique ID.", arg -> {
        if (netServer.admins.banPlayerID(arg[0])) {
            info("Banned player by ID: {0}.", arg[0]);
            for (Player player : playerGroup.all()) {
                if (netServer.admins.getTrace(Net.getConnection(player.clientid).address).uuid.equals(arg[0])) {
                    netServer.kick(player.clientid, KickReason.banned);
                    break;
                }
            }
        } else {
            err("That ID is already banned!");
        }
    });
    handler.register("unbanip", "<ip>", "Completely unban a person by IP.", arg -> {
        if (netServer.admins.unbanPlayerIP(arg[0])) {
            info("Unbanned player by IP: {0}.", arg[0]);
        } else {
            err("That IP is not banned!");
        }
    });
    handler.register("unbanid", "<id>", "Completely unban a person by ID.", arg -> {
        if (netServer.admins.unbanPlayerID(arg[0])) {
            info("&lmUnbanned player by ID: {0}.", arg[0]);
        } else {
            err("That IP is not banned!");
        }
    });
    handler.register("admin", "<username...>", "Make a user admin", arg -> {
        if (!state.is(State.playing)) {
            err("Open the server first.");
            return;
        }
        Player target = null;
        for (Player player : playerGroup.all()) {
            if (player.name.equalsIgnoreCase(arg[0])) {
                target = player;
                break;
            }
        }
        if (target != null) {
            String id = netServer.admins.getTrace(Net.getConnection(target.clientid).address).uuid;
            netServer.admins.adminPlayer(id, Net.getConnection(target.clientid).address);
            NetEvents.handleAdminSet(target, true);
            info("Admin-ed player by ID: {0} / {1}", id, arg[0]);
        } else {
            info("Nobody with that name could be found.");
        }
    });
    handler.register("unadmin", "<username...>", "Removes admin status from a player", arg -> {
        if (!state.is(State.playing)) {
            err("Open the server first.");
            return;
        }
        Player target = null;
        for (Player player : playerGroup.all()) {
            if (player.name.equalsIgnoreCase(arg[0])) {
                target = player;
                break;
            }
        }
        if (target != null) {
            String id = netServer.admins.getTrace(Net.getConnection(target.clientid).address).uuid;
            netServer.admins.unAdminPlayer(id);
            NetEvents.handleAdminSet(target, false);
            info("Un-admin-ed player by ID: {0} / {1}", id, arg[0]);
        } else {
            info("Nobody with that name could be found.");
        }
    });
    handler.register("admins", "List all admins.", arg -> {
        Array<PlayerInfo> admins = netServer.admins.getAdmins();
        if (admins.size == 0) {
            Log.info("No admins have been found.");
        } else {
            Log.info("&lyAdmins:");
            for (PlayerInfo info : admins) {
                Log.info(" &lm {0} /  ID: '{1}' / IP: '{2}'", info.lastName, info.id, info.lastIP);
            }
        }
    });
    handler.register("runwave", "Trigger the next wave.", arg -> {
        if (!state.is(State.playing)) {
            err("Not hosting. Host a game first.");
        } else if (state.enemies > 0) {
            err("There are still {0} enemies remaining.", state.enemies);
        } else {
            logic.runWave();
            info("Wave spawned.");
        }
    });
    handler.register("load", "<slot>", "Load a save from a slot.", arg -> {
        if (state.is(State.playing)) {
            err("Already hosting. Type 'stop' to stop hosting first.");
            return;
        } else if (!Strings.canParseInt(arg[0])) {
            err("Invalid save slot '{0}'.", arg[0]);
            return;
        }
        int slot = Strings.parseInt(arg[0]);
        if (!SaveIO.isSaveValid(slot)) {
            err("No save data found for slot.");
            return;
        }
        SaveIO.loadFromSlot(slot);
        info("Save loaded.");
        host();
        state.set(State.playing);
    });
    handler.register("save", "<slot>", "Save game state to a slot.", arg -> {
        if (!state.is(State.playing)) {
            err("Not hosting. Host a game first.");
            return;
        } else if (!Strings.canParseInt(arg[0])) {
            err("Invalid save slot '{0}'.", arg[0]);
            return;
        }
        int slot = Strings.parseInt(arg[0]);
        SaveIO.saveToSlot(slot);
        info("Saved to slot {0}.", slot);
    });
    handler.register("gameover", "Force a game over.", arg -> {
        if (state.is(State.menu)) {
            info("Not playing a map.");
            return;
        }
        world.removeBlock(world.getCore());
        info("Core destroyed.");
    });
    handler.register("debug", "Print debug info", arg -> {
        info(DebugFragment.debugInfo());
    });
    handler.register("traceblock", "<x> <y>", "Prints debug info about a block", arg -> {
        try {
            int x = Integer.parseInt(arg[0]);
            int y = Integer.parseInt(arg[1]);
            Tile tile = world.tile(x, y);
            if (tile != null) {
                if (tile.entity != null) {
                    Array<Object> arr = tile.block().getDebugInfo(tile);
                    StringBuilder result = new StringBuilder();
                    for (int i = 0; i < arr.size / 2; i++) {
                        result.append(arr.get(i * 2));
                        result.append(": ");
                        result.append(arr.get(i * 2 + 1));
                        result.append("\n");
                    }
                    Log.info("&ly{0}", result);
                } else {
                    Log.info("No tile entity for that block.");
                }
            } else {
                Log.info("No tile at that location.");
            }
        } catch (NumberFormatException e) {
            Log.err("Invalid coordinates passed.");
        }
    });
    handler.register("info", "<UUID>", "Get global info for a player's UUID.", arg -> {
        PlayerInfo info = netServer.admins.getInfoOptional(arg[0]);
        if (info != null) {
            Log.info("&lcTrace info for player '{0}':", info.lastName);
            Log.info("  &lyall names used: {0}", info.names);
            Log.info("  &lyIP: {0}", info.lastIP);
            Log.info("  &lyall IPs used: {0}", info.ips);
            Log.info("  &lytimes joined: {0}", info.timesJoined);
            Log.info("  &lytimes kicked: {0}", info.timesKicked);
            Log.info("");
            Log.info("  &lytotal blocks broken: {0}", info.totalBlocksBroken);
            Log.info("  &lytotal blocks placed: {0}", info.totalBlockPlaced);
        } else {
            info("Nobody with that UUID could be found.");
        }
    });
    handler.register("trace", "<username...>", "Trace a player's actions", arg -> {
        if (!state.is(State.playing)) {
            err("Open the server first.");
            return;
        }
        Player target = null;
        for (Player player : playerGroup.all()) {
            if (player.name.equalsIgnoreCase(arg[0])) {
                target = player;
                break;
            }
        }
        if (target != null) {
            TraceInfo info = netServer.admins.getTrace(Net.getConnection(target.clientid).address);
            Log.info("&lcTrace info for player '{0}':", target.name);
            Log.info("  &lyEntity ID: {0}", info.playerid);
            Log.info("  &lyIP: {0}", info.ip);
            Log.info("  &lyUUID: {0}", info.uuid);
            Log.info("  &lycustom client: {0}", info.modclient);
            Log.info("  &lyandroid: {0}", info.android);
            Log.info("");
            Log.info("  &lytotal blocks broken: {0}", info.totalBlocksBroken);
            Log.info("  &lystructure blocks broken: {0}", info.structureBlocksBroken);
            Log.info("  &lylast block broken: {0}", info.lastBlockBroken.formalName);
            Log.info("");
            Log.info("  &lytotal blocks placed: {0}", info.totalBlocksPlaced);
            Log.info("  &lylast block placed: {0}", info.lastBlockPlaced.formalName);
        } else {
            info("Nobody with that name could be found.");
        }
    });
}
Also used : Player(io.anuke.mindustry.entities.Player) Difficulty(io.anuke.mindustry.game.Difficulty) Tile(io.anuke.mindustry.world.Tile) TraceInfo(io.anuke.mindustry.net.TraceInfo) IOException(java.io.IOException) GameMode(io.anuke.mindustry.game.GameMode) Command(io.anuke.ucore.util.CommandHandler.Command) PlayerInfo(io.anuke.mindustry.net.Administration.PlayerInfo) Map(io.anuke.mindustry.world.Map)

Aggregations

Difficulty (io.anuke.mindustry.game.Difficulty)2 GameMode (io.anuke.mindustry.game.GameMode)2 Map (io.anuke.mindustry.world.Map)2 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Vars (io.anuke.mindustry.Vars)1 Player (io.anuke.mindustry.entities.Player)1 PlayerInfo (io.anuke.mindustry.net.Administration.PlayerInfo)1 TraceInfo (io.anuke.mindustry.net.TraceInfo)1 Tile (io.anuke.mindustry.world.Tile)1 Core (io.anuke.ucore.core.Core)1 Settings (io.anuke.ucore.core.Settings)1 Timers (io.anuke.ucore.core.Timers)1 ClickListener (io.anuke.ucore.scene.event.ClickListener)1 InputEvent (io.anuke.ucore.scene.event.InputEvent)1 Touchable (io.anuke.ucore.scene.event.Touchable)1 io.anuke.ucore.scene.ui (io.anuke.ucore.scene.ui)1 Stack (io.anuke.ucore.scene.ui.layout.Stack)1 Table (io.anuke.ucore.scene.ui.layout.Table)1 Elements (io.anuke.ucore.scene.utils.Elements)1