cooldoode325

Core Equip Slots

Feb 24th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.31 KB | None | 0 0
  1. =begin
  2. #===============================================================================
  3. Title: Core - Equip Slots
  4. Author: Tsukihime
  5. Date: Dec 10, 2013
  6. --------------------------------------------------------------------------------
  7. ** Change log
  8. Dec 10, 2013
  9. - fixed issue with battle test
  10. Nov 1, 2013
  11. - added support for setting initial equips
  12. Sep 22, 2013
  13. - added support for dual wield feature
  14. Jul 12, 2013
  15. - Initial release
  16. --------------------------------------------------------------------------------
  17. ** Terms of Use
  18. * Free to use in non-commercial projects
  19. * Contact me for commercial use
  20. * No real support. The script is provided as-is
  21. * Will do bug fixes, but no compatibility patches
  22. * Features may be requested but no guarantees, especially if it is non-trivial
  23. * Credits to Tsukihime in your project
  24. * Preserve this header
  25. --------------------------------------------------------------------------------
  26. ** Description
  27.  
  28. This script provides core functionality for extending equip slots.
  29. It improves the way equip slots are handled and allows you to assign
  30. equip slots for each actor individually. It also sorts equip slots
  31. automatically based on your order of choice.
  32.  
  33. --------------------------------------------------------------------------------
  34. ** Installation
  35.  
  36. Place this script below Materials and above Main
  37.  
  38. --------------------------------------------------------------------------------
  39. ** Usage
  40.  
  41. -- Assign initial equip slots --
  42.  
  43. Note-tag actors or classes with
  44.  
  45. <equip slot: x>
  46.  
  47. Where `x` is the equip type ID (etype ID). By default, they are as follows:
  48. 0 - weapon
  49. 1 - shield
  50. 2 - headgear
  51. 3 - bodygear
  52. 4 - accessory
  53.  
  54. Actor equip slots take precedence over class equip slots if both have been
  55. assigned. If no equip slots are assigned, then the class receives default
  56. equip slots defined in the configuration.
  57.  
  58. If you are using a custom equip script that allows you to define your own
  59. equip types, you can use those etype ID's as well.
  60.  
  61. -- Sorting equip slots --
  62.  
  63. In the configuration, there is a Sort_Order that determines how your equip
  64. slots will be sorted based on etype ID. You must provide a value for every
  65. etype ID in your project.
  66.  
  67. -- Initial equips --
  68.  
  69. You can set initial equips by specifying the item in your equip slot:
  70.  
  71. <equip slot: 0 w4>
  72. <equip slot: 1 a2>
  73.  
  74. This equips the first slot with weapon 4, and the second slot with armor 2.
  75. Note that the script currently only allows one type of equip in a slot, so
  76. you can't equip both weapons OR armors in the same slot.
  77.  
  78. #===============================================================================
  79. =end
  80. $imported = {} if $imported.nil?
  81. $imported["TH_CoreEquipSlots"] = true
  82. #===============================================================================
  83. # ** Configuration
  84. #===============================================================================
  85. module TH
  86. module Core_Equip_Slots
  87.  
  88. # Order that the equip slots will be sorted. You must include all
  89. # etype ID's defined in your project
  90. Sort_Order = [0, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
  91.  
  92. # Default slots to assign to actor if no slots are provided.
  93. Default_Slots = [0, 1, 5, 6, 7, 8, 9, 10, 11, 12, 12, 13, 14, 15]
  94.  
  95. # Assigns an equip slot
  96. Regex = /<equip[-_ ]slot:\s*(\d+)\s*(?:(.*))\s*>/i
  97.  
  98. #===============================================================================
  99. # ** Rest of script
  100. #===============================================================================
  101. def self.sort_order
  102. Sort_Order
  103. end
  104.  
  105. def initial_slots
  106. load_notetag_Core_Equip_Slots if @initial_slots.nil?
  107. return @initial_slots
  108. end
  109. end
  110. end
  111.  
  112. #-------------------------------------------------------------------------------
  113. # Load initial slots for actors and classes
  114. #-------------------------------------------------------------------------------
  115. module RPG
  116. class Actor
  117. include TH::Core_Equip_Slots
  118.  
  119. def load_notetag_Core_Equip_Slots
  120. @initial_slots = []
  121. @initial_equips = []
  122. res = self.note.scan(TH::Core_Equip_Slots::Regex)
  123. res.each do |data|
  124. @initial_slots << data[0].to_i
  125.  
  126. id = 0
  127. unless data[1].empty?
  128. type = data[1][0].downcase
  129. id = data[1][1..-1].to_i
  130. end
  131. @initial_equips << id
  132. end
  133. end
  134.  
  135. def has_slots?
  136. load_notetag_Core_Equip_Slots if @initial_slots.nil?
  137. return !@initial_slots.empty?
  138. end
  139.  
  140. alias :th_core_equip_slots_equips :equips
  141. def equips
  142. load_notetag_Core_Equip_Slots if @initial_equips.nil?
  143. @equips = @initial_equips unless @initial_equips.empty?
  144. th_core_equip_slots_equips
  145. end
  146. end
  147.  
  148. class Class
  149. include TH::Core_Equip_Slots
  150.  
  151. def load_notetag_Core_Equip_Slots
  152. @initial_slots = []
  153. res = self.note.scan(TH::Core_Equip_Slots::Regex)
  154. res.each do |data|
  155. @initial_slots << data[0].to_i
  156. end
  157. @initial_slots = Default_Slots if @initial_slots.empty?
  158. end
  159. end
  160. end
  161.  
  162. #-------------------------------------------------------------------------------
  163. # An equip slot object. Holds a Game_BaseItem object and delegates most calls
  164. # to it for backwards compatibility. The purpose of this class is to
  165. # synchronize the slot ID's and the actual equip items themselves rather than
  166. # storing them as two separate arrays in Game_Actor
  167. #-------------------------------------------------------------------------------
  168. class Game_EquipSlot
  169.  
  170. attr_reader :etype_id
  171. attr_reader :initial_etype_id
  172.  
  173. def initialize(etype_id)
  174. @etype_id = etype_id
  175. @item = Game_BaseItem.new
  176. @initial_etype_id = etype_id
  177. end
  178.  
  179. def is_skill?; @item.is_skill?; end
  180. def is_item?; @item.is_item?; end
  181. def is_weapon?; @item.is_weapon?; end
  182. def is_armor?; @item.is_armor?; end
  183. def is_nil?; @item.is_nil? end
  184.  
  185. def object
  186. @item.object
  187. end
  188.  
  189. def object=(obj)
  190. @item.object = obj
  191. end
  192.  
  193. def set_etype(etype_id)
  194. @etype_id = etype_id
  195. end
  196.  
  197. def set_equip(weapon, item_id)
  198. @item.set_equip(weapon, item_id)
  199. end
  200.  
  201. def restore_etype
  202. @etype_id = @initial_etype_id
  203. end
  204. end
  205.  
  206. #-------------------------------------------------------------------------------
  207. # Abstract the equip slots to reference actual EquipSlot objects. Also
  208. # synchronizes the slot ID's with the slot types.
  209. #-------------------------------------------------------------------------------
  210. class Game_Actor < Game_Battler
  211.  
  212. alias :th_core_equip_slots_initialize :initialize
  213. def initialize(actor_id)
  214. th_core_equip_slots_initialize(actor_id)
  215. @last_dual_weapon_status = false
  216. end
  217.  
  218. #-----------------------------------------------------------------------------
  219. # Check
  220. #-----------------------------------------------------------------------------
  221. alias :th_core_equip_slots_refresh :refresh
  222. def refresh
  223. check_equip_slots
  224. th_core_equip_slots_refresh
  225. end
  226.  
  227. #-----------------------------------------------------------------------------
  228. # Replaced. Create an array of EquipSlot objects instead of just Game_BaseItem
  229. #-----------------------------------------------------------------------------
  230. def init_equips(equips)
  231. @equips = Array.new(initial_slots.size) {|i| Game_EquipSlot.new(initial_slots[i]) }
  232. sort_equip_slots
  233. equips.each_with_index do |item_id, i|
  234. etype_id = index_to_etype_id(i)
  235. slot_id = empty_slot(etype_id)
  236. @equips[slot_id].set_equip(etype_id == 0, item_id) if slot_id
  237. end
  238. refresh
  239. end
  240.  
  241. #-----------------------------------------------------------------------------
  242. # Replaced. Etype can be retrieved from the slot directly
  243. #-----------------------------------------------------------------------------
  244. def index_to_etype_id(index)
  245. @equips[index].etype_id
  246. end
  247.  
  248. #-----------------------------------------------------------------------------
  249. # Replaced. Etype ID's are pulled from the slots themselves
  250. #-----------------------------------------------------------------------------
  251. def equip_slots
  252. @equips.collect {|slot| slot.etype_id }
  253. end
  254.  
  255. #-----------------------------------------------------------------------------
  256. # New. Returns the initial slots for the actor. Actor slots take precedence
  257. # over class slots.
  258. #-----------------------------------------------------------------------------
  259. def initial_slots
  260. return actor.initial_slots if actor.has_slots?
  261. return self.class.initial_slots
  262. end
  263.  
  264. #-----------------------------------------------------------------------------
  265. # New. Sort equip slots based on sort order
  266. #-----------------------------------------------------------------------------
  267. def sort_equip_slots
  268. @equips.sort_by! {|eslot| TH::Core_Equip_Slots.sort_order.index(eslot.etype_id)}
  269. end
  270.  
  271. #-----------------------------------------------------------------------------
  272. # New.
  273. #-----------------------------------------------------------------------------
  274. def check_equip_slots
  275. check_dual_wield_slots if @last_dual_weapon_status != dual_wield?
  276. end
  277.  
  278. #-----------------------------------------------------------------------------
  279. # New.
  280. #-----------------------------------------------------------------------------
  281. def check_dual_wield_slots
  282. @last_dual_weapon_status = dual_wield?
  283. @equips.each do |slot|
  284. if slot.initial_etype_id == 1
  285. @last_dual_weapon_status ? slot.set_etype(0) : slot.restore_etype
  286. end
  287. end
  288. end
  289. end
  290.  
  291. #-------------------------------------------------------------------------------
  292. # Adjust contents size to account for additional slots
  293. #-------------------------------------------------------------------------------
  294. class Window_EquipSlot < Window_Selectable
  295.  
  296. def refresh
  297. create_contents
  298. super
  299. end
  300. end
  301.  
  302. #===============================================================================
  303. # Compatibility with battle test
  304. #===============================================================================
  305. if $BTEST
  306. class Game_Actor < Game_Battler
  307. def index_to_etype_id(index)
  308. initial_slots[index]
  309. end
  310. end
  311. end
Advertisement
Add Comment
Please, Sign In to add comment