Search in sources :

Example 1 with GameController

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

the class EnhanceCommand method execute.

@Override
protected void execute(CommandEvent event) {
    // Check if they just want the list
    if (event.getArgs().equalsIgnoreCase("list")) {
        sendEnhanceList(event);
        return;
    }
    // Next check if they've picked a game to enhance
    String gameName = event.getArgs();
    // Run through the list of games to find the one they asked for
    for (Game game : Game.values()) {
        if (gameName.equalsIgnoreCase(game.getShortName()) || gameName.equalsIgnoreCase(game.getName())) {
            enhanceGame(event, game);
            return;
        }
    }
    // If they don't seem to be enhancing a minigame, just send them their status
    // Start by checking to see if they're in-game, and read from their player-file instead
    Player player = null;
    // Find the channel
    GameController controller = null;
    for (GameController next : RaceToABillionBot.game) if (next.channel.equals(event.getChannel())) {
        controller = next;
        break;
    }
    if (controller == null) {
        event.reply("This command must be used in a game channel.");
        return;
    }
    for (Player next : controller.players) if (next.uID.equals(event.getAuthor().getId())) {
        player = next;
        break;
    }
    // If they aren't in-game, get their data by generating their player object
    if (player == null) {
        player = new Player(event.getMember(), controller, null);
    }
    // Now let's start building up the reply message
    StringBuilder output = new StringBuilder();
    // List their enhance slot status
    output.append("```\n" + player.getName() + "'s Enhanced Minigames:\n");
    boolean emptySlots = false;
    for (int i = 0; i < player.getEnhanceCap(); i++) {
        if (i < player.enhancedGames.size()) {
            output.append(" (*) ");
            output.append(player.enhancedGames.get(i).getName());
        } else {
            output.append(" ( ) Empty Slot");
            emptySlots = true;
        }
        output.append("\n");
    }
    int livesToNewSlot = (25 * (player.getEnhanceCap() + 1) * (player.getEnhanceCap() + 2) / 2) - player.totalLivesSpent;
    if (player.newbieProtection > 0)
        output.append("     (Finish your newbie protection, then use " + livesToNewSlot + " lives to open a new slot)\n\n");
    else
        output.append("     (Use " + livesToNewSlot + " more lives to open a new slot)\n\n");
    output.append("Type '!enhance list' to see the list of available enhancements.\n");
    if (emptySlots)
        output.append("Type '!enhance' followed by a minigame's name to permanently enhance that minigame.\n");
    output.append("```");
    event.reply(output.toString());
}
Also used : Player(tel.discord.rtab.Player) Game(tel.discord.rtab.board.Game) GameController(tel.discord.rtab.GameController)

Example 2 with GameController

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

the class EnhanceCommand method enhanceGame.

void enhanceGame(CommandEvent event, Game game) {
    // First of all, is the game actually in this season?
    if (game.getWeight(4) <= 0) {
        event.reply("That minigame is not available this season.");
        return;
    }
    // Find the channel
    GameController controller = null;
    for (GameController next : RaceToABillionBot.game) if (next.channel.equals(event.getChannel())) {
        controller = next;
        break;
    }
    if (controller == null) {
        event.reply("This command must be used in a game channel.");
        return;
    }
    // Check that they're in game currently, or that there's no game running
    if (controller.players.size() <= 0) {
        // If there's no game running, find them in the savefile
        try {
            List<String> list = Files.readAllLines(Paths.get("scores", "scores" + event.getChannel().getId() + ".csv"));
            int index = findUserInList(list, event.getAuthor().getId(), false);
            if (index < 0 || index >= list.size()) {
                event.reply("You currently have no open enhance slots.");
                return;
            }
            String[] record = list.get(index).split("#");
            /*
				 * record[11] = total lives spent
				 * record[12] = list of enhanced minigames
				 * (this is copied directly from the player initialisation file)
				 */
            int totalLivesSpent = Integer.parseInt(record[11]);
            ArrayList<Game> enhancedGames = new ArrayList<Game>();
            // Remove the brackets
            String savedEnhancedGames = record[12].substring(1, record[12].length() - 1);
            String[] enhancedList = savedEnhancedGames.split(",");
            if (enhancedList[0].length() > 0)
                for (int j = 0; j < enhancedList.length; j++) enhancedGames.add(Game.valueOf(enhancedList[j].trim()));
            // Do the obvious checks
            if (RtaBMath.getEnhanceCap(totalLivesSpent) <= enhancedGames.size()) {
                event.reply("You currently have no open enhance slots.");
                return;
            }
            for (Game nextGame : enhancedGames) {
                if (game == nextGame) {
                    event.reply("You have already enhanced that minigame.");
                    return;
                }
            }
            // Enhance it!
            enhancedGames.add(game);
            event.reply("Minigame enhanced!");
            // Now replace the record in the list
            StringBuilder updatedLine = new StringBuilder();
            for (int i = 0; i < 11; i++) {
                updatedLine.append(record[i]);
                updatedLine.append("#");
            }
            updatedLine.append(totalLivesSpent);
            updatedLine.append("#");
            updatedLine.append(enhancedGames.toString());
            list.set(index, updatedLine.toString());
            // And save it
            Path file = Paths.get("scores", "scores" + event.getChannel().getId() + ".csv");
            Path oldFile = Files.move(file, file.resolveSibling("scores" + event.getChannel().getId() + "old.csv"));
            Files.write(file, list);
            Files.delete(oldFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return;
    }
    boolean playerFound = false;
    for (Player next : controller.players) if (next.uID.equals(event.getAuthor().getId())) {
        playerFound = true;
        if (next.getEnhanceCap() <= next.enhancedGames.size()) {
            event.reply("You currently have no open enhance slots.");
            return;
        }
        for (Game nextGame : next.enhancedGames) {
            if (game == nextGame) {
                event.reply("You have already enhanced that minigame.");
                return;
            }
        }
        // Yay they actually met all the conditions was that so hard
        next.enhancedGames.add(game);
        event.reply("Minigame enhanced!");
    }
    if (!playerFound) {
        event.reply("There is a game currently in progress; please wait until it is finished to enhance.");
        return;
    }
}
Also used : Path(java.nio.file.Path) Player(tel.discord.rtab.Player) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Game(tel.discord.rtab.board.Game) GameController(tel.discord.rtab.GameController)

Example 3 with GameController

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

the class LivesCommand method execute.

@Override
protected void execute(CommandEvent event) {
    for (GameController game : RaceToABillionBot.game) {
        if (game.channel.equals(event.getChannel())) {
            if (game.lifePenalty == LifePenaltyType.NONE) {
                event.reply("You have unlimited lives in this channel.");
                return;
            }
            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);
                }
                // Then pass off to the actual controller if they're an actual user
                if (index < 0 || index >= list.size())
                    event.reply("User not found.");
                else
                    event.reply(checkLives(game, index));
            } catch (IOException e) {
                e.printStackTrace();
            }
            // We found the right channel, so
            return;
        }
    }
}
Also used : GameController(tel.discord.rtab.GameController) IOException(java.io.IOException)

