Paste #46669: Roast me

Date: 2018/02/14 10:37:02 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


Dice_Assignment:
  type: assignment
  debug: false
  actions:
    on assignment:
      - trigger name:click state:true
      - trigger name:proximity state:true radius:3
    on click:
      - run Dice_PlayGame instantly
    on enter proximity:
      - narrate "<&6>Welcome! Come try your luck at Dice Poker! <&b>$100<&6> buy-in!"
      - narrate "<&e>Roll the dice for the best combination, you get <&b>2<&e> chances to hold and improve your result!"
      - run Dice_ResetFlags instantly
########################################Main Gameplay Section####################################
#        Define which stage of the game the player is in by their 'phase'.                      #
#        Which phase you are in determines how many more times you can hold/reroll the dice.    #
#    Each phase assumes that the dice desired have been held already, and instantly rolls.      #
#  Phase 1 and 2 only check for Jackpot because We assume no one wants to troll themselves and  #
#    reroll that. Anything else might want to be rerolled for a better shot at the Jackpot.     #
#    If they win, end the game. Check if the game isn't over before giving an option to reroll. #
#    Indicate that they are moving on to the next reroll, and give them a chance to hold.       #
#  The roll, jackpotcheck, phase-assignment could probably be compartmentalized, but I'm lazy.  #
# If they are in phase 3 and haven't hit Jackpot, check the others. The others require the hand #
#  to be sorted first, but that's ok since the player won't be holding anymore, won't see them. #
#  Finally, if the phase is undefined or invalid, try to start the game anew. Reset and Restart.#
#################################################################################################
Dice_PlayGame:
  type: task
  debug: false
  script:
    - if <player.flag[dice_phase]||0> == 1 {
      - run Dice_Roll_Hand instantly
      - if <proc[Dice_CheckFive]> {
        - run Dice_Payout def:<global.flag[FivePay]>
        - narrate "JACKPOT! 5 in a row!"
        - run Dice_ResetFlags instantly
      }
      - if <player.flag[dice_phase]||0> == 1 {
        - flag player dice_phase:2
        - inventory open d:in@Dice_Hand_Inventory
      }
    } else if <player.flag[dice_phase]||0> == 2 {
      - run Dice_Roll_Hand instantly
      - if <proc[Dice_CheckFive]> {
        - run Dice_Payout def:<global.flag[FivePay]>
        - narrate "JACKPOT! 5 in a row!"
        - run Dice_ResetFlags instantly
      }
      - if <player.flag[dice_phase]||0> == 2 {
        - flag player dice_phase:3
        - inventory open d:in@Dice_Hand_Inventory
      }
    } else if <player.flag[dice_phase]||0> == 3 {
      - run Dice_Roll_Hand instantly
      - narrate "<&2>You have <&e><player.flag[dice_hand].comma_separated> in hand!"
      - run Dice_SortHand instantly
      - flag global DiceGames:+:1
      - if <proc[Dice_CheckFive]> {
        - narrate "<&5>JACKPOT! <&d>5 <&4>in <&b>a <&a>row!"
        - run Dice_Payout def:<global.flag[FivePay]>
        - flag global FiveWins:+:1
      } else if <proc[Dice_CheckFour]> {
        - narrate "<&c>Got 4 of a Kind!"
        - run Dice_Payout def:<global.flag[FourPay]>
        - flag global FourWins:+:1
      } else if <proc[Dice_CheckFullHouse]> {
        - narrate "<&e>Got a Full House!"
        - run Dice_Payout def:<global.flag[FullHousePay]>
        - flag global FullWins:+:1
      } else if <proc[Dice_CheckThree]> {
        - narrate "<&a>Got 3 of a Kind!"
        - run Dice_Payout def:<global.flag[ThreePay]>
        - flag global ThreeWins:+:1
      } else if <proc[Dice_CheckStraight]> {
        - narrate "<&b>Got a Straight!"
        - run Dice_Payout def:<global.flag[StraightPay]>
        - flag global StraightWins:+:1
      } else {
        - narrate "<&6>Better Luck Next Time!"
      }
      - narrate "<global.flag[DiceGames].as_int> ever. <global.flag[FiveWins].as_int> 5s hit. <global.flag[FourWins].as_int> 4s hit. <global.flag[ThreeWins].as_int> 3s hit. <global.flag[FullWins].as_int> FH hit. <global.flag[StraightWins].as_int> Str8s hit."
      - run Dice_ResetFlags instantly
    } else {
      - run Dice_ResetFlags instantly
      - if <player.money> >= <global.flag[dice_cost]> {
        - money take quantity:<global.flag[dice_cost]>
        - run Dice_Initialize instantly
        - run Dice_PlayGame instantly
      } else {
        - narrate "<&c>You don't have that much? Get out of here, vagrant."
      }
    }
#####################################Inventory Management Section################################
#                   Inv has 5 dice and a Continue/Done button. Dice are Emerald_Ore or          #
#                         Redstone_Ore to indicate if they are held or not.                     #
#    Placement of Dice in Inv View is based on the mouse getting centered each time it opens.   #
#################################################################################################
Dice_One:
  type: item
  material: <player.flag[dice_held].get[1]>
  display name: <&6><player.flag[dice_hand].get[1]>
  lore:
    - "Your first die"
    - "Click to HOLD"
    - "Red means REROLL"
Dice_Two:
  type: item
  material: <player.flag[dice_held].get[2]>
  display name: <&6><player.flag[dice_hand].get[2]>
  lore:
    - "Your first die"
    - "Click to HOLD"
    - "Red means REROLL"
Dice_Three:
  type: item
  material: <player.flag[dice_held].get[3]>
  display name: <&6><player.flag[dice_hand].get[3]>
  lore:
    - "Your first die"
    - "Click to HOLD"
    - "Red means REROLL"
Dice_Four:
  type: item
  material: <player.flag[dice_held].get[4]>
  display name: <&6><player.flag[dice_hand].get[4]>
  lore:
    - "Your first die"
    - "Click to HOLD"
    - "Red means REROLL"
Dice_Five:
  type: item
  material: <player.flag[dice_held].get[5]>
  display name: <&6><player.flag[dice_hand].get[5]>
  lore:
    - "Your first die"
    - "Click to HOLD"
    - "Red means REROLL"
Dice_Done:
  type: item
  material: GOLD_BLOCK
  display name: <&6><player.flag[dice_hand].get[5]>
  lore:
    - "Click to REROLL!"

Dice_Hand_Inventory_Listener:
  type: world
  debug: false
  events:
    on player clicks in Dice_Hand_Inventory:
      - determine cancelled
    on player drags in Dice_Hand_Inventory:
      - determine cancelled
    on player clicks Dice_One in Dice_Hand_Inventory:
      - if <player.flag[dice_held].get[1]> == REDSTONE_ORE {
        - flag player dice_held[1]:EMERALD_ORE
      } else {
        - flag player dice_held[1]:REDSTONE_ORE
      }
      - inventory open d:in@Dice_Hand_Inventory
    on player clicks Dice_Two in Dice_Hand_Inventory:
      - if <player.flag[dice_held].get[2]> == REDSTONE_ORE {
        - flag player dice_held[2]:EMERALD_ORE
      } else {
        - flag player dice_held[2]:REDSTONE_ORE
      }
      - inventory open d:in@Dice_Hand_Inventory
    on player clicks Dice_Three in Dice_Hand_Inventory:
      - if <player.flag[dice_held].get[3]> == REDSTONE_ORE {
        - flag player dice_held[3]:EMERALD_ORE
      } else {
        - flag player dice_held[3]:REDSTONE_ORE
      }
      - inventory open d:in@Dice_Hand_Inventory
    on player clicks Dice_Four in Dice_Hand_Inventory:
      - if <player.flag[dice_held].get[4]> == REDSTONE_ORE {
        - flag player dice_held[4]:EMERALD_ORE
      } else {
        - flag player dice_held[4]:REDSTONE_ORE
      }
      - inventory open d:in@Dice_Hand_Inventory
    on player clicks Dice_Five in Dice_Hand_Inventory:
      - if <player.flag[dice_held].get[5]> == REDSTONE_ORE {
        - flag player dice_held[5]:EMERALD_ORE
      } else {
        - flag player dice_held[5]:REDSTONE_ORE
      }
      - inventory open d:in@Dice_Hand_Inventory
    on player clicks Dice_Done in Dice_Hand_Inventory:
      - inventory close
      - run Dice_PlayGame instantly

