Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from evennia import default_cmds, CmdSet, InterruptCommand
- from typeclasses.objects import altObject
- from evennia.utils.evmenu import EvMenu
- from evennia.utils import interactive
- class UseATM(default_cmds.MuxCommand):
- key = "Use ATM"
- auto_help = False
- def func(self):
- if not self.caller.tags.get("Yes", category="BankAccount"):
- self.caller.msg("You don't have a bank account. You need to go to the bank to open an account before you can use the ATM.")
- return
- if self.caller.tags.get("Yes", category="BankAccount"):
- EvMenu(self.caller, "typeclasses.atm", startnode="menu_start_node")
- def menu_start_node(caller):
- text = "You currently have $%s Pepperbucks in your account." % (caller.db.bank)
- options = ({"desc": "Make a deposit.",
- "exec": deposit},
- {"desc": "Make a withdraw.",
- "exec": withdraw},
- {"desc": "Check Balance.",
- "exec": balance},
- {"desc": "Cancel.",
- "goto": "END"}),
- return text, options
- def END(caller):
- text = "Thank you for using the First United Credit-Kilobyte Union ATM.|/ATM: Have a great day!"
- options = ()
- return text, options
- def withdraw(caller):
- if self.caller.db.bank == 0:
- self.caller.msg("Insufficient funds to complete transaction.")
- return "menu_start_node"
- if self.caller.db.bank > 0:
- self.caller.msg("How much would you like to withdraw?")
- withdraw = yield("Enter a whole dollar number, such as 5")
- try:
- self.withdraw = int(withdraw)
- except ValueError:
- self.caller.msg(f"Invalid transaction amount {withdraw}")
- self.caller.msg("Transaction Canceled.")
- return "menu_start_node"
- if self.withdraw > self.caller.db.bank:
- self.caller.msg("Insufficient Funds.")
- self.caller.msg("Transaction Canceled.")
- return "menu_start_node"
- elif self.withdraw <= self.caller.db.bank:
- self.caller.db.bank -= self.withdraw
- self.caller.db.pepperbucks += self.withdraw
- self.caller.msg("Your account balance is $%s" % (self.caller.db.bank))
- return "another"
- def deposit(caller):
- if self.caller.db.pepperbucks == 0:
- self.caller.msg("You don't have any cash to deposit.")
- return "menu_start_node"
- if self.caller.db.pepperbucks > 0:
- self.caller.msg("How much would you like to deposit?")
- deposit = yield("Enter a whole dollar number, such as 5")
- try:
- self.deposit = int(deposit)
- except ValueError:
- self.caller.msg(f"Invalid transaction amount {withdraw}")
- self.caller.msg("Transaction Canceled.")
- return "menu_start_node"
- if self.withdraw > self.caller.db.pepperbucks:
- self.caller.msg("You don't have that much cash.")
- self.caller.msg("Transaction Canceled.")
- return "menu_start_node"
- elif self.deposit <= self.caller.db.pepperbucks:
- self.caller.db.pepperbucks -= self.withdraw
- self.caller.db.bank += self.withdraw
- self.caller.msg("Your account balance is $%s" % (self.caller.db.bank))
- return "another"
- def balance(caller):
- self.caller.msg("Your current balance is $%s" % (self.caller.db.bank))
- return "another"
- def another(caller):
- text = "Do you want to make another transaction?"
- options = ({"desc": "Yes.",
- "goto": "menu_start_node"},
- {"desc": "No.",
- "goto": "END"}),
- return text, options
- class ATMCmdSet(CmdSet):
- key = "ATMCmdSet"
- def at_cmdset_creation(self):
- self.add(UseATM())
- class ATM(altObject):
- def at_object_creation(self):
- self.db.desc = "A simple ATM. First United Credit-Kilobyte Union ATM floats across the screen."
- self.db.descalt = "An enchanted money machine glows eerily. There are two words on the screen: Give and Take."
- self.cmdset.add_default(ATMCmdSet, permanent=True)
- self.locks.add("get:false()")
- self.db.get_err_msg = "The ATM is too heavy to steal. Duh."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement