Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. from evennia import default_cmds, CmdSet, InterruptCommand
  2. from typeclasses.objects import altObject
  3. from evennia.utils.evmenu import EvMenu
  4. from evennia.utils import interactive
  5.  
  6. class UseATM(default_cmds.MuxCommand):
  7. key = "Use ATM"
  8. auto_help = False
  9.  
  10. def func(self):
  11. if not self.caller.tags.get("Yes", category="BankAccount"):
  12. 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.")
  13. return
  14. if self.caller.tags.get("Yes", category="BankAccount"):
  15. EvMenu(self.caller, "typeclasses.atm", startnode="menu_start_node")
  16.  
  17. def menu_start_node(caller):
  18. text = "You currently have $%s Pepperbucks in your account." % (caller.db.bank)
  19. options = ({"desc": "Make a deposit.",
  20. "exec": deposit},
  21. {"desc": "Make a withdraw.",
  22. "exec": withdraw},
  23. {"desc": "Check Balance.",
  24. "exec": balance},
  25. {"desc": "Cancel.",
  26. "goto": "END"}),
  27. return text, options
  28.  
  29. def END(caller):
  30. text = "Thank you for using the First United Credit-Kilobyte Union ATM.|/ATM: Have a great day!"
  31. options = ()
  32. return text, options
  33.  
  34. def withdraw(caller):
  35. if self.caller.db.bank == 0:
  36. self.caller.msg("Insufficient funds to complete transaction.")
  37. return "menu_start_node"
  38. if self.caller.db.bank > 0:
  39. self.caller.msg("How much would you like to withdraw?")
  40. withdraw = yield("Enter a whole dollar number, such as 5")
  41. try:
  42. self.withdraw = int(withdraw)
  43. except ValueError:
  44. self.caller.msg(f"Invalid transaction amount {withdraw}")
  45. self.caller.msg("Transaction Canceled.")
  46. return "menu_start_node"
  47. if self.withdraw > self.caller.db.bank:
  48. self.caller.msg("Insufficient Funds.")
  49. self.caller.msg("Transaction Canceled.")
  50. return "menu_start_node"
  51. elif self.withdraw <= self.caller.db.bank:
  52. self.caller.db.bank -= self.withdraw
  53. self.caller.db.pepperbucks += self.withdraw
  54. self.caller.msg("Your account balance is $%s" % (self.caller.db.bank))
  55. return "another"
  56.  
  57. def deposit(caller):
  58. if self.caller.db.pepperbucks == 0:
  59. self.caller.msg("You don't have any cash to deposit.")
  60. return "menu_start_node"
  61. if self.caller.db.pepperbucks > 0:
  62. self.caller.msg("How much would you like to deposit?")
  63. deposit = yield("Enter a whole dollar number, such as 5")
  64. try:
  65. self.deposit = int(deposit)
  66. except ValueError:
  67. self.caller.msg(f"Invalid transaction amount {withdraw}")
  68. self.caller.msg("Transaction Canceled.")
  69. return "menu_start_node"
  70. if self.withdraw > self.caller.db.pepperbucks:
  71. self.caller.msg("You don't have that much cash.")
  72. self.caller.msg("Transaction Canceled.")
  73. return "menu_start_node"
  74. elif self.deposit <= self.caller.db.pepperbucks:
  75. self.caller.db.pepperbucks -= self.withdraw
  76. self.caller.db.bank += self.withdraw
  77. self.caller.msg("Your account balance is $%s" % (self.caller.db.bank))
  78. return "another"
  79.  
  80. def balance(caller):
  81. self.caller.msg("Your current balance is $%s" % (self.caller.db.bank))
  82. return "another"
  83.  
  84. def another(caller):
  85. text = "Do you want to make another transaction?"
  86. options = ({"desc": "Yes.",
  87. "goto": "menu_start_node"},
  88. {"desc": "No.",
  89. "goto": "END"}),
  90. return text, options
  91.  
  92. class ATMCmdSet(CmdSet):
  93. key = "ATMCmdSet"
  94. def at_cmdset_creation(self):
  95. self.add(UseATM())
  96.  
  97. class ATM(altObject):
  98. def at_object_creation(self):
  99. self.db.desc = "A simple ATM. First United Credit-Kilobyte Union ATM floats across the screen."
  100. self.db.descalt = "An enchanted money machine glows eerily. There are two words on the screen: Give and Take."
  101. self.cmdset.add_default(ATMCmdSet, permanent=True)
  102. self.locks.add("get:false()")
  103. self.db.get_err_msg = "The ATM is too heavy to steal. Duh."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement