Paste #22009: Edit of P#21301 dBanker

Date: 2015/10/30 22:57:22 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


dBankerConfig:
  type: yaml data
  coin:
    ## This is how many dollars each coin is worth.
    ## Default: 1
    value: 1
    ## This can be an itemscript or a normal minecraft item.
    ## Must be written as i@item e.g. 'i@dBankerCoin'
    ## Default: coin
    item: dBankerCoin
    name:
      ## The name of one coin. e.g. coin
      ## Default: Coin
      singular: Coin
      ## The name of more than one. e.g. coins
      ## Default: Coins
      plural: Coins
  upgrade:
    ## These are the costs for each upgrade of storage.
    ## Default: 1000
    one: 1000
    ## Default: 2000
    two: 2000
    ## Default: 3000
    three: 3000

dBankerCoin:
  type: item
  debug: false
  material: gold_nugget
  display name: A Coin
  lore:
  - <&1>A single dollar coin!

dBanker:
  type: assignment
  debug: false
  actions:
    on assignment:
      - trigger name:click state:true
      - trigger name:chat state:true
      - trigger name:proximity state:true radius:5

    on exit proximity:
      - if <pl.has_flag[dBankerStep]> {
        - flag player dBankerStep:!
        - narrate format:dBankerChat "Please, do come back soon!"
      }

    on click:
      - if <pl.has_flag[dBankerStep]> queue clear
      - look <npc> <pl.eye_location>
      - narrate format:dBankerChat "Hello <pl.name>!"
      - wait 10t
      - narrate format:dBankerChat "What can I do for you today?"
      - narrate "Type <&8>Store<&f>, <&8>Deposit<&f>, <&8>Withdraw<&f>, <&8>Upgrade<&f>, or <&8>Nothing<&f>."
      - flag player dBankerStep:Choose

    on chat:
      - if <player.has_flag[dBankerStep].not> queue clear
      - determine passively cancelled
      - wait 5t
      - choose <player.flag[dBankerStep]>:
        - case choose:
          - choose <context.message>:
            - case store:
              - if <server.list_notables[inventories].contains[in@dBank_<pl.uuid>].not> {
                - note "in@generic[size=27;title=<&3><pl.name><&f>'s Bank;contents=li@i@air|i@air|i@air|i@air|i@diamond]" as:dBank_<pl.uuid>
                - narrate format:dBankerChat "I've had to create a new account for you!"
                - wait 5t
                - narrate format:dBankerChat "You'll find a complimentary diamond in there for you!"
                - wait 5t
              }
              - inventory open d:in@dBank_<pl.uuid>
              - flag player dBankerStep:!

            - case withdraw:
              - define Amt <pl.money.as_int||0>
              - narrate format:dBankerChat "Okay, it looks like you have <&6><def[Amt]><&f> dollars in your account."
              - wait 5t
              - if <def[Amt]> == 0 {
                - narrate format:dBankerChat "So, I'm sorry. I can't let you withdraw at the moment!"
                - flag player dBankerStep:!
                - queue clear
              }
              - narrate format:dBankerChat "Please tell me how many <s@dBankerConfig.yaml_key[coin.name.plural]> you would like."
              - wait 5t
              - narrate format:dBankerChat "One <s@dBankerConfig.yaml_key[coin.name.singular]> is worth <&6><s@dBankerConfig.yaml_key[coin.value].as_int><&f> <t[<s@dBankerConfig.yaml_key[coin.value].as_int.is[==].to[1]>]:dollar||dollars>."
              - narrate "Type an integer. <&8>e.g. 5"
              - flag player dBankerStep:Withdraw

            - case deposit:
              - define Amt <pl.inventory.quantity[<s@dBankerConfig.yaml_key[coin.item].as_item>]>
              - narrate format:dBankerChat "Okay, it looks like you have <&6><def[Amt]><&f> <proc[CoinName].context[<def[Amt]>]>."
              - wait 5t
              - if <def[Amt]> == 0 {
                - narrate format:dBankerChat "So, I'm sorry. I can't let you deposit at the moment!"
                - flag player dBankerStep:!
                - queue clear
              }
              - narrate format:dBankerChat "Please tell me how many <s@dBankerConfig.yaml_key[coin.name.plural]> you'd like to deposit!"
              - narrate "Type an integer. <&8>e.g. 5"
              - flag player dBankerStep:Deposit

            - case upgrade:
              - if <server.list_notables[inventories].contains[in@dBank_<pl.uuid>].not> {
                - narrate format:dBankerChat "Sorry, you don't seem to have an account with us at the moment."
                - narrate format:dBankerChat "Please, ask to store items to open an account!"
                - flag player dBankerStep:!
                - queue clear
              }
              - define B in@dBank_<pl.uuid>
              - define Upgrade <def[B].size.sub[27].div[9]>
              - if <def[Upgrade]> == 3 {
                - narrate format:dBankerChat "Your bank is fully upgraded!"
                - flag player dBankerStep:!
                - queue clear
              }
              - narrate format:dBankerChat "It would seem your current upgrade tier is <&6><def[Upgrade]><&f>."
              - wait 5t
              - narrate format:dBankerChat "Would you like to upgrade to the next tier for <&6><proc[dBankerUCost].context[<def[Upgrade]>]><&f> dollars?"
              - narrate "Type <&8>Yes<&f> or <&8>No<&f>."
              - flag player dBankerStep:Upgrade

            - case nothing:
              - narrate format:dBankerChat "Okay, come back at any time!"
              - flag player dBankerStep:!

            - default:
              - narrate format:dBankerChat "I'm sorry, I have no idea what you mean!"
              - narrate "Type <&8>Store<&f>, <&8>Deposit<&f>, <&8>Withdraw<&f>, <&8>Upgrade<&f>, or <&8>Nothing<&f>."

        - case deposit:
          - define Amt <context.message.as_int||null>
          - if <def[Amt]> == null {
            - narrate format:dBankerChat "Sorry, I don't understand that amount. Please tell me again."
            - queue clear
          }
          - if <def[Amt]> <= 0 {
            - narrate format:dBankerChat "I can't let you do that.."
            - flag player dBankerStep:!
            - queue clear
          }
          - if <def[Amt]> > <pl.inventory.quantity[<s@dBankerConfig.yaml_key[coin.item].as_item>]> {
            - narrate format:dBankerChat "It would seem you don't have that many <s@dBankerConfig.yaml_key[coin.name.plural]>.."
            - flag player dBankerStep:!
            - queue clear
          }
          - give money quantity:<def[Amt].mul[<s@dBankerConfig.yaml_key[coin.value]>]>
          - take <s@dBankerConfig.yaml_key[coin.item].as_item> quantity:<def[Amt]>
          - narrate format:dBankerChat "I put the <proc[CoinName].context[<def[Amt]>]> in your account for you and you now have <&6><pl.money.as_int||0><&f> dollars."
          - flag player dBankerStep:!

        - case withdraw:
          - define Amt <context.message.as_int||null>
          - if <def[Amt]> == null {
            - narrate format:dBankerChat "Sorry, I don't understand that amount. Please tell me again."
            - queue clear
          }
          - if <def[Amt]> <= 0 {
            - narrate format:dBankerChat "I can't let you do that.."
            - flag player dBankerStep:!
            - queue clear
          }
          - define Val <def[Amt].mul[<s@dBankerConfig.yaml_key[coin.value]>]>
          - if <def[Val]> > <pl.money> {
            - narrate format:dBankerChat "It would seem you don't have enough money.."
            - flag player dBankerStep:!
            - queue clear
          }
          - if <pl.inventory.can_fit[<s@dBankerConfig.yaml_key[coin.item].as_item>].quantity[<def[Amt]>].not> {
            - narrate format:dBankerChat "Sorry, it looks like you can't hold the <s@dBankerConfig.yaml_key[coin.name.plural]>, you might try a few less!"
            - flag player dBankerStep:!
            - queue clear
          }
          - wait 5t
          - take money quantity:<def[Val]>
          - give <s@dBankerConfig.yaml_key[coin.item].as_item> quantity:<def[Amt]>
          - narrate format:dBankerChat "I've withdrawn the money from your account, and given you <&6><def[Amt]><&f> <proc[CoinName].context[<def[Amt]>]>."
          - flag player dBankerStep:!

        - case upgrade:
          - define Answer <li@Yes|No.filter[starts_with[<context.message>]].get[1]||null>
          - choose <def[Answer]>:
            - case yes:
              - define B in@dBank_<pl.uuid>
              - define Upgrade <def[B].size.sub[27].div[9]>
              - define Amt <el@val[1000].mul[<def[Upgrade].add[1]>]>
              - if <pl.money||0> < <def[Amt]> {
                - narrate format:dBankerChat "You don't seem to have enough money!"
                - flag player dBankerStep:!
                - queue clear
              }
              - narrate format:dBankerChat "I'll do that for you now!"
              - adjust <def[B]> size:<def[B].size.add[9]> save:B
              - take money quantity:<proc[dBankerUCost].context[<def[Upgrade]>]>
              - note <entry[B].result> as:dBank_<pl.uuid>
              - flag player dBankerStep:!
              - narrate format:dBankerChat "Your bank is now upgraded to level <&6><def[Upgrade].add[1]><&f>."

            - case no:
              - narrate format:dBankerChat "Please move along then. I have customers to serve!"
              - flag player dBankerStep:!

            - default:
              - narrate format:dBankerChat "Sorry?"
              - narrate "Type <&8>Yes<&f> or <&8>No<&f>."

