blucalm

Custom DM add-on

Nov 7th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.73 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: 7 Nov. 2012
  25. #
  26. # Update Log:
  27. # 3 Nov. 2012 - Fixed problem occuring when adding more than one unique item to
  28. # the party's inventory
  29. # 30 Oct. 2012 - First version completed
  30. #
  31. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  32. $imported ||= {}
  33. raise "Tsuki_CustomDataManager is required for the DM add-on" if !$imported["Tsuki_CustomDataManager"]
  34. $imported["(~^_^)~Custom DM add-on"] = 0.1
  35.  
  36. #==============================================================================
  37. # ** Unique RPG BaseItem
  38. #==============================================================================
  39. module UniqueRPGBI
  40. RE = /<Unique>/
  41. end # UniqueRPGBI
  42. #==============================================================================
  43. # ** RPG::BaseItem
  44. #==============================================================================
  45. class RPG::BaseItem
  46. attr_accessor :is_unique_rpgbi
  47. attr_accessor :id
  48. #----------------------------------------------------------------------------
  49. # * Is a Potential Unique Item? - Check if this obj. can show up in the
  50. # party's inventory.
  51. #----------------------------------------------------------------------------
  52. def valid_uniq_party_item?
  53. self.is_a?(RPG::Item) || self.is_a?(RPG::Armor) || self.is_a?(RPG::Weapon)
  54. end # valid_uniq_party_item?
  55.  
  56. end # RPG::BaseItem
  57. #==============================================================================
  58. # ** RPG::Item
  59. #==============================================================================
  60. class RPG::Item < RPG::UsableItem
  61. #----------------------------------------------------------------------------
  62. # * Add to Custom Database
  63. #----------------------------------------------------------------------------
  64. def add_to_dbases
  65. self.id = $data_items.length
  66. $custom_items.push(self)
  67. $data_items.push(self)
  68. end
  69. #----------------------------------------------------------------------------
  70. # * Remove From Custom Database
  71. #----------------------------------------------------------------------------
  72. def sub_fr_dbase
  73. $custom_items.delete(self)
  74. end # sub_fr_dbase
  75.  
  76. end # RPG::Item
  77. #==============================================================================
  78. # ** RPG::Armor
  79. #==============================================================================
  80. class RPG::Armor < RPG::EquipItem
  81. #----------------------------------------------------------------------------
  82. # * Add to Custom Database
  83. #----------------------------------------------------------------------------
  84. def add_to_dbases
  85. self.id = $data_armors.length
  86. $custom_armors.push(self)
  87. $data_armors.push(self)
  88. end
  89. #----------------------------------------------------------------------------
  90. # * Remove From Custom Database
  91. #----------------------------------------------------------------------------
  92. def sub_fr_dbase
  93. $custom_armors.delete(self)
  94. end # sub_fr_dbase
  95.  
  96. end # RPG::Armor
  97. #==============================================================================
  98. # ** RPG::Weapon
  99. #==============================================================================
  100. class RPG::Weapon < RPG::EquipItem
  101.  
  102. #----------------------------------------------------------------------------
  103. # * Add to Custom Database
  104. #----------------------------------------------------------------------------
  105. def add_to_dbases
  106. self.id = $data_weapons.length
  107. $custom_weapons.push(self)
  108. $data_weapons.push(self)
  109. end
  110. #----------------------------------------------------------------------------
  111. # * Remove From Custom Database
  112. #----------------------------------------------------------------------------
  113. def sub_fr_dbase
  114. $custom_weapons.delete(self)
  115. end # sub_fr_dbase
  116.  
  117. end # RPG::Weapon
  118.  
  119. #==============================================================================
  120. # ** DataManager
  121. #==============================================================================
  122. module DataManager
  123. class << self
  124. alias ldb_ntags_unique_rpgbi_voldb load_database
  125. end
  126. #----------------------------------------------------------------------------
  127. # * Load Database
  128. #----------------------------------------------------------------------------
  129. def self.load_database
  130. ldb_ntags_unique_rpgbi_voldb
  131. ld_vol_db_ntags_uniquerpgi
  132. end
  133. #----------------------------------------------------------------------------
  134. # * Load Tags
  135. #----------------------------------------------------------------------------
  136. def self.ld_vol_db_ntags_uniquerpgi
  137. iter = [$data_items, $data_weapons, $data_armors]
  138. iter.each{ |set|
  139. set.each{ |item|
  140. next unless item
  141. item.note.split(/[\r\n]+/).each{ |line|
  142. case line
  143. when UniqueRPGBI::RE
  144. item.is_unique_rpgbi = true
  145. end
  146. }
  147. }
  148. }
  149. end # ld_vol_db_ntags_uniquerpgi
  150.  
  151. end # DataManager
  152. #==============================================================================
  153. # * Game_Party
  154. #==============================================================================
  155. class Game_Party < Game_Unit
  156.  
  157. # Modify gain_item, remove the item from the volatile DB when the party
  158. # no longer has any of them.
  159.  
  160. # Make a new entry in the db when the party gains a unique item and modify the
  161. # id of that item such that it is the largest in the db
  162.  
  163. #----------------------------------------------------------------------------
  164. # * Alias - gain_item
  165. #----------------------------------------------------------------------------
  166. alias gain_itm_unique_rpgbi_era gain_item
  167. def gain_item(item, amount, include_equip = false)
  168. if amount > 1
  169. amount.times{ gain_item(item, 1, include_equip) }
  170. return
  171. end
  172.  
  173. item = try_to_eval_unique(item, amount)
  174. gain_itm_unique_rpgbi_era(item, amount, include_equip=false)
  175. end
  176. #----------------------------------------------------------------------------
  177. # * Each unique item gets a separate slot in the db
  178. #----------------------------------------------------------------------------
  179. def try_to_eval_unique(item, amount)
  180. return item unless !item.nil? && item.is_unique_rpgbi
  181. item = Marshal.load(Marshal.dump(item))
  182. delete_cust_item?(item,amount) ? item.sub_fr_dbase : item.add_to_dbases
  183. item
  184. end
  185. #----------------------------------------------------------------------------
  186. # * Check to Remove Custom Item From Database
  187. #----------------------------------------------------------------------------
  188. def delete_cust_item?(item, amount)
  189. !item.nil? && item.valid_uniq_party_item? && -amount >= item_number(item) &&
  190. item.is_unique_rpgbi
  191. end # delete_custom?
  192.  
  193. end # Game_Party
  194.  
  195. # End of File
Advertisement
Add Comment
Please, Sign In to add comment