Guest User

Shopaholic Page 5

a guest
Jul 29th, 2012
246
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #-------------------------------------------------------------------------------
  2. # page 5 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. # This class implements bank inventories and provides access to true interest
  11. # calculations. The instance of this class is $game_banking
  12. #-------------------------------------------------------------------------------
  13. #-------------------------------------------------------------------------------
  14. #
  15. # IMPORTANT CUSOMIZATION INFORMATION:
  16. # To call a bank, use the script call:
  17. # $scene = Scene_Bank.new(bankID, rates, slotCost, loanMax, hasVault)
  18. # bankID: The ID of the bank to be shown. (you can show the same bank
  19. # In various events throughout your game, just as you can with
  20. # shops. This way, you can have 1 bank for your entire game
  21. # if you chose)
  22. # rates: An array of interest rates: [savings, checking, loan]
  23. # savings: interest rate for savings accounts at this
  24. # instance of this bank.
  25. # checking: interest rate for checking accounts at this
  26. # instance of this bank.
  27. # loan: interest rate for checking accounts at this
  28. # instance of this bank.
  29. # NOTE: If you have more than one event per bankID you can
  30. # set different interest rates at each one! (sort of like
  31. # branches of a real bank)
  32. # slotCost: Cost for each new Saftey Deposit Box in the vault
  33. # loanMax: The max amount the bank will issue in a single loan. This
  34. # overrides the global setting for max loan if it is lower.
  35. # hasVault Boolean indicating whether or not this instance of this bank
  36. # has a vault. Again if you have multiple events for a bankID
  37. # Then you can enable the vault in some while disabling it in
  38. # others and the players items will persist.
  39. #-------------------------------------------------------------------------------
  40. class Game_Banking
  41.  
  42. attr_accessor :bankAccounts
  43. attr_accessor :bankVaults
  44. attr_reader :interestTerm
  45. attr_reader :loanMax
  46. #-----------------------------------------------------------------------------
  47. # Creates the $game_banking object
  48. #-----------------------------------------------------------------------------
  49. def initialize
  50. @lastInterestTime = 0
  51.  
  52. #---------------------------------------------------------------------------
  53. # How many minutes must pass before the bank compounds interest.
  54. #---------------------------------------------------------------------------
  55. @interestTerm = 2
  56. #---------------------------------------------------------------------------
  57. # You can set a universal maximum for all loans here.
  58. #---------------------------------------------------------------------------
  59. @loanMax = 100000
  60. #---------------------------------------------------------------------------
  61. # All banks are created allowing the same account types. if you want to
  62. # disable an account type for your game, chage it's value below to false
  63. #---------------------------------------------------------------------------
  64. @allowSavings = true
  65. @allowChecking = true
  66. @allowLoans = true
  67. #---------------------------------------------------------------------------
  68. # Number of saftey deposit boxes in the vault. (multiples of 8 look best)
  69. #---------------------------------------------------------------------------
  70. @maxSlots = 64
  71. #---------------------------------------------------------------------------
  72. # Number of starting "free" slots per bank.
  73. #---------------------------------------------------------------------------
  74. @freeSlots = 4
  75.  
  76. initBanks
  77. end
  78. #-----------------------------------------------------------------------------
  79. # Sets up the banks' accounts and their vaults
  80. #-----------------------------------------------------------------------------
  81. def initBanks
  82. #---------------------------------------------------------------------------
  83. # IMPORTANT:
  84. # You will get an error when managing accounts and vaults if you try to
  85. # pass a bankID that is higher than the number of @totalBanks - 1. Set
  86. # this to the number of *different* banks in your game, or HIGHER! Setting
  87. # higher will waste memory, but you can always count up the number of
  88. # banks you have before shipping your finished game and change it back to
  89. # the correct number!
  90. # Note, if you want one "central" bank, just use the same bankID in each
  91. # bank event.
  92. #---------------------------------------------------------------------------
  93. @totalBanks = 1
  94.  
  95. @bankVaults = []
  96. @bankAccounts = []
  97. for x in 0..@totalBanks - 1
  98. @bankVaults [x] = []
  99. @bankAccounts[x] = []
  100. @bankAccounts[x].push(Account.new(0)) if @allowSavings
  101. @bankAccounts[x].push(Account.new(1)) if @allowChecking
  102. @maxSlots.times {@bankVaults[x].push(Storage_Slot.new)}
  103. for y in 0..@freeSlots - 1
  104. @bankVaults[x][y].unlock
  105. end
  106. end
  107. end
  108. #-----------------------------------------------------------------------------
  109. # Sets interest rates for each of the bank's accounts.
  110. # bankID: The ID of the bank that needs to have interest rates set
  111. # rates: An array of interest rates: [savings, checking, loan]
  112. #-----------------------------------------------------------------------------
  113. def setRates(bankID, rates)
  114. for account in @bankAccounts[bankID]
  115. account.interestRate = rates[account.type]
  116. end
  117. end
  118. #-----------------------------------------------------------------------------
  119. # Calculates interest on a bank's accounts.
  120. # bankID: The ID number of the bank whose interest needs to be calculated
  121. #-----------------------------------------------------------------------------
  122. def calcInterest(bankID)
  123. timesToCompound = 0
  124. now = Graphics.frame_count / Graphics.frame_rate
  125. while @lastInterestTime < now - (@interestTerm * 60)
  126. @lastInterestTime += @interestTerm * 60
  127. timesToCompound += 1
  128. end
  129. for x in 1..timesToCompound
  130. for account in @bankAccounts[bankID]
  131. account.compound
  132. end
  133. end
  134. end
  135. #-----------------------------------------------------------------------------
  136. # Creates a loan and adds it to the player's accounts at that bank.
  137. # bankID: The id number of the bank to add the loan to.
  138. # rates: An interest rates array: [savings, checking, loan]
  139. # amount: The amount of the loan
  140. #-----------------------------------------------------------------------------
  141. def makeLoan(bankID, rates, amount)
  142. loan = Account.new(2)
  143. loan.balance = amount
  144. loan.interestRate = rates[2]
  145. @bankAccounts[bankID].push(loan)
  146. end
  147. #-----------------------------------------------------------------------------
  148. # Returns the number of closed slots in a bank's vault
  149. # bankID: The ID number of the bank whose slots need to be checked
  150. # RETURNS: Integer (Fixnum)
  151. #-----------------------------------------------------------------------------
  152. def closedVaultSlots(bankID)
  153. closedSlots = 0
  154. for slot in @bankVaults[bankID]
  155. closedSlots += 1 if slot.locked
  156. end
  157. return closedSlots
  158. end
  159. end
RAW Paste Data