Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # page 12 of 12
- # Shopoholic v 2.0
- # code by cmpsr2000
- # available exclusively @ rpgrevolution.com/forums
- # Released June 25, 2008
- #
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # ** Scene_Bank
- #-------------------------------------------------------------------------------
- # This class performs the bank screen processing.
- #-------------------------------------------------------------------------------
- class Scene_Bank < Scene_Base
- #-----------------------------------------------------------------------------
- # Creates the banking scene.
- # bankID: The ID of the bank to be shown. (you can show the same bank
- # In various events throughout your game, just as you can with
- # shops. This way, you can have 1 bank for your entire game
- # if you chose)
- # rates: An array of interest rates: [savings, checking, loan]
- # savings: interest rate for savings accounts at this
- # instance of this bank.
- # checking: interest rate for checking accounts at this
- # instance of this bank.
- # loan: interest rate for checking accounts at this
- # instance of this bank.
- # NOTE: If you have more than one event per bankID you can
- # set different interest rates at each one! (sort of like
- # branches of a real bank)
- # slotCost: Cost for each new Saftey Deposit Box in the vault
- # loanMax: The max amount the bank will issue in a single loan. This
- # overrides the global setting for max loan if it is lower.
- # hasVault Boolean indicating whether or not this instance of this bank
- # has a vault. Again if you have multiple events for a bankID
- # Then you can enable the vault in some while disabling it in
- # others and the players items will persist.
- #-----------------------------------------------------------------------------
- def initialize(bankID, rates, slotCost, loanMax = 9999999, hasVault = true)
- @bankID = bankID
- @xfer = false
- @rates = rates #interest rates array: [savings, checking, loan]
- @slotCost = slotCost
- @hasVault = hasVault
- @loanMax = loanMax
- $game_banking.setRates(@bankID, @rates)
- $game_banking.calcInterest(@bankID)
- end
- #-----------------------------------------------------------------------------
- # Uhhh.....ends the banking scene :)
- #-----------------------------------------------------------------------------
- def terminate
- super
- dispose_menu_background
- @command_window.dispose
- @accountCmd_window.dispose
- @help_window.dispose
- @gold_window.dispose
- @dummy_window.dispose
- @account_window.dispose
- @vault_window.dispose
- @item_window.dispose
- @number_window.dispose
- end
- #-----------------------------------------------------------------------------
- # Creates the windows and sets up the starting positions and attributes
- #-----------------------------------------------------------------------------
- def start
- super
- create_menu_background
- create_command_window
- create_accountCmd_window
- @help_window = Window_Help.new
- @gold_window = Window_Gold.new(384, 56)
- @dummy_window = Window_Base.new(0, 112, 544, 304)
- @account_window = Window_Bank_Account.new(0, 112, @bankID)
- @vault_window = Window_Bank_Vault.new(0, 112, @bankID)
- @number_window = Window_Bank_Number.new(0, 112)
- @item_window = Window_Item.new(304, 112, 240, 304)
- @account_window.active = false
- @account_window.visible = false
- @account_window.help_window = @help_window
- @account_window.accountCmd_window = @accountCmd_window
- @account_window.refresh
- @vault_window.active = false
- @vault_window.visible = false
- @vault_window.help_window = @help_window
- @number_window.active = false
- @number_window.visible = false
- @item_window.column_max = 1
- @item_window.active = false
- @item_window.visible = false
- @dummy_window.active = false
- @dummy_window.visible = true
- @accountCmd_window.active = false
- @accountCmd_window.visible = false
- @accountCmd_window.z = 101
- end
- #-----------------------------------------------------------------------------
- # Builds the main command window
- #-----------------------------------------------------------------------------
- def create_command_window
- s1 = Vocab::BankAccounts
- s2 = Vocab::BankVault
- s3 = Vocab::BankCancel
- @command_window = Window_Command.new(384, [s1, s2, s3], 3)
- @command_window.y = 56
- if not @hasVault
- @command_window.draw_item(1, false)
- end
- end
- #-----------------------------------------------------------------------------
- # Builds the account command window
- #-----------------------------------------------------------------------------
- def create_accountCmd_window
- s1 = Vocab::BankDeposit
- s2 = Vocab::BankWithdraw
- s3 = Vocab::BankTransfer
- @accountCmd_window = Window_Command.new(384, [s1, s2, s3], 3)
- @accountCmd_window.x = 80
- @accountCmd_window.y = 212
- end
- #-----------------------------------------------------------------------------
- # Updates the windows and checks for input depending on the active window
- #-----------------------------------------------------------------------------
- def update
- super
- update_menu_background
- @help_window.update
- @command_window.update
- @accountCmd_window.update
- @gold_window.update
- @dummy_window.update
- @account_window.update
- @vault_window.update
- @item_window.update
- @number_window.update
- if @command_window.active
- update_command_selection
- elsif @account_window.active
- update_account_selection
- elsif @vault_window.active
- update_vault_selection
- elsif @item_window.active
- update_item_selection
- elsif @number_window.active
- update_number_input
- elsif @accountCmd_window.active
- update_accountCmd_selection
- end
- end
- #-----------------------------------------------------------------------------
- # Checks the command window for input when it is active
- #-----------------------------------------------------------------------------
- def update_command_selection
- if Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- elsif Input.trigger?(Input::C)
- case @command_window.index
- when 0 # accounts
- Sound.play_decision
- @command_window.active = false
- @dummy_window.visible = false
- @account_window.active = true
- @account_window.visible = true
- @account_window.refresh
- when 1 # vault
- if not @hasVault
- Sound.play_buzzer
- else
- Sound.play_decision
- @command_window.active = false
- @dummy_window.visible = false
- @vault_window.active = true
- @vault_window.visible = true
- @item_window.visible = true
- @vault_window.refresh
- @item_window.refresh
- end
- when 2 # cancel
- Sound.play_decision
- $scene = Scene_Map.new
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Checks the account window for input when it is active
- #-----------------------------------------------------------------------------
- def update_account_selection
- if Input.trigger?(Input::B)
- if @xfer
- Sound.play_cancel
- @xfer = false
- @accountCmd_window.index = 0
- @account_window.refresh
- else
- Sound.play_cancel
- @command_window.active = true
- @dummy_window.visible = true
- @account_window.active = false
- @account_window.visible = false
- end
- @help_window.set_text("")
- return
- end
- if Input.trigger?(Input::C)
- if @xfer
- @xferAccount = @account_window.account
- if @account == @xferAccount or @xferAccount.balance == 9999999
- Sound.play_buzzer
- return
- end
- if @xferAccount.type == 2 #loan
- max = [@account.balance, @xferAccount.balance].min
- else
- max = @account.balance
- end
- callNumberWindow(max)
- else
- @account = @account_window.account
- if @account == nil
- #if we are creating a new loan:
- if @account_window.index == @account_window.item_max - 1
- Sound.play_decision
- @action = 3
- max = [@loanMax, $game_banking.loanMax, 9999999].min
- callNumberWindow(max)
- return
- else
- Sound.play_buzzer
- return
- end
- end
- Sound.play_decision
- @account_window.active = false
- @accountCmd_window.active = true
- @accountCmd_window.visible = true
- @accountCmd_window.draw_item(0, true)
- @accountCmd_window.draw_item(1, true)
- @accountCmd_window.draw_item(2, true)
- if @account.type == 2 or @account.balance == 0 #loan or empty
- @accountCmd_window.draw_item(1, false)
- @accountCmd_window.draw_item(2, false)
- elsif @account.balance == 9999999
- @accountCmd_window.draw_item(0, false)
- end
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Brigns the number window to the front with the correct layout
- #-----------------------------------------------------------------------------
- def callNumberWindow(max)
- @account_window.active = false
- @account_window.visible = false
- @accountCmd_window.active = false
- @accountCmd_window.visible = false
- @item_window.visible = false
- @item_window.active = false
- @vault_window.visible = false
- @vault_window.active = false
- @number_window.set(max, @action, @account, @xferAccount, @item, @slotCost)
- @number_window.active = true
- @number_window.visible = true
- end
- #-----------------------------------------------------------------------------
- # Checks the vault window for input when it is active
- #-----------------------------------------------------------------------------
- def update_vault_selection
- if Input.trigger?(Input::B)
- Sound.play_cancel
- if @storing
- @storing = false
- else
- @command_window.active = true
- @dummy_window.visible = true
- @vault_window.active = false
- @vault_window.visible = false
- @item_window.visible = false
- end
- @help_window.set_text("")
- elsif Input.trigger?(Input::C)
- @slot = @vault_window.slot
- if @slot != nil and @slot.item != nil
- Sound.play_decision
- @slot.takeItem
- @vault_window.refresh
- @item_window.refresh
- else
- if @vault_window.index == @vault_window.item_max - 1
- max = $game_banking.closedVaultSlots(@bankID)
- @action = 4 #buy slots
- callNumberWindow(max)
- elsif @slot == nil or @slot.locked
- Sound.play_buzzer
- else
- Sound.play_decision
- @storing = true
- @item_window.active = true
- @vault_window.active = false
- end
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Checks the item window for input when it is active
- #-----------------------------------------------------------------------------
- def update_item_selection
- if Input.trigger?(Input::B)
- Sound.play_cancel
- @storing = false
- @item_window.active = false
- @vault_window.active = true
- elsif Input.trigger?(Input::C)
- @item = @item_window.item
- max = $game_party.item_number(@item)
- @action = 5 #how many to transfer
- callNumberWindow(max)
- end
- end
- #-----------------------------------------------------------------------------
- # Checks the account command window for input when it is active
- #-----------------------------------------------------------------------------
- def update_accountCmd_selection
- if Input.trigger?(Input::B)
- Sound.play_cancel
- @accountCmd_window.visible = false
- @accountCmd_window.active = false
- @account_window.active = true
- elsif Input.trigger?(Input::C)
- @action = @accountCmd_window.index
- case @action
- when 0 # deposit
- if @account.balance == 9999999
- Sound.play_buzzer
- else
- Sound.play_decision
- if @account.type == 2
- max = [$game_party.gold, @account.balance].min
- else
- max = [$game_party.gold, 9999999 - @account.balance].min
- end
- callNumberWindow(max)
- end
- when 1 # withdraw
- if @account.type == 2 or @account.balance == 0
- Sound.play_buzzer
- else
- Sound.play_decision
- max = [9999999 - $game_party.gold, @account.balance].min
- callNumberWindow(max)
- end
- when 2 #transfer
- if @account.type == 2 or @account.balance == 0
- Sound.play_buzzer
- else
- Sound.play_decision
- @xfer = true
- @accountCmd_window.active = false
- @accountCmd_window.visible = false
- @account_window.active = true
- @account_window.refresh
- @help_window.set_text("Select a recieving account for balance transfer.")
- end
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Checks the number window for input when it is active
- #-----------------------------------------------------------------------------
- def update_number_input
- if Input.trigger?(Input::B)
- cancel_number_input
- elsif Input.trigger?(Input::C)
- decide_number_input
- end
- end
- #-----------------------------------------------------------------------------
- # Cancels the number window and restores the previous window state.
- #-----------------------------------------------------------------------------
- def cancel_number_input
- Sound.play_cancel
- @number_window.active = false
- @number_window.visible = false
- case @command_window.index
- when 0 # accounts
- @account_window.active = true
- @account_window.visible = true
- @xfer = false if @xfer
- when 1 # vault
- if @storing
- @item_window.active = true
- else
- @vault_window.active = true
- end
- @vault_window.visible = true
- @item_window.visible = true
- end
- end
- #-----------------------------------------------------------------------------
- # Confirms the number input and proccesses banking events accordingly
- #-----------------------------------------------------------------------------
- def decide_number_input
- Sound.play_shop
- @number_window.active = false
- @number_window.visible = false
- case @command_window.index
- when 0 # accounts
- if @account_window.index == @account_window.item_max - 1 #get loan
- $game_banking.makeLoan(@bankID, @rates, @number_window.number)
- $game_party.gain_gold(@number_window.number)
- else
- case @accountCmd_window.index
- when 0 #deposit
- @account.deposit(@number_window.number)
- $game_party.lose_gold(@number_window.number)
- if @account.type == 2 and @account.balance == 0
- $game_banking.bankAccounts[@bankID].delete(@account)
- end
- when 1 #withdraw(NA for loan)
- @account.withdraw(@number_window.number)
- $game_party.gain_gold(@number_window.number)
- when 2 #transfer
- @account.withdraw(@number_window.number)
- @xferAccount.deposit(@number_window.number)
- if @xferAccount.type == 2 and @xferAccount.balance == 0
- $game_banking.bankAccounts[@bankID].delete(@xferAccount)
- end
- @xfer = false
- end
- end
- @account = nil
- @xferAccount = nil
- @accountCmd_window.index = 0
- @account_window.active = true
- @account_window.visible = true
- @account_window.refresh
- @gold_window.refresh
- when 1 # vault
- if @storing
- @slot.storeItem(@item, @number_window.number)
- @storing = false
- else #must be buying slots
- purchasedSlots = @number_window.number
- $game_party.lose_gold(purchasedSlots * @slotCost)
- x = 0
- while purchasedSlots > 0
- if $game_banking.bankVaults[@bankID][x].locked
- $game_banking.bankVaults[@bankID][x].unlock
- purchasedSlots -= 1
- end
- x += 1
- end
- end
- @vault_window.active = true
- @vault_window.visible = true
- @item_window.visible = true
- @vault_window.refresh
- @item_window.refresh
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement