Advertisement
hyde9318

Shopaholic Page 12

Jul 29th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.61 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # page 12 of 12
  3. # Shopoholic v 2.0
  4. # code by cmpsr2000
  5. # available exclusively @ rpgrevolution.com/forums
  6. # Released June 25, 2008
  7. #
  8. #-------------------------------------------------------------------------------
  9. #-------------------------------------------------------------------------------
  10. # ** Scene_Bank
  11. #-------------------------------------------------------------------------------
  12. # This class performs the bank screen processing.
  13. #-------------------------------------------------------------------------------
  14. class Scene_Bank < Scene_Base
  15. #-----------------------------------------------------------------------------
  16. # Creates the banking scene.
  17. # bankID: The ID of the bank to be shown. (you can show the same bank
  18. # In various events throughout your game, just as you can with
  19. # shops. This way, you can have 1 bank for your entire game
  20. # if you chose)
  21. # rates: An array of interest rates: [savings, checking, loan]
  22. # savings: interest rate for savings accounts at this
  23. # instance of this bank.
  24. # checking: interest rate for checking accounts at this
  25. # instance of this bank.
  26. # loan: interest rate for checking accounts at this
  27. # instance of this bank.
  28. # NOTE: If you have more than one event per bankID you can
  29. # set different interest rates at each one! (sort of like
  30. # branches of a real bank)
  31. # slotCost: Cost for each new Saftey Deposit Box in the vault
  32. # loanMax: The max amount the bank will issue in a single loan. This
  33. # overrides the global setting for max loan if it is lower.
  34. # hasVault Boolean indicating whether or not this instance of this bank
  35. # has a vault. Again if you have multiple events for a bankID
  36. # Then you can enable the vault in some while disabling it in
  37. # others and the players items will persist.
  38. #-----------------------------------------------------------------------------
  39. def initialize(bankID, rates, slotCost, loanMax = 9999999, hasVault = true)
  40. @bankID = bankID
  41. @xfer = false
  42. @rates = rates #interest rates array: [savings, checking, loan]
  43. @slotCost = slotCost
  44. @hasVault = hasVault
  45. @loanMax = loanMax
  46. $game_banking.setRates(@bankID, @rates)
  47. $game_banking.calcInterest(@bankID)
  48. end
  49. #-----------------------------------------------------------------------------
  50. # Uhhh.....ends the banking scene :)
  51. #-----------------------------------------------------------------------------
  52. def terminate
  53. super
  54. dispose_menu_background
  55. @command_window.dispose
  56. @accountCmd_window.dispose
  57. @help_window.dispose
  58. @gold_window.dispose
  59. @dummy_window.dispose
  60. @account_window.dispose
  61. @vault_window.dispose
  62. @item_window.dispose
  63. @number_window.dispose
  64. end
  65. #-----------------------------------------------------------------------------
  66. # Creates the windows and sets up the starting positions and attributes
  67. #-----------------------------------------------------------------------------
  68. def start
  69. super
  70. create_menu_background
  71. create_command_window
  72. create_accountCmd_window
  73. @help_window = Window_Help.new
  74. @gold_window = Window_Gold.new(384, 56)
  75. @dummy_window = Window_Base.new(0, 112, 544, 304)
  76. @account_window = Window_Bank_Account.new(0, 112, @bankID)
  77. @vault_window = Window_Bank_Vault.new(0, 112, @bankID)
  78. @number_window = Window_Bank_Number.new(0, 112)
  79. @item_window = Window_Item.new(304, 112, 240, 304)
  80. @account_window.active = false
  81. @account_window.visible = false
  82. @account_window.help_window = @help_window
  83. @account_window.accountCmd_window = @accountCmd_window
  84. @account_window.refresh
  85. @vault_window.active = false
  86. @vault_window.visible = false
  87. @vault_window.help_window = @help_window
  88. @number_window.active = false
  89. @number_window.visible = false
  90. @item_window.column_max = 1
  91. @item_window.active = false
  92. @item_window.visible = false
  93. @dummy_window.active = false
  94. @dummy_window.visible = true
  95. @accountCmd_window.active = false
  96. @accountCmd_window.visible = false
  97. @accountCmd_window.z = 101
  98. end
  99. #-----------------------------------------------------------------------------
  100. # Builds the main command window
  101. #-----------------------------------------------------------------------------
  102. def create_command_window
  103. s1 = Vocab::BankAccounts
  104. s2 = Vocab::BankVault
  105. s3 = Vocab::BankCancel
  106. @command_window = Window_Command.new(384, [s1, s2, s3], 3)
  107. @command_window.y = 56
  108. if not @hasVault
  109. @command_window.draw_item(1, false)
  110. end
  111. end
  112. #-----------------------------------------------------------------------------
  113. # Builds the account command window
  114. #-----------------------------------------------------------------------------
  115. def create_accountCmd_window
  116. s1 = Vocab::BankDeposit
  117. s2 = Vocab::BankWithdraw
  118. s3 = Vocab::BankTransfer
  119. @accountCmd_window = Window_Command.new(384, [s1, s2, s3], 3)
  120. @accountCmd_window.x = 80
  121. @accountCmd_window.y = 212
  122. end
  123. #-----------------------------------------------------------------------------
  124. # Updates the windows and checks for input depending on the active window
  125. #-----------------------------------------------------------------------------
  126. def update
  127. super
  128. update_menu_background
  129. @help_window.update
  130. @command_window.update
  131. @accountCmd_window.update
  132. @gold_window.update
  133. @dummy_window.update
  134. @account_window.update
  135. @vault_window.update
  136. @item_window.update
  137. @number_window.update
  138. if @command_window.active
  139. update_command_selection
  140. elsif @account_window.active
  141. update_account_selection
  142. elsif @vault_window.active
  143. update_vault_selection
  144. elsif @item_window.active
  145. update_item_selection
  146. elsif @number_window.active
  147. update_number_input
  148. elsif @accountCmd_window.active
  149. update_accountCmd_selection
  150. end
  151. end
  152. #-----------------------------------------------------------------------------
  153. # Checks the command window for input when it is active
  154. #-----------------------------------------------------------------------------
  155. def update_command_selection
  156. if Input.trigger?(Input::B)
  157. Sound.play_cancel
  158. $scene = Scene_Map.new
  159. elsif Input.trigger?(Input::C)
  160. case @command_window.index
  161. when 0 # accounts
  162. Sound.play_decision
  163. @command_window.active = false
  164. @dummy_window.visible = false
  165. @account_window.active = true
  166. @account_window.visible = true
  167. @account_window.refresh
  168. when 1 # vault
  169. if not @hasVault
  170. Sound.play_buzzer
  171. else
  172. Sound.play_decision
  173. @command_window.active = false
  174. @dummy_window.visible = false
  175. @vault_window.active = true
  176. @vault_window.visible = true
  177. @item_window.visible = true
  178. @vault_window.refresh
  179. @item_window.refresh
  180. end
  181. when 2 # cancel
  182. Sound.play_decision
  183. $scene = Scene_Map.new
  184. end
  185. end
  186. end
  187. #-----------------------------------------------------------------------------
  188. # Checks the account window for input when it is active
  189. #-----------------------------------------------------------------------------
  190. def update_account_selection
  191. if Input.trigger?(Input::B)
  192. if @xfer
  193. Sound.play_cancel
  194. @xfer = false
  195. @accountCmd_window.index = 0
  196. @account_window.refresh
  197. else
  198. Sound.play_cancel
  199. @command_window.active = true
  200. @dummy_window.visible = true
  201. @account_window.active = false
  202. @account_window.visible = false
  203. end
  204. @help_window.set_text("")
  205. return
  206. end
  207. if Input.trigger?(Input::C)
  208. if @xfer
  209. @xferAccount = @account_window.account
  210. if @account == @xferAccount or @xferAccount.balance == 9999999
  211. Sound.play_buzzer
  212. return
  213. end
  214. if @xferAccount.type == 2 #loan
  215. max = [@account.balance, @xferAccount.balance].min
  216. else
  217. max = @account.balance
  218. end
  219. callNumberWindow(max)
  220. else
  221. @account = @account_window.account
  222. if @account == nil
  223. #if we are creating a new loan:
  224. if @account_window.index == @account_window.item_max - 1
  225. Sound.play_decision
  226. @action = 3
  227. max = [@loanMax, $game_banking.loanMax, 9999999].min
  228. callNumberWindow(max)
  229. return
  230. else
  231. Sound.play_buzzer
  232. return
  233. end
  234. end
  235. Sound.play_decision
  236. @account_window.active = false
  237. @accountCmd_window.active = true
  238. @accountCmd_window.visible = true
  239. @accountCmd_window.draw_item(0, true)
  240. @accountCmd_window.draw_item(1, true)
  241. @accountCmd_window.draw_item(2, true)
  242. if @account.type == 2 or @account.balance == 0 #loan or empty
  243. @accountCmd_window.draw_item(1, false)
  244. @accountCmd_window.draw_item(2, false)
  245. elsif @account.balance == 9999999
  246. @accountCmd_window.draw_item(0, false)
  247. end
  248. end
  249. end
  250. end
  251. #-----------------------------------------------------------------------------
  252. # Brigns the number window to the front with the correct layout
  253. #-----------------------------------------------------------------------------
  254. def callNumberWindow(max)
  255. @account_window.active = false
  256. @account_window.visible = false
  257. @accountCmd_window.active = false
  258. @accountCmd_window.visible = false
  259. @item_window.visible = false
  260. @item_window.active = false
  261. @vault_window.visible = false
  262. @vault_window.active = false
  263. @number_window.set(max, @action, @account, @xferAccount, @item, @slotCost)
  264. @number_window.active = true
  265. @number_window.visible = true
  266. end
  267. #-----------------------------------------------------------------------------
  268. # Checks the vault window for input when it is active
  269. #-----------------------------------------------------------------------------
  270. def update_vault_selection
  271. if Input.trigger?(Input::B)
  272. Sound.play_cancel
  273. if @storing
  274. @storing = false
  275. else
  276. @command_window.active = true
  277. @dummy_window.visible = true
  278. @vault_window.active = false
  279. @vault_window.visible = false
  280. @item_window.visible = false
  281. end
  282. @help_window.set_text("")
  283. elsif Input.trigger?(Input::C)
  284. @slot = @vault_window.slot
  285. if @slot != nil and @slot.item != nil
  286. Sound.play_decision
  287. @slot.takeItem
  288. @vault_window.refresh
  289. @item_window.refresh
  290. else
  291. if @vault_window.index == @vault_window.item_max - 1
  292. max = $game_banking.closedVaultSlots(@bankID)
  293. @action = 4 #buy slots
  294. callNumberWindow(max)
  295. elsif @slot == nil or @slot.locked
  296. Sound.play_buzzer
  297. else
  298. Sound.play_decision
  299. @storing = true
  300. @item_window.active = true
  301. @vault_window.active = false
  302. end
  303. end
  304. end
  305. end
  306. #-----------------------------------------------------------------------------
  307. # Checks the item window for input when it is active
  308. #-----------------------------------------------------------------------------
  309. def update_item_selection
  310. if Input.trigger?(Input::B)
  311. Sound.play_cancel
  312. @storing = false
  313. @item_window.active = false
  314. @vault_window.active = true
  315. elsif Input.trigger?(Input::C)
  316. @item = @item_window.item
  317. max = $game_party.item_number(@item)
  318. @action = 5 #how many to transfer
  319. callNumberWindow(max)
  320. end
  321. end
  322. #-----------------------------------------------------------------------------
  323. # Checks the account command window for input when it is active
  324. #-----------------------------------------------------------------------------
  325. def update_accountCmd_selection
  326. if Input.trigger?(Input::B)
  327. Sound.play_cancel
  328. @accountCmd_window.visible = false
  329. @accountCmd_window.active = false
  330. @account_window.active = true
  331. elsif Input.trigger?(Input::C)
  332. @action = @accountCmd_window.index
  333. case @action
  334. when 0 # deposit
  335. if @account.balance == 9999999
  336. Sound.play_buzzer
  337. else
  338. Sound.play_decision
  339. if @account.type == 2
  340. max = [$game_party.gold, @account.balance].min
  341. else
  342. max = [$game_party.gold, 9999999 - @account.balance].min
  343. end
  344. callNumberWindow(max)
  345. end
  346. when 1 # withdraw
  347. if @account.type == 2 or @account.balance == 0
  348. Sound.play_buzzer
  349. else
  350. Sound.play_decision
  351. max = [9999999 - $game_party.gold, @account.balance].min
  352. callNumberWindow(max)
  353. end
  354. when 2 #transfer
  355. if @account.type == 2 or @account.balance == 0
  356. Sound.play_buzzer
  357. else
  358. Sound.play_decision
  359. @xfer = true
  360. @accountCmd_window.active = false
  361. @accountCmd_window.visible = false
  362. @account_window.active = true
  363. @account_window.refresh
  364. @help_window.set_text("Select a recieving account for balance transfer.")
  365. end
  366. end
  367. end
  368. end
  369. #-----------------------------------------------------------------------------
  370. # Checks the number window for input when it is active
  371. #-----------------------------------------------------------------------------
  372. def update_number_input
  373. if Input.trigger?(Input::B)
  374. cancel_number_input
  375. elsif Input.trigger?(Input::C)
  376. decide_number_input
  377. end
  378. end
  379. #-----------------------------------------------------------------------------
  380. # Cancels the number window and restores the previous window state.
  381. #-----------------------------------------------------------------------------
  382. def cancel_number_input
  383. Sound.play_cancel
  384. @number_window.active = false
  385. @number_window.visible = false
  386. case @command_window.index
  387. when 0 # accounts
  388. @account_window.active = true
  389. @account_window.visible = true
  390. @xfer = false if @xfer
  391. when 1 # vault
  392. if @storing
  393. @item_window.active = true
  394. else
  395. @vault_window.active = true
  396. end
  397. @vault_window.visible = true
  398. @item_window.visible = true
  399. end
  400. end
  401. #-----------------------------------------------------------------------------
  402. # Confirms the number input and proccesses banking events accordingly
  403. #-----------------------------------------------------------------------------
  404. def decide_number_input
  405. Sound.play_shop
  406. @number_window.active = false
  407. @number_window.visible = false
  408. case @command_window.index
  409. when 0 # accounts
  410. if @account_window.index == @account_window.item_max - 1 #get loan
  411. $game_banking.makeLoan(@bankID, @rates, @number_window.number)
  412. $game_party.gain_gold(@number_window.number)
  413. else
  414. case @accountCmd_window.index
  415. when 0 #deposit
  416. @account.deposit(@number_window.number)
  417. $game_party.lose_gold(@number_window.number)
  418. if @account.type == 2 and @account.balance == 0
  419. $game_banking.bankAccounts[@bankID].delete(@account)
  420. end
  421. when 1 #withdraw(NA for loan)
  422. @account.withdraw(@number_window.number)
  423. $game_party.gain_gold(@number_window.number)
  424. when 2 #transfer
  425. @account.withdraw(@number_window.number)
  426. @xferAccount.deposit(@number_window.number)
  427. if @xferAccount.type == 2 and @xferAccount.balance == 0
  428. $game_banking.bankAccounts[@bankID].delete(@xferAccount)
  429. end
  430. @xfer = false
  431. end
  432. end
  433. @account = nil
  434. @xferAccount = nil
  435. @accountCmd_window.index = 0
  436. @account_window.active = true
  437. @account_window.visible = true
  438. @account_window.refresh
  439. @gold_window.refresh
  440. when 1 # vault
  441. if @storing
  442. @slot.storeItem(@item, @number_window.number)
  443. @storing = false
  444. else #must be buying slots
  445. purchasedSlots = @number_window.number
  446. $game_party.lose_gold(purchasedSlots * @slotCost)
  447. x = 0
  448. while purchasedSlots > 0
  449. if $game_banking.bankVaults[@bankID][x].locked
  450. $game_banking.bankVaults[@bankID][x].unlock
  451. purchasedSlots -= 1
  452. end
  453. x += 1
  454. end
  455. end
  456. @vault_window.active = true
  457. @vault_window.visible = true
  458. @item_window.visible = true
  459. @vault_window.refresh
  460. @item_window.refresh
  461. end
  462. end
  463. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement