Kyriaki

Item/Equipment/Skill Conditions

Jul 1st, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.63 KB | None | 0 0
  1. #==============================================================================
  2. # ** Item/Equipment/Skill Conditions
  3. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. # This script allows you to set stats and/or level requirements for weapons
  5. # and armor
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. # Instructions:
  8. # Place above Main and below Materials
  9. #
  10. # To configure this script, you have to place codes in the Notes Field of
  11. # the respective items. These codes are:
  12. #
  13. # \LVLR[<level_requirement>] *Actor must be at least this level
  14. # \HPR[<hp_requirement>] *Actor must have this much HP
  15. # \MPR[<mp_requirement>] *Actor must have this much MP
  16. # \ATKR[<attack_requirement>] *Actor must have this much Attack
  17. # \DEFR[<defense_requirement>] *Actor must have this much Defense
  18. # \SPIR[<spirit_requirement>] *Actor must have this much Spirit
  19. # \AGIR[<agility_requirement>] *Actor must have this much Agility
  20. # \WPNR[<weapon_id>] *Weapon must be equipped
  21. # \ARMR[<armor_id>] *Armor must be equipped
  22. # \ITMR[<item_id>, <n>] *At least n of item_id in possession
  23. # \ITMR[<item_id>, <n>]C *As above and consumed upon use.
  24. # \PWPNR[<possession_weapon_id>, <n>] *At least n of weapon_id in possession
  25. # \PWPNR[<possession_weapon_id>, <n>]C *As above and consumed upon use.
  26. # \PARMR[<possession_armor_id>, <n>] *At least n of armor_id in possession
  27. # \PARMR[<possession_armor_id>, <n>]C *As above and consumed upon use.
  28. # \SKLR[<skill_id>] *Skill must be learned
  29. # \STER[<state_id>] *State must be added
  30. #
  31. # After any of them that make sense, you can also add these restrictions:
  32. # >= - greater than or equal to - default
  33. # <= - less than or equal to
  34. # > - strictly greater than
  35. # < - strictly less than
  36. # = - strictly equal to
  37. #
  38. # You can leave out any or all or none of them and the script will only
  39. # restrict the attributes you set
  40. #
  41. # EXAMPLE:
  42. # If Club has a Notes Field like this:
  43. #
  44. # \LVLR[6]<
  45. # \ATKR[37]
  46. # \AGIR[27]>
  47. #
  48. # then an actor could only use that club if he was less than level 6, had
  49. # an Attack of at least 37 and an Agility of at least 28.
  50. #==============================================================================
  51. # ** RPG::BaseItem
  52. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. # Summary of Changes
  54. # new method - requirements_field
  55. #==============================================================================
  56.  
  57. class RPG::BaseItem
  58. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. # * Requirement Field
  60. #--------------------------------------------------------------------------
  61. # This method returns an array of restrictions on using each item
  62. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. def requirement_field
  64. r_field = []
  65. # Dissect Note
  66. text = self.note.dup
  67. text.sub! (/\\lvlr\[(\d+?)\](<*>*=*)/i) { '' }
  68. r_field.push ([$1.to_i, $2.to_s])
  69. # HP Requirement
  70. text.sub! (/\\hpr\[(\d+?)\](<*>*=*)/i) { '' }
  71. r_field.push ([$1.to_i, $2.to_s])
  72. # MP Requirement
  73. text.sub! (/\\mpr\[(\d+?)\](<*>*=*)/i) { '' }
  74. r_field.push ([$1.to_i, $2.to_s])
  75. # Attack Requirement
  76. text.sub! (/\\atkr\[(\d+?)\](<*>*=*)/i) { '' }
  77. r_field.push ([$1.to_i, $2.to_s])
  78. # Defense Requirement
  79. text.sub! (/\\defr\[(\d+?)\](<*>*=*)/i) { '' }
  80. r_field.push ([$1.to_i, $2.to_s])
  81. # Spirit Requirement
  82. text.sub! (/\\spir\[(\d+?)\](<*>*=*)/i) { '' }
  83. r_field.push ([$1.to_i, $2.to_s])
  84. # Agility Requirement
  85. text.sub! (/\\agir\[(\d+?)\](<*>*=*)/i) { '' }
  86. r_field.push ([$1.to_i, $2.to_s])
  87. r_field.push ([], [], [], [], [], [], [], [], [], [])
  88. # Weapon Requirement
  89. r_field[7].push ($1.to_i) while text.sub! (/\\wpnr\[(\d+?)\]/i) {''} != nil
  90. # Armor Requirement
  91. r_field[8].push ($1.to_i) while text.sub! (/\\armr\[(\d+?)\]/i) {''} != nil
  92. # Item Possession Requirement
  93. while text.sub! (/\\itmr\[(\d+),*\s*(\d*)\](C*)(<*>*=*)/i) { '' } != nil
  94. r_field[9].push ([$1.to_i, [$2.to_i, 1].max, $4.to_s])
  95. # Consumable items
  96. r_field[14].push ([$1.to_i, [$2.to_i, 1].max, $4.to_s]) if $3 != ""
  97. end
  98. # Weapon Possession Requirement
  99. while text.sub! (/pwpnr\[(\d+),*\s*(\d*)\](C*)(<*>*=*)/i) {''} != nil
  100. r_field[10].push ([$1.to_i, [$2.to_i, 1].max, $4.to_s])
  101. # Consumable weapons
  102. r_field[15].push ([$1.to_i, [$2.to_i, 1].max, $4.to_s]) if $3 != nil
  103. end
  104. # Armor Possession Requirement
  105. while text.sub! (/parmr\[(\d+),*\s*(\d*)\](C*)(<*>*=*)/i) {''} != nil
  106. r_field[11].push ([$1.to_i, [$2.to_i, 1].max, $4.to_s])
  107. # Consumable Armors\
  108. r_field[16].push ([$1.to_i, [$2.to_i, 1].max, $4.to_s]) if $3 != nil
  109. end
  110. # Skill Requirement
  111. r_field[12].push ($1.to_i) while text.sub! (/\\sklr\[(\d+?)\]/i) {''} != nil
  112. # State Requirement
  113. r_field[13].push ($1.to_i) while text.sub! (/\\ster\[(\d+?)\]/i) {''} != nil
  114. return r_field
  115. end
  116. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  117. # * Check requirements
  118. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. def check_reqs (user)
  120. actor_stats = [user.level, user.maxhp, user.maxmp, user.atk, user.def, user.spi, user.agi]
  121. reqs = self.requirement_field
  122. # Stats
  123. for i in 0...7
  124. case reqs[i][1]
  125. when "" # Assume Greater than or Equal to
  126. return false unless actor_stats[i] >= reqs[i][0]
  127. else # Other
  128. begin
  129. eval ("return false unless actor_stats[i] #{reqs[i][1]} reqs[i][0]")
  130. rescue
  131. end
  132. end
  133. end
  134. data = [$data_items, $data_weapons, $data_armors]
  135. # Weapons and Armor equips
  136. for i in 7...9
  137. reqs[i].each { |j|
  138. return false unless user.equips.include? (data[i-6][j])
  139. }
  140. end
  141. # Items, Weapons, Armors in possession
  142. for i in 9...12
  143. reqs[i].each { |j|
  144. case j[2]
  145. when ""
  146. return false unless $game_party.item_number (data[i-9][j[0]]) >= j[1]
  147. else
  148. begin
  149. eval ("return false unless $game_party.item_number (data[i-9][j[0]]) #{j[2]} j[1]")
  150. rescue
  151. end
  152. end
  153. }
  154. end
  155. # Skills learned
  156. self.requirement_field[12].each { |i| return false unless user.skill_learn? ($data_skills[i]) }
  157. # States
  158. self.requirement_field[13].each { |i| return false unless user.state? (i) }
  159. return true
  160. end
  161. end
  162.  
  163. #==============================================================================
  164. # ** Game_Actor
  165. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  166. # Summary of Changes:
  167. # new method - check_reqs, consume_reagants
  168. # aliased_methods - equippable?, setup, level_down, maxhp=, maxmp=, atk=,
  169. # def=, spi=, agi=
  170. # modified super - skill_effect, item_effect, skill_can_use?, item_effective?
  171. #==============================================================================
  172.  
  173. class Game_Actor < Game_Battler
  174. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175. # * Setup
  176. # actor_id : actor ID
  177. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  178. alias modalg_equip_required_actor_stp_7ht1 setup
  179. def setup (actor_id)
  180. # Run Original Method
  181. modalg_equip_required_actor_stp_7ht1 (actor_id)
  182. # Make sure all starting items are allowed to be on the hero
  183. check_equip_reqs
  184. end
  185. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  186. # * Determine if Equippable
  187. # item : item
  188. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  189. alias modalg_eqp_reqs_actor_check_equip_5js9 equippable?
  190. def equippable?(item)
  191. return false if item == nil
  192. return modalg_eqp_reqs_actor_check_equip_5js9 (item) & item.check_reqs (self)
  193. end
  194. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195. # * Determine Usable Skills
  196. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  197. def skill_can_use? (skill)
  198. test = super (skill)
  199. return skill.check_reqs (self) if test
  200. return test
  201. end
  202. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  203. # * Determine if an Item can be Used
  204. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  205. def item_effective?(user, item)
  206. return super (user, item) if user.is_a? (Game_Enemy)
  207. return super (user, item) & item.check_reqs (user)
  208. end
  209. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  210. # * Apply Item Effects
  211. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  212. def item_effect(user, item)
  213. super (user, item)
  214. # Consume reagants if consumable
  215. consume_reagants (item)
  216. end
  217. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218. # * Apply Skill Effects
  219. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  220. def skill_effect(user, skill)
  221. super (user, skill)
  222. # Consume reagants if consumable
  223. consume_reagants (skill)
  224. end
  225. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226. # * Check Equipment Requirements
  227. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  228. def check_equip_reqs
  229. @checking_equipment = true
  230. equip_array = equips.dup
  231. for i in 0...5
  232. # Unequip everything
  233. change_equip (i, nil, true)
  234. test = equippable? (equip_array[i])
  235. change_equip (i, equip_array[i], true)
  236. # Unequip item for real if requirements not met
  237. change_equip (i, nil) unless test
  238. end
  239. @checking_equipment = false
  240. end
  241. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  242. # * Consume Reagants
  243. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  244. def consume_reagants (item)
  245. unless @skipped || @missed || @evaded
  246. # Remove items, weapons, and armors
  247. item.requirement_field[14].each { |i| $game_party.lose_item ($data_items[i[0]], i[1]) }
  248. item.requirement_field[15].each { |i| $game_party.lose_item ($data_weapons[i[0]], i[1]) }
  249. item.requirement_field[16].each { |i| $game_party.lose_item ($data_armors[i[0]], i[1]) }
  250. end
  251. end
  252. #--------------------------------------------------------------------------
  253. # * Make sure requirements still met if stats decrease in any way
  254. #--------------------------------------------------------------------------
  255. alias modalg_eqpreqs_lvlup_check_9dn4 level_up
  256. def level_up
  257. modalg_eqpreqs_lvlup_check_9dn4
  258. check_equip_reqs
  259. end
  260.  
  261. alias modalg_equip_reqs_changelvl_check_5hy2 level_down
  262. def level_down
  263. modalg_equip_reqs_changelvl_check_5hy2
  264. check_equip_reqs
  265. end
  266.  
  267. alias modalg_equip_reqs_changemaxhp_check_h83d maxhp=
  268. def maxhp=(new_maxhp)
  269. modalg_equip_reqs_changemaxhp_check_h83d (new_maxhp)
  270. check_equip_reqs
  271. end
  272.  
  273. alias modalg_equip_reqs_changemxmp_check_8fjq maxmp=
  274. def maxmp=(new_maxmp)
  275. modalg_equip_reqs_changemxmp_check_8fjq (new_maxmp)
  276. check_equip_reqs
  277. end
  278.  
  279. alias modalg_equip_reqs_change_atk_94nd atk=
  280. def atk=(new_atk)
  281. modalg_equip_reqs_change_atk_94nd (new_atk)
  282. check_equip_reqs
  283. end
  284.  
  285. alias modernalg_chck_reqs_def_73ij def=
  286. def def=(new_def)
  287. modernalg_chck_reqs_def_73ij (new_def)
  288. check_equip_reqs
  289. end
  290.  
  291. alias modalgebra_reqs_chck_sprit_8dsn spi=
  292. def spi=(new_spi)
  293. modalgebra_reqs_chck_sprit_8dsn (new_spi)
  294. check_equip_reqs
  295. end
  296.  
  297. alias modalgebra_requirements_equipment_agi_6hdt agi=
  298. def agi=(new_agi)
  299. modalgebra_requirements_equipment_agi_6hdt (new_agi)
  300. check_equip_reqs
  301. end
  302.  
  303. alias ma_chck_eqp_reqs_chnge_equip_7fn change_equip
  304. def change_equip (equip_type, item, test = false)
  305. ma_chck_eqp_reqs_chnge_equip_7fn (equip_type, item, test)
  306. check_equip_reqs if @checking_equipment == nil || !@checking_equipment && !test
  307. end
  308.  
  309. alias ma_frgt_skill_check_eqp_reqs_8her forget_skill
  310. def forget_skill (skill_id)
  311. ma_frgt_skill_check_eqp_reqs_8her (skill_id)
  312. check_equip_reqs if @checking_equipment == nil || !@checking_equipment
  313. end
  314. end
  315.  
  316. #==============================================================================
  317. # ** Game_Party
  318. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  319. # Summary of Changes:
  320. # aliased methods - item_can_use?
  321. #==============================================================================
  322.  
  323. class Game_Party
  324. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  325. # * Item Can Use?
  326. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  327. alias modalg_req_itm_party_use_9m43 item_can_use?
  328. def item_can_use? (item)
  329. # Run Original Method
  330. test = modalg_req_itm_party_use_9m43 (item)
  331. return false unless test
  332. if $game_temp.in_battle
  333. return test & item.check_reqs ($scene.active_battler)
  334. else
  335. $game_party.members.each { |i| return test if item.check_reqs (i) }
  336. return false
  337. end
  338. end
  339. end
  340.  
  341. #==============================================================================
  342. # ** Scene_Battle
  343. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  344. # Summary of Changes:
  345. # makes public - active_battler
  346. #==============================================================================
  347.  
  348. class Scene_Battle < Scene_Base
  349. attr_reader :active_battler
  350. end
  351.  
  352. #==============================================================================
  353. # ** Scene_Item
  354. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  355. # Summary of Changes:
  356. # aliased method - use_item_nontarget
  357. #==============================================================================
  358.  
  359. class Scene_Item < Scene_Base
  360. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  361. # * Use Item (apply effects to non-ally targets)
  362. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  363. alias modalg_eqp_reqs_consume_regnts_refresh_rn4 use_item_nontarget
  364. def use_item_nontarget
  365. # Run Original Method
  366. modalg_eqp_reqs_consume_regnts_refresh_rn4
  367. # Refresh Item Window
  368. @item_window.refresh
  369. end
  370. end
Advertisement
Add Comment
Please, Sign In to add comment