blucalm

Unique Items 13 Dec 12 Upg Equips Compat

Dec 13th, 2012
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.41 KB | None | 0 0
  1. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  2. # Custom DM add-on
  3. # Author: Eshra
  4. # First Version: 30 Oct. 2012
  5. # Compatibility: RPG Maker VX Ace
  6. # Dependencies:
  7. # 1. Tsuki_CustomDataManager
  8. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  9. #
  10. #------------------------------------------------------------------------------
  11. # * How to Use
  12. #------------------------------------------------------------------------------
  13. # This script is for use with the custom database/manager, it provides a notetag
  14. # to label a specific item in the database as unique
  15. #
  16. # <Unique>
  17. #
  18. # Once in the party's inventory, the unique item exists as a separate entity in
  19. # the database, when it is removed from the party's inventory it is removed from
  20. # the database. If properties of the unique item are changed, it will have no
  21. # effect on new instances of that type of item.
  22. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  23. #
  24. # Original Release Date: Unreleased
  25. #
  26. # Update Log:
  27. # 13 Dec. 2012 Added calls to CleanCDB instead of removing custom items from
  28. # the database incorrectly as I was before.
  29. # 3 Nov. 2012 - Fixed problem occuring when adding more than one unique item to
  30. # the party's inventory
  31. # 30 Oct. 2012 - First version completed
  32. #
  33. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  34. $imported ||= {}
  35. raise "Tsuki_CustomDataManager is required for the DM add-on" if !$imported["Tsuki_CustomDataManager"]
  36. $imported["Ra Custom DM add-on"] = 0.2
  37.  
  38. module Era
  39. CleanCDB_Amt = 400 # number of unique items needed to be gained before cleaning
  40. end
  41. #==============================================================================
  42. # ** Unique RPG BaseItem
  43. #==============================================================================
  44. module UniqueRPGBI
  45. RE = /<Unique>/i
  46. end # UniqueRPGBI
  47. #==============================================================================
  48. # ** RPG::BaseItem
  49. #==============================================================================
  50. class RPG::BaseItem
  51. attr_accessor :is_unique_rpgbi
  52. attr_accessor :id
  53. #----------------------------------------------------------------------------
  54. # * Is a Potential Unique Item? - Check if this obj. can show up in the
  55. # party's inventory.
  56. #----------------------------------------------------------------------------
  57. def valid_uniq_party_item?
  58. self.is_a?(RPG::Item) || self.is_a?(RPG::Armor) || self.is_a?(RPG::Weapon)
  59. end # valid_uniq_party_item?
  60.  
  61. end # RPG::BaseItem
  62. #==============================================================================
  63. # ** RPG::Item
  64. #==============================================================================
  65. class RPG::Item < RPG::UsableItem
  66. #----------------------------------------------------------------------------
  67. # * Add to Custom Database
  68. #----------------------------------------------------------------------------
  69. def add_to_dbases
  70. return if @is_upg_dupe
  71. self.id = $data_items.length
  72. $custom_items.push(self)
  73. $data_items.push(self)
  74. end
  75. #----------------------------------------------------------------------------
  76. # * Remove From Custom Database
  77. #----------------------------------------------------------------------------
  78. def sub_fr_dbase
  79. return if @is_upg_dupe
  80. # $custom_items.delete(self)
  81. end # sub_fr_dbase
  82.  
  83. end # RPG::Item
  84. #==============================================================================
  85. # ** RPG::Armor
  86. #==============================================================================
  87. class RPG::Armor < RPG::EquipItem
  88. #----------------------------------------------------------------------------
  89. # * Add to Custom Database
  90. #----------------------------------------------------------------------------
  91. def add_to_dbases
  92. return if @is_upg_dupe # for compatibility with upg equips script
  93. self.id = $data_armors.length
  94. $custom_armors.push(self)
  95. $data_armors.push(self)
  96. end
  97. #----------------------------------------------------------------------------
  98. # * Remove From Custom Database
  99. #----------------------------------------------------------------------------
  100. def sub_fr_dbase
  101. return if @is_upg_dupe
  102. end # sub_fr_dbase
  103.  
  104. end # RPG::Armor
  105. #==============================================================================
  106. # ** RPG::Weapon
  107. #==============================================================================
  108. class RPG::Weapon < RPG::EquipItem
  109.  
  110. #----------------------------------------------------------------------------
  111. # * Add to Custom Database
  112. #----------------------------------------------------------------------------
  113. def add_to_dbases
  114. return if @is_upg_dupe
  115. self.id = $data_weapons.length
  116. $custom_weapons.push(self)
  117. $data_weapons.push(self)
  118. end
  119. #----------------------------------------------------------------------------
  120. # * Remove From Custom Database
  121. #----------------------------------------------------------------------------
  122. def sub_fr_dbase
  123. return if @is_upg_dupe
  124. end # sub_fr_dbase
  125.  
  126. end # RPG::Weapon
  127.  
  128. #==============================================================================
  129. # ** DataManager
  130. #==============================================================================
  131. module DataManager
  132. class << self
  133. alias ldb_ntags_unique_rpgbi_voldb load_database
  134. end
  135. #----------------------------------------------------------------------------
  136. # * Load Database
  137. #----------------------------------------------------------------------------
  138. def self.load_database
  139. ldb_ntags_unique_rpgbi_voldb
  140. ld_vol_db_ntags_uniquerpgi
  141. end
  142. #----------------------------------------------------------------------------
  143. # * Load Tags
  144. #----------------------------------------------------------------------------
  145. def self.ld_vol_db_ntags_uniquerpgi
  146. iter = [$data_items, $data_weapons, $data_armors]
  147. iter.each{ |set|
  148. set.each do |item|
  149. next unless item
  150. item.note.split(/[\r\n]+/).each{ |line|
  151. case line
  152. when UniqueRPGBI::RE
  153. item.is_unique_rpgbi = true
  154. end
  155. }
  156. end
  157. }
  158. end # ld_vol_db_ntags_uniquerpgi
  159.  
  160. end # DataManager
  161. #==============================================================================
  162. # * Game_Party
  163. #==============================================================================
  164. class Game_Party < Game_Unit
  165.  
  166. # Modify gain_item, remove the item from the volatile DB when the party
  167. # no longer has any of them.
  168.  
  169. # Make a new entry in the db when the party gains a unique item and modify the
  170. # id of that item such that it is the largest in the db
  171.  
  172. #----------------------------------------------------------------------------
  173. # * Alias - gain_item
  174. #----------------------------------------------------------------------------
  175. alias gain_itm_unique_rpgbi_era gain_item
  176. def gain_item(item, amount, include_equip = false)
  177.  
  178.  
  179. if amount > 1
  180. amount.times{ gain_item(item, 1, include_equip) }
  181. return
  182. end
  183.  
  184. item = try_to_eval_unique(item, amount)
  185. gain_itm_unique_rpgbi_era(item, amount, include_equip=false)
  186.  
  187. # Clean up the databases if over 200 unique items have been gained
  188. @num_uniques||=0;
  189. @num_uniques+=1 if item && item.is_unique_rpgbi
  190. if $imported["Ra CleanCDB"] && @num_uniques > Era::CleanCDB_Amt
  191. Era::CleanCDB.clean; @num_uniques = 0
  192. end
  193.  
  194. end
  195. #----------------------------------------------------------------------------
  196. # * Each unique item gets a separate slot in the db
  197. #----------------------------------------------------------------------------
  198. def try_to_eval_unique(item, amount)
  199. return item unless !item.nil? && item.is_unique_rpgbi
  200. item = Marshal.load(Marshal.dump(old_item = item))
  201. delete_cust_item?(item,amount) ? old_item.sub_fr_dbase : item.add_to_dbases
  202. item
  203. end
  204. #----------------------------------------------------------------------------
  205. # * Check to Remove Custom Item From Database
  206. #----------------------------------------------------------------------------
  207. def delete_cust_item?(item, amount)
  208. !item.nil? && item.valid_uniq_party_item? && -amount >= item_number(item) &&
  209. item.is_unique_rpgbi
  210. end # delete_custom?
  211.  
  212. end # Game_Party
  213.  
  214. # End of File
Advertisement
Add Comment
Please, Sign In to add comment