Dice_Hand_Inventory:
  type: inventory
  title: ""
  size: 27
  slots:
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [] [] [] [] [] [] []"
    - "[] [] [i@Dice_One[quantity=<player.flag[dice_hand].get[1].as_int>]] [i@Dice_Two[quantity=<player.flag[dice_hand].get[2].as_int>]] [i@Dice_Three[quantity=<player.flag[dice_hand].get[3].as_int>]] [i@Dice_Four[quantity=<player.flag[dice_hand].get[4].as_int>]] [i@Dice_Five[quantity=<player.flag[dice_hand].get[5].as_int>]] [] [i@Dice_Done]"
#####################################Utility Functions/Tasks#####################################
#        Roll_Hand only randomizes dice that do not have Emerald_Ore in the parallel List       #
#        SortHand is only used before the final win check, so Held dice don't matter            #
#        Payout takes an integer as a parameter, and gives the player money in that amount      #
#        Initialize sets all flags needed for the player to play the game correctly.            #
#        ResetFlags makes everything blank, as if the player intends to walk away.              #
#              It also serves as a convenient spot to store global variables (flags)            #
#################################################################################################
Dice_Roll_Hand:
  type: task
  debug: false
  script:
    - foreach <li@1|2|3|4|5> {
      - if <player.flag[dice_held].get[%value%]> == REDSTONE_ORE {
        - flag player dice_hand[%value%]:<util.random.int[1].to[6]>
      }
    }
Dice_SortHand:
  type: task
  debug: false
  script:
    - flag player dice_temp:!
    - flag player dice_temp:|:<player.flag[dice_hand].numerical.as_list>
    - flag player dice_hand:!
    - flag player dice_hand:|:<player.flag[dice_temp].numerical.as_list>

Dice_Payout:
  type: task
  definitions: pay
  debug: false
  script:
    - give money quantity:%pay%
    - narrate "<&e>You now have <&a>$<&6><player.money.as_int||0>"

Dice_Initialize:
  type: task
  debug: false
  script:
    - flag player dice_hand:|:0|0|0|0|0
    - flag player dice_held:|:REDSTONE_ORE|REDSTONE_ORE|REDSTONE_ORE|REDSTONE_ORE|REDSTONE_ORE
    - flag player dice_phase:1

Dice_ResetFlags:
  type: task
  debug: false
  script:
    - flag player dice_hand:!
    - flag player dice_held:!
    - flag player dice_phase:!
    - flag player dice_temp:!
    - flag global dice_cost:100
    - flag global FivePay:2000
    - flag global FourPay:300
    - flag global FullHousePay:150
    - flag global ThreePay:100
    - flag global StraightPay:400
######################################Dice Win Check Conditions##################################
#      These checks assume that the Hand is a sorted list of numbers, and are independent.      #
#################################################################################################
Dice_CheckFullHouse:
  type: procedure
  debug: false
  script:
    - if <player.flag[dice_hand].get[1].as_int> == <player.flag[dice_hand].get[2].as_int> && <player.flag[dice_hand].get[2].as_int> != <player.flag[dice_hand].get[3].as_int> && <player.flag[dice_hand].get[3].as_int> == <player.flag[dice_hand].get[4].as_int> && <player.flag[dice_hand].get[4].as_int> == <player.flag[dice_hand].get[5].as_int> {
      - determine true
    } else if <player.flag[dice_hand].get[1].as_int> == <player.flag[dice_hand].get[2].as_int> && <player.flag[dice_hand].get[2].as_int> == <player.flag[dice_hand].get[3].as_int> && <player.flag[dice_hand].get[3].as_int> != <player.flag[dice_hand].get[4].as_int> && <player.flag[dice_hand].get[4].as_int> == <player.flag[dice_hand].get[5].as_int> {
      - determine true
    } else {
      - determine false
    }

Dice_CheckThree:
  type: procedure
  debug: false
  script:
    - if <player.flag[dice_hand].get[1].as_int> == <player.flag[dice_hand].get[2].as_int> && <player.flag[dice_hand].get[2].as_int> == <player.flag[dice_hand].get[3].as_int> && <player.flag[dice_hand].get[3].as_int> != <player.flag[dice_hand].get[4].as_int> && <player.flag[dice_hand].get[4].as_int> != <player.flag[dice_hand].get[5].as_int> {
      - determine true
    } else if <player.flag[dice_hand].get[1].as_int> != <player.flag[dice_hand].get[2].as_int> && <player.flag[dice_hand].get[2].as_int> == <player.flag[dice_hand].get[3].as_int> && <player.flag[dice_hand].get[3].as_int> == <player.flag[dice_hand].get[4].as_int> && <player.flag[dice_hand].get[4].as_int> != <player.flag[dice_hand].get[5].as_int> {
      - determine true
    } else if <player.flag[dice_hand].get[1].as_int> != <player.flag[dice_hand].get[2].as_int> && <player.flag[dice_hand].get[2].as_int> != <player.flag[dice_hand].get[3].as_int> && <player.flag[dice_hand].get[3].as_int> == <player.flag[dice_hand].get[4].as_int> && <player.flag[dice_hand].get[4].as_int> == <player.flag[dice_hand].get[5].as_int> {
      - determine true
    } else {
      - determine false
    }

Dice_CheckFour:
  type: procedure
  debug: false
  script:
    - if <player.flag[dice_hand].get[1].as_int> == <player.flag[dice_hand].get[2].as_int> && <player.flag[dice_hand].get[2].as_int> == <player.flag[dice_hand].get[3].as_int> && <player.flag[dice_hand].get[3].as_int> == <player.flag[dice_hand].get[4].as_int> && <player.flag[dice_hand].get[4].as_int> != <player.flag[dice_hand].get[5].as_int> {
      - determine true
    } else if <player.flag[dice_hand].get[1].as_int> != <player.flag[dice_hand].get[2].as_int> && <player.flag[dice_hand].get[2].as_int> == <player.flag[dice_hand].get[3].as_int> && <player.flag[dice_hand].get[3].as_int> == <player.flag[dice_hand].get[4].as_int> && <player.flag[dice_hand].get[4].as_int> == <player.flag[dice_hand].get[5].as_int> {
      - determine true
    } else {
      - determine false
    }

Dice_CheckStraight:
  type: procedure
  debug: false
  script:
    - if <player.flag[dice_hand].get[1].as_int> == <player.flag[dice_hand].get[2].as_int.sub_int[1]> && <player.flag[dice_hand].get[2].as_int> == <player.flag[dice_hand].get[3].as_int.sub_int[1]> && <player.flag[dice_hand].get[3].as_int> == <player.flag[dice_hand].get[4].as_int.sub_int[1]> && <player.flag[dice_hand].get[4].as_int> == <player.flag[dice_hand].get[5].as_int.sub_int[1]> {
      - determine true
    } else {
      - determine false
    }

Dice_CheckFive:
  type: procedure
  debug: false
  script:
    - if <player.flag[dice_hand].get[1].as_int> == <player.flag[dice_hand].get[2].as_int> && <player.flag[dice_hand].get[2].as_int> == <player.flag[dice_hand].get[3].as_int> && <player.flag[dice_hand].get[3].as_int> == <player.flag[dice_hand].get[4].as_int> && <player.flag[dice_hand].get[4].as_int> == <player.flag[dice_hand].get[5].as_int> {
      - determine true
    } else {
      - determine false
    }