dBankerUCost:
  type: procedure
  definitions: tier
  script:
  - choose <def[Tier]>:
    - case 0:
      - if <s@dBankerConfig.yaml_key[upgrade.one].as_int||1000> == "" {
        - define Cost 1000
      }
      else {
        - define Cost <s@dBankerConfig.yaml_key[upgrade.one].as_int||1000>
      }
    - case 1:
      - if <s@dBankerConfig.yaml_key[upgrade.two].as_int||2000> == "" {
        - define Cost 2000
      }
      else {
        - define Cost <s@dBankerConfig.yaml_key[upgrade.two].as_int||2000>
      }
    - case 2:
      - if <s@dBankerConfig.yaml_key[upgrade.three].as_int||3000> == "" {
        - define Cost 3000
      }
      else {
        - define Cost <s@dBankerConfig.yaml_key[upgrade.three].as_int||3000>
      }
  - determine <def[Cost]>

CoinName:
  type: procedure
  definitions: Amt
  script:
    - choose <def[Amt]>:
      - case 1:
        - determine <s@dBankerConfig.yaml_key[coin.name.singular]>
      - default:
        - determine <s@dBankerConfig.yaml_key[coin.name.plural]>

dBankerChat:
  type: format
  debug: false
  format: <&6><npc.name>:<&f> <text>