Example 4 with GameController

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

the class BonusCommand method execute.

@Override
protected void execute(CommandEvent event) {
    for (GameController game : RaceToABillionBot.game) {
        if (game.channel.equals(event.getChannel())) {
            SpaceType desire;
            switch(event.getArgs().toUpperCase()) {
                case "CASH":
                case "C":
                case "MONEY":
                case "M":
                    desire = SpaceType.CASH;
                    break;
                case "BOOST":
                case "BOOSTER":
                case "B":
                    desire = SpaceType.BOOSTER;
                    break;
                case "MINIGAME":
                case "GAME":
                case "G":
                    desire = SpaceType.GAME;
                    break;
                case "EVENT":
                case "E":
                case "SPLIT AND SHARE":
                    desire = SpaceType.EVENT;
                    break;
                case "BOMB":
                    event.reply("Well, if you say so.");
                case "GRAB BAG":
                case "BILLION":
                case "ONE BILLION DOLLARS":
                case "A BILLION DOLLARS":
                case "A BILLION":
                case "AMULET OF YENDOR":
                case "THE AMULET OF YENDOR":
                    // greedy
                    desire = SpaceType.BOMB;
                    break;
                // Useless memes follow
                case "BLAMMO":
                    if (Math.random() < 0.5)
                        event.reply("Does this look like !blammo to you?");
                    else
                        event.reply("There are no blammos in the bonus bag.");
                    return;
                case "NUMBERWANG":
                case "NEGATIVE BILLION":
                case "A NEGATIVE BILLION":
                    event.reply("You found **Numberwang**, worth shinty-six. Your score is unaffected.");
                    return;
                case "TRIFORCE":
                    event.reply("You found **The Triforce**! " + "Click here to claim your prize: <https://www.youtube.com/watch?v=dQw4w9WgXcQ>");
                    return;
                case "MEME":
                    event.reply("https://niceme.me");
                    return;
                case "HIDDEN":
                case "HIDDEN COMMAND":
                case "A HIDDEN COMMAND":
                    event.reply("If you're using this command, you already have one.");
                    return;
                case "BLESSED FIXED GREASED +2 GRAY DRAGON SCALE MAIL":
                case "BLESSED FIXED GREASED +2 GREY DRAGON SCALE MAIL":
                case "BLESSED FIXED GREASED +2 SILVER DRAGON SCALE MAIL":
                    event.reply("Unfortunately, nothing happens. (It's the bonus bag, not a wand of wishing)");
                    return;
                default:
                    event.reply("Use !bonus cash, !bonus boost, !bonus game, or !bonus event to specify what you want.");
                    return;
            }
            int player = game.findPlayerInGame(event.getAuthor().getId());
            // it's their turn, and they haven't picked a space) (this is getting a little silly)
            if (game.gameStatus != GameStatus.IN_PROGRESS || player != game.currentTurn || game.resolvingTurn || game.currentBlammo || game.players.get(player).status != PlayerStatus.ALIVE || game.players.get(player).hiddenCommand != HiddenCommand.BONUS)
                event.reply("You can't do this right now.");
            else
                game.useBonusBag(player, desire);
            return;
        }
    }
    // We aren't in a game channel? Uh...
    event.reply("This is not a game channel.");
}
Also used : SpaceType(tel.discord.rtab.board.SpaceType) GameController(tel.discord.rtab.GameController)

Example 5 with GameController

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

the class SkipCommand method execute.

@Override
protected void execute(CommandEvent event) {
    for (GameController game : RaceToABillionBot.game) {
        if (game.channel.equals(event.getChannel())) {
            // Check that there's a minigame and that the current player is the minigame's owner
            if (game.currentGame == null)
                return;
            int player = game.findPlayerInGame(event.getAuthor().getId());
            if (player != game.currentTurn)
                return;
            // Cool, tell the game to skip and let it handle that
            game.currentGame.skipMessages();
            // 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)

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