Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # page 5 of 12
- # Shopoholic v 2.0
- # code by cmpsr2000
- # available exclusively @ rpgrevolution.com/forums
- # Released June 25, 2008
- #
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # This class implements bank inventories and provides access to true interest
- # calculations. The instance of this class is $game_banking
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- #
- # IMPORTANT CUSOMIZATION INFORMATION:
- # To call a bank, use the script call:
- # $scene = Scene_Bank.new(bankID, rates, slotCost, loanMax, hasVault)
- # 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.
- #-------------------------------------------------------------------------------
- class Game_Banking
- attr_accessor :bankAccounts
- attr_accessor :bankVaults
- attr_reader :interestTerm
- attr_reader :loanMax
- #-----------------------------------------------------------------------------
- # Creates the $game_banking object
- #-----------------------------------------------------------------------------
- def initialize
- @lastInterestTime = 0
- #---------------------------------------------------------------------------
- # How many minutes must pass before the bank compounds interest.
- #---------------------------------------------------------------------------
- @interestTerm = 2
- #---------------------------------------------------------------------------
- # You can set a universal maximum for all loans here.
- #---------------------------------------------------------------------------
- @loanMax = 100000
- #---------------------------------------------------------------------------
- # All banks are created allowing the same account types. if you want to
- # disable an account type for your game, chage it's value below to false
- #---------------------------------------------------------------------------
- @allowSavings = true
- @allowChecking = true
- @allowLoans = true
- #---------------------------------------------------------------------------
- # Number of saftey deposit boxes in the vault. (multiples of 8 look best)
- #---------------------------------------------------------------------------
- @maxSlots = 64
- #---------------------------------------------------------------------------
- # Number of starting "free" slots per bank.
- #---------------------------------------------------------------------------
- @freeSlots = 4
- initBanks
- end
- #-----------------------------------------------------------------------------
- # Sets up the banks' accounts and their vaults
- #-----------------------------------------------------------------------------
- def initBanks
- #---------------------------------------------------------------------------
- # IMPORTANT:
- # You will get an error when managing accounts and vaults if you try to
- # pass a bankID that is higher than the number of @totalBanks - 1. Set
- # this to the number of *different* banks in your game, or HIGHER! Setting
- # higher will waste memory, but you can always count up the number of
- # banks you have before shipping your finished game and change it back to
- # the correct number!
- # Note, if you want one "central" bank, just use the same bankID in each
- # bank event.
- #---------------------------------------------------------------------------
- @totalBanks = 1
- @bankVaults = []
- @bankAccounts = []
- for x in 0..@totalBanks - 1
- @bankVaults [x] = []
- @bankAccounts[x] = []
- @bankAccounts[x].push(Account.new(0)) if @allowSavings
- @bankAccounts[x].push(Account.new(1)) if @allowChecking
- @maxSlots.times {@bankVaults[x].push(Storage_Slot.new)}
- for y in 0..@freeSlots - 1
- @bankVaults[x][y].unlock
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Sets interest rates for each of the bank's accounts.
- # bankID: The ID of the bank that needs to have interest rates set
- # rates: An array of interest rates: [savings, checking, loan]
- #-----------------------------------------------------------------------------
- def setRates(bankID, rates)
- for account in @bankAccounts[bankID]
- account.interestRate = rates[account.type]
- end
- end
- #-----------------------------------------------------------------------------
- # Calculates interest on a bank's accounts.
- # bankID: The ID number of the bank whose interest needs to be calculated
- #-----------------------------------------------------------------------------
- def calcInterest(bankID)
- timesToCompound = 0
- now = Graphics.frame_count / Graphics.frame_rate
- while @lastInterestTime < now - (@interestTerm * 60)
- @lastInterestTime += @interestTerm * 60
- timesToCompound += 1
- end
- for x in 1..timesToCompound
- for account in @bankAccounts[bankID]
- account.compound
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Creates a loan and adds it to the player's accounts at that bank.
- # bankID: The id number of the bank to add the loan to.
- # rates: An interest rates array: [savings, checking, loan]
- # amount: The amount of the loan
- #-----------------------------------------------------------------------------
- def makeLoan(bankID, rates, amount)
- loan = Account.new(2)
- loan.balance = amount
- loan.interestRate = rates[2]
- @bankAccounts[bankID].push(loan)
- end
- #-----------------------------------------------------------------------------
- # Returns the number of closed slots in a bank's vault
- # bankID: The ID number of the bank whose slots need to be checked
- # RETURNS: Integer (Fixnum)
- #-----------------------------------------------------------------------------
- def closedVaultSlots(bankID)
- closedSlots = 0
- for slot in @bankVaults[bankID]
- closedSlots += 1 if slot.locked
- end
- return closedSlots
- end
- end
RAW Paste Data