Announcement

Collapse
No announcement yet.

Code for !fruit

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code for !fruit

    Here's the current code for !fruit, in case anyone is curious. I thought it might be worth putting out there, since many people over the years have claimed it's somehow rigged. Not the easiest for a non-programmer to read, but it's also not that difficult or long.

    Easier to read format: https://hastebin.com/gugazalefe.java

    Pasted:

    Code:
        
        /**        Handles the !fruit command. (Anyone)
            <p>
            Pulls the handle of the one-armed bandit (aka fruit machine)
            in an ill-fated attempt to earn more money.
            @param sender Sender of the command.
            @param command Amount to throw away
        */
        String doCmdFruit(String sender, String command, boolean nonCommandPlay) {
            int bet = 0;
            int iterations = 1;
            int winnings = 0;
    
    
            if (!nonCommandPlay && context.getPubChallenge().isDueling(sender)) {
                m_botAction.sendSmartPrivateMessage(sender, "You cannot gamble while duelling.");
                return "ERROR";
            }
    
    
            if (command.contains(":")) {
                String[] parsed = command.split(":");
    
    
                if (parsed.length != 2) {
                    m_botAction.sendPrivateMessage(sender, "Format:  !fruit 10:5  (Bet 10 x5 times) or !fruit 50  (Bet 50)");
                    return "ERROR";
                }
    
    
                try {
                    bet = Integer.parseInt(parsed[0]);
                    iterations = Integer.parseInt(parsed[1]);
                } catch(Exception e) {
                    m_botAction.sendPrivateMessage(sender, "Format:  !fruit 10:5  (Bet 10 x5 times) or !fruit 50  (Bet 50)");
                    return "ERROR";
                }
            } else {
                try {
                    bet = Integer.parseInt(command);
                } catch(Exception e) {
                    m_botAction.sendPrivateMessage(sender, "Provide a # to use the fruit machine (between 10 and 1500). E.g., !fruit 50, or !fruit 50:5 to play 5 times for 50.");
                    return "ERROR";
                }
            }
    
    
            if (bet < 10 || bet > 1500) {
                m_botAction.sendPrivateMessage(sender, "Provide an amount between 10 and 1500. (To bet larger amounts, use !fruit amt:times, e.g., !fruit 100:10 to bet 100 for 10 total pulls of the fruit machine)");
                return "ERROR";
            }
    
    
            if (iterations > 10 || iterations < 1) {
                m_botAction.sendPrivateMessage(sender, "Bot only accepts 10 bets at a time maximum (and, of course, 1 minimum).");
                return "ERROR";
            }
    
    
            PubPlayer pp = playerManager.getPlayer(sender, false);
    
    
            if (pp == null ) {
                m_botAction.sendPrivateMessage(sender, "Can't locate you. Try entering pub.");
                return "ERROR";
            }
    
    
            if (!nonCommandPlay && pp.getMoney() < (bet * iterations)) {
                m_botAction.sendSmartPrivateMessage(sender, "You don't have $" + bet + " to bet.");
                return "ERROR";
            }
    
    
            for (int j = 0; j < iterations; j++) {
                Random r = new Random();
                int[] slots = new int[3];
    
    
                for (int i = 0; i < 3; i++)
                    slots[i] = r.nextInt(10);
    
    
                int winFactor = 0;
                String winMsg = "";
    
    
                if (slots[0] == slots[1] && slots[1] == slots[2]) {
                    switch (slots[0]) {
                    case 0:
                        winFactor = 5;
                        winMsg = "YOU'RE BEING WATCHED JACKPOT!";
                        break;
    
    
                    case 1:
                        winFactor = 20;
                        winMsg = "> WARBIRD JACKPOT! <";
                        break;
    
    
                    case 2:
                        winFactor = 75;
                        winMsg = ">>>> !!! JAVELIN JACKPOT !!! <<<";
                        break;
    
    
                    case 3:
                        winFactor = 45;
                        winMsg = ">> SPIDER JACKPOT!! <<";
                        break;
    
    
                    case 4:
                        winFactor = 200;
                        winMsg = ">>>>>>>>> !!!! OMGOMGOMG .. YES!! LEVIATHAN JACKPOT !!!!! <<<<<<<<";
                        break;
    
    
                    case 5:
                        winFactor = 60;
                        winMsg = ">>> !!!TERRIER JACKPOT!!! <<<";
                        break;
    
    
                    case 6:
                        winFactor = 10;
                        winMsg = "WEASEL JACKPOT!!";
                        break;
    
    
                    case 7:
                        winFactor = 30;
                        winMsg = ">> LANCASTER JACKPOT!! <<";
                        break;
    
    
                    case 8:
                        winFactor = 15;
                        winMsg = "SHARK JACKPOT!";
                        break;
    
    
                    case 9:
                        winFactor = 100;
                        winMsg = ">>>>>>> !!!! YEAHHHHHH!! NIGHTWASP JACKPOT !!!! <<<<<<";
                        break;
                    }
                } else {
                    int[] hits = new int[10];
    
    
                    for (int i = 0; i < 10; i++) {
                        for (int y = 0; y < 3; y++)
                            if (slots[y] == i)
                                hits[i]++;
                    }
    
    
                    if (hits[1] == 1 && hits[3] == 1 && hits[7] == 1) {
                        winFactor = 5;
                        winMsg = "All Fighter Matchup!";
                    } else if (hits[3] + hits[7] == 3) {
                        winFactor = 3;
                        winMsg = "Basefighter Matchup!";
                    } else if (hits[5] == 1 && hits[3] == 1 && hits[8] == 1) {
                        winFactor = 7;
                        winMsg = "Basing Team Matchup!";
                    } else if (hits[5] == 1 && hits[7] == 1 && hits[8] == 1) {
                        winFactor = 6;
                        winMsg = "Alt. Basing Matchup!";
                    } else if (hits[2] == 1 && hits[4] == 1 && hits[9] == 1) {
                        winFactor = 5;
                        winMsg = "Bombing Run Matchup!";
                    } else if (hits[4] == 1 && hits[6] == 1 && hits[8] == 1) {
                        winFactor = 4;
                        winMsg = "Sneaky Team Matchup!";
                    } else if (hits[4] == 2 && hits[5] == 1 ) {
                        winFactor = 3;
                        winMsg = "Double LeviTerr Matchup!";
                    } else if (hits[4] == 1 && hits[5] >= 1 ) {
                        winFactor = 2;
                        winMsg = "LeviTerr Matchup!";
                    } else if (hits[5] >= 1) {
                        // Each Terr has a 25% chance of giving a free play
                        for (int k = 0; k < hits[5]; k++)
                            if (r.nextInt(4) == 0)
                                winFactor = 1;
                    }
                }
    
    
                String rollmsg =
                    "[" + Tools.centerString( getShipNameSpecial(slots[0]), 8 ).toUpperCase() + "]   " +
                    "[" + Tools.centerString( getShipNameSpecial(slots[1]), 8 ).toUpperCase() + "]   " +
                    "[" + Tools.centerString( getShipNameSpecial(slots[2]), 8 ).toUpperCase() + "]   ";
    
    
                if (winFactor > 0) {
                    if (winFactor > 1) {
                        if (winFactor >= 5) {
                            Player p = m_botAction.getPlayer( pp.getPlayerName() );
    
    
                            if (p != null &&
                                    p.getShipType() != Tools.Ship.SPECTATOR &&
                                    ( pp.getLastDeath() + (Tools.TimeInMillis.MINUTE * 1) > System.currentTimeMillis() )) {
                                winFactor++;
                            }
                        }
    
    
                        rollmsg += " $$ " + (bet * winFactor) + " $$";
                        //
                        //[  SPID  ]   [  SPID  ]   [  LANC  ]
                        m_botAction.sendPrivateMessage(sender,
                                                       Tools.centerString( "WIN!  " + winMsg + "  WIN!", 50 ),
                                                       Tools.Sound.VICTORY_BELL );
                        winnings += ((bet * winFactor) - bet);
                        fruitStats[0] += ((bet * winFactor) - bet);
                    } else {
                        if (!nonCommandPlay)
                            rollmsg += "(free play)";
                        //m_botAction.sendPrivateMessage(sender, "A Terr has ported you to safety; you keep your bet." );
                    }
                } else {
                    rollmsg += "(no win)";
                    if (!nonCommandPlay) {
                        winnings -= bet;
                        fruitStats[1] += bet;
                    }
                }
    
    
                if (nonCommandPlay) {
                    if (winnings > 0)
                        pp.setMoney( pp.getMoney() + winnings );
                    return rollmsg;         // Non-!fruit plays are single plays only
                }
                m_botAction.sendPrivateMessage(sender, rollmsg);
            }
            
            pp.setMoney( pp.getMoney() + winnings );
            return "";
        }
    "You're a gentleman," they used to say to him. "You shouldn't have gone murdering people with a hatchet; that's no occupation for a gentleman."
    -Dostoevsky's Crime and Punishment

  • #2
    Thanks for posting this code qan.
    Last edited by Renzo; 12-06-2023, 04:02 PM.

    Comment

    Working...
    X