Search in sources :

Example 6 with GameController

use of tel.discord.rtab.GameController in project RtaB6 by Telnaior.

the class AnnuitiesCommand method execute.

@Override
protected void execute(CommandEvent event) {
    for (GameController game : RaceToABillionBot.game) {
        if (game.channel.equals(event.getChannel())) {
            try {
                List<String> list = Files.readAllLines(Paths.get("scores", "scores" + event.getChannel().getId() + ".csv"));
                // If no name given, check it for themselves
                int index;
                if (event.getArgs() == "")
                    index = findUserInList(list, event.getAuthor().getId(), false);
                else // If it's a mention, search by the id of the mention
                if (event.getArgs().startsWith("<@!")) {
                    String mentionID = parseMention(event.getArgs());
                    index = findUserInList(list, mentionID, false);
                } else // Otherwise check it for the player named
                {
                    index = findUserInList(list, event.getArgs(), true);
                }
                // Tell them they're not real if they aren't
                if (index < 0 || index >= list.size())
                    event.reply("User not found.");
                else {
                    // Parse the array the same way we do when joining a game
                    String[] record = list.get(index).split("#");
                    String savedAnnuities = record[10];
                    savedAnnuities = savedAnnuities.replaceAll("[^\\d,-]", "");
                    String[] annuityList = savedAnnuities.split(",");
                    LinkedList<MutablePair<Integer, Integer>> annuities = new LinkedList<>();
                    for (int j = 1; j < annuityList.length; j += 2) annuities.add(MutablePair.of(Integer.parseInt(annuityList[j - 1]), Integer.parseInt(annuityList[j])));
                    // Start building our response
                    StringBuilder output = new StringBuilder().append("```\n" + record[1] + "'s Annuities:\n");
                    if (annuities.size() == 0) {
                        output.append("You have no annuities.\n");
                    } else {
                        // Run through the iterator and tally up the payments
                        ListIterator<MutablePair<Integer, Integer>> iterator = annuities.listIterator();
                        while (iterator.hasNext()) {
                            MutablePair<Integer, Integer> nextAnnuity = iterator.next();
                            output.append(String.format("$%,d: ", nextAnnuity.getLeft()));
                            if (nextAnnuity.getRight() == -1)
                                output.append("For the Rest of the Season\n");
                            else
                                output.append(String.format("%d spaces\n", nextAnnuity.getRight()));
                        }
                    }
                    output.append("```");
                    event.reply(output.toString());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            // We found the right channel, so
            return;
        }
    }
}
Also used : IOException(java.io.IOException) LinkedList(java.util.LinkedList) MutablePair(net.dv8tion.jda.internal.utils.tuple.MutablePair) GameController(tel.discord.rtab.GameController)

Example 7 with GameController

use of tel.discord.rtab.GameController in project RtaB6 by Telnaior.

the class TruesightCommand method execute.

@Override
protected void execute(CommandEvent event) {
    for (GameController game : RaceToABillionBot.game) {
        if (game.channel.equals(event.getChannel())) {
            int player = game.findPlayerInGame(event.getAuthor().getId());
            String rawSpace = event.getArgs();
            // Check that it's valid (the game is running, the space is legit, they're alive, and they have the command)
            if (game.gameStatus != GameStatus.IN_PROGRESS || player == -1 || !game.checkValidNumber(rawSpace) || game.players.get(player).status != PlayerStatus.ALIVE || game.players.get(player).hiddenCommand != HiddenCommand.TRUESIGHT)
                event.reply("You can't do this right now.");
            else // Cool, we're good, pass it over
            {
                int space = Integer.parseInt(rawSpace) - 1;
                if (game.pickedSpaces[space])
                    event.reply("That space has already been picked.");
                else
                    game.useTruesight(player, space);
            }
            return;
        }
    }
    // We aren't in a game channel? Uh...
    event.reply("This is not a game channel.");
}
Also used : GameController(tel.discord.rtab.GameController)

Example 8 with GameController

use of tel.discord.rtab.GameController in project RtaB6 by Telnaior.

the class NextCommand method execute.

@Override
protected void execute(CommandEvent event) {
    for (GameController game : RaceToABillionBot.game) {
        if (game.channel.equals(event.getChannel())) {
            if (game.gameStatus != GameStatus.SIGNUPS_OPEN || (!game.playersCanJoin && game.players.size() == 0)) {
                game.pingList.add(event.getAuthor().getAsMention());
                event.reply(String.format("Noted - will ping you when you can %s.", game.playersCanJoin ? "play" : "bet"));
            } else {
                if (game.playersCanJoin)
                    event.reply("You can join already!");
                else {
                    event.reply("You can bet already!");
                    game.listPlayers(false);
                }
            }
            // We found the right channel, so
            return;
        }
    }
}
Also used : GameController(tel.discord.rtab.GameController)

Example 9 with GameController

use of tel.discord.rtab.GameController in project RtaB6 by Telnaior.

the class PeekCommand method execute.

@Override
protected void execute(CommandEvent event) {
    for (GameController game : RaceToABillionBot.game) {
        if (game.channel.equals(event.getChannel())) {
            int player = game.findPlayerInGame(event.getAuthor().getId());
            // Make sure they're in the game, the game is running, and they actually have a peek
            if (game.gameStatus != GameStatus.IN_PROGRESS || player == -1 || game.players.get(player).peeks < 1) {
                event.reply("You don't have a peek to use.");
                return;
            }
            // Make sure they're peeking a space that's on the board
            try {
                int location = Integer.parseInt(event.getArgs()) - 1;
                if (location < 0 || location >= game.boardSize || game.pickedSpaces[location]) {
                    event.reply("That is not a valid space.");
                    return;
                }
                // We checked everything, pass it on to the game to actually peek it
                game.usePeek(player, location);
            } catch (NumberFormatException e) {
                event.reply("That is not a valid space.");
                return;
            }
            // We found the right channel, so
            return;
        }
    }
    // We aren't in a game channel? Uh...
    event.reply("This is not a game channel.");
}
Also used : GameController(tel.discord.rtab.GameController)

Example 10 with GameController

use of tel.discord.rtab.GameController in project RtaB6 by Telnaior.

the class DefuseCommand method execute.

@Override
protected void execute(CommandEvent event) {
    for (GameController game : RaceToABillionBot.game) {
        if (game.channel.equals(event.getChannel())) {
            int player = game.findPlayerInGame(event.getAuthor().getId());
            String rawSpace = event.getArgs();
            // Check that it's valid (the game is running, the space is legit, they're alive, and they have the command)
            if (game.gameStatus != GameStatus.IN_PROGRESS || player == -1 || !game.checkValidNumber(rawSpace) || game.players.get(player).status != PlayerStatus.ALIVE || game.players.get(player).hiddenCommand != HiddenCommand.DEFUSE)
                event.reply("You can't do this right now.");
            else // Cool, we're good, pass it over
            {
                int space = Integer.parseInt(rawSpace) - 1;
                if (game.pickedSpaces[space])
                    event.reply("That space has already been picked.");
                else
                    game.useShuffler(player, space);
            }
            return;
        }
    }
    // We aren't in a game channel? Uh...
    event.reply("This is not a game channel.");
}
Also used : GameController(tel.discord.rtab.GameController)

Aggregations

GameController (tel.discord.rtab.GameController)14 Player (tel.discord.rtab.Player)4 IOException (java.io.IOException)3 Game (tel.discord.rtab.board.Game)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 MutablePair (net.dv8tion.jda.internal.utils.tuple.MutablePair)1 SpaceType (tel.discord.rtab.board.SpaceType)1