pigu_6

MR.Bubble| Functions reader

Nov 23rd, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.40 KB | None | 0 0
  1. # ╔═══════════════════════════════════════════════════════╤══════╤═══════════╗
  2. # ║ Reader Functions for Features/Effects │ v1.2 │ (9/04/12) ║
  3. # ╚═══════════════════════════════════════════════════════╧══════╧═══════════╝
  4. # Script by:
  5. # Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
  6. #--------------------------------------------------------------------------
  7. # This is a scripter's tool. This means programming knowledge and Ruby
  8. # knowledge are required to understand and utilize this script. This script
  9. # does nothing by itself.
  10. #
  11. # If you are a regular user using this script for another existing script,
  12. # you don't need to do anything with this script. Just install it in your
  13. # script editor and leave it alone.
  14. #
  15. # All RPG::BaseItem objects have an array of RPG::BaseItem::Feature objects
  16. # that contain all Feature properties defined by the developer in the
  17. # database. Unfortunately, the way Feature objects is coded makes it not
  18. # immediately understandable by humans. It requires checking the methods in
  19. # Game_BattlerBase and Game_Battler to decipher what the values in a Feature
  20. # mean. This makes trying to display a specific object's features difficult
  21. # to accomplish.
  22. #
  23. # This script is essentially a collection of wrapper functions based off the
  24. # methods defined in Game_BattlerBase and Game_Battler. This was mostly a
  25. # copy and paste job and most of the return values are similar to the ones
  26. # from those original classes.
  27. #
  28. # For example, if you have a $data_items object, you can do
  29. #
  30. # $data_items[id].hp_recovery
  31. #
  32. # to directly get that item's total HP recovery value. There are many
  33. # other usable methods.
  34. #
  35. # RPG::UsableItem objects do not have Features, but have a similar inner
  36. # class called RPG::UsableItem::Effect which have their own reader
  37. # functions.
  38. #
  39. # This script was made for my own use, but other scripters can use it
  40. # if they want.
  41. #--------------------------------------------------------------------------
  42. # ++ Changelog ++
  43. #--------------------------------------------------------------------------
  44. # v1.2 : "tp_gain" has changed to "tp_recovery". (9/04/2012)
  45. # v1.1 : Bugfix: Arrays no longer return an array of arrays. (8/23/2012)
  46. # v1.0 : Initial release. (8/20/2012)
  47. #--------------------------------------------------------------------------
  48. # ++ Installation ++
  49. #--------------------------------------------------------------------------
  50. # Install this script in the Materials section in your project's
  51. # script editor.
  52. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  53. # ++ Methods ++
  54. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  55. # The following methods are for any RPG::BaseItem object:
  56. #
  57. # param(param_id)
  58. # param_id is a value between 0~7. Not to be confused with the standard
  59. # param methods, this method returns the rate modifier for the given
  60. # parameter. Param rates start at 1.0 by default.
  61. #
  62. # xparam(xparam_id)
  63. # xparam_id is a value between 0~9. Ex-Parameters start at 0.0 by default.
  64. #
  65. # sparam(sparam_id)
  66. # sparam_id is a value between 0~9. Sp-Parameters start at 1.0 by default.
  67. #
  68. # mhp # MHP Maximum Hit Points
  69. # mmp # MMP Maximum Magic Points
  70. # atk # ATK ATtacK power
  71. # def # DEF DEFense power
  72. # mat # MAT Magic ATtack power
  73. # mdf # MDF Magic DeFense power
  74. # agi # AGI AGIlity
  75. # luk # LUK LUcK
  76. # In general, anything that is not an RPG::EquipItem object will return 0.
  77. #
  78. # hit # HIT HIT rate
  79. # eva # EVA EVAsion rate
  80. # cri # CRI CRItical rate
  81. # cev # CEV Critical EVasion rate
  82. # mev # MEV Magic EVasion rate
  83. # mrf # MRF Magic ReFlection rate
  84. # cnt # CNT CouNTer attack rate
  85. # hrg # HRG Hp ReGeneration rate
  86. # mrg # MRG Mp ReGeneration rate
  87. # trg # TRG Tp ReGeneration rate
  88. # Ex-Parameters start at 0.0 by default.
  89. #
  90. # tgr # TGR TarGet Rate
  91. # grd # GRD GuaRD effect rate
  92. # rec # REC RECovery effect rate
  93. # pha # PHA PHArmacology
  94. # mcr # MCR Mp Cost Rate
  95. # tcr # TCR Tp Charge Rate
  96. # pdr # PDR Physical Damage Rate
  97. # mdr # MDR Magical Damage Rate
  98. # fdr # FDR Floor Damage Rate
  99. # exr # EXR EXperience Rate
  100. # Sp-Paramters start at 1.0 by default.
  101. #
  102. # mhp_rate # MHP Maximum Hit Points rate
  103. # mmp_rate # MMP Maximum Magic Points rate
  104. # atk_rate # ATK ATtacK power rate
  105. # def_rate # DEF DEFense power rate
  106. # mat_rate # MAT Magic ATtack power rate
  107. # mdf_rate # MDF Magic DeFense power rate
  108. # agi_rate # AGI AGIlity rate
  109. # luk_rate # LUK LUcK rate
  110. # Not to be confused with the standard param methods, these methods
  111. # return the rate modifier for the given parameter. Param rates start
  112. # at 1.0 by default.
  113. #
  114. # dual_wield?
  115. # auto_battle?
  116. # guard?
  117. # substitute?
  118. # preserve_tp?
  119. # encounter_half?
  120. # encounter_none?
  121. # cancel_surprise?
  122. # raise_preemptive?
  123. # gold_double?
  124. # drop_item_double?
  125. # Returns true if that specified Feature flag is found. Otherwise, false.
  126. #
  127. # get_feature_flags
  128. # Returns an array of keys that each represent a Feature flag. If the
  129. # key is included in the array, it means the flag is true. Possible keys
  130. # are:
  131. # :dual_wield
  132. # :auto_battle
  133. # :guard
  134. # :substitute
  135. # :preserve_tp
  136. # :encounter_half
  137. # :encounter_none
  138. # :cancel_surprise
  139. # :raise_preemptive
  140. # :gold_double
  141. # :drop_item_double
  142. #
  143. # element_rate(element_id)
  144. # Returns the element modifier rate for a given element_id. A value
  145. # of 1.0 means no change.
  146. #
  147. # debuff_rate(param_id)
  148. # Returns the debuff modifier rate for a given param_id. A value of
  149. # 1.0 means no change.
  150. #
  151. # state_rate(state_id)
  152. # Returns the state modifier rate for a given state_id. A value of 1.0
  153. # means no change.
  154. #
  155. # state_resist_set
  156. # Returns an array of resist state ID numbers.
  157. #
  158. # atk_elements
  159. # Returns an array of attack element ID numbers.
  160. #
  161. # atk_states
  162. # Returns an array of attack state ID numbers.
  163. #
  164. # atk_states_rate(state_id)
  165. # Returns the total attack state rate for a given state_id.
  166. #
  167. # atk_speed
  168. # Returns the attack speed value.
  169. #
  170. # atk_times_add
  171. # Returns the number of consecutive attacks granted.
  172. #
  173. # added_skill_types
  174. # Returns an array of added skill type ID numbers.
  175. #
  176. # sealed_skill_types
  177. # Returns an array of sealed skill type ID numbers.
  178. #
  179. # added_skills
  180. # Returns an array of added skill ID numbers.
  181. #
  182. # sealed_skills
  183. # Returns an array of sealed skill ID numbers.
  184. #
  185. # equip_wtypes
  186. # Returns an array of granted equip weapon types ID numbers
  187. #
  188. # equip_atypes
  189. # Returns an array of granted equip armor types ID numbers
  190. #
  191. # fixed_equips
  192. # Returns an array of fixed equipment index numbers. Each index
  193. # corresponds to an existing equip slot.
  194. # (0:Weapon, 1:Shield, 2:Helmet, 3:Armor, 4:Accessory)
  195. #
  196. # sealed_equips
  197. # Returns an array of sealed equipment index numbers. Each index
  198. # corresponds to an existing equip slot.
  199. # (0:Weapon, 1:Shield, 2:Helmet, 3:Armor, 4:Accessory)
  200. #
  201. # action_plus_set
  202. # Returns an array of Action Times+ chances.
  203. #
  204. #--------------------------------------------------------------------------
  205. # The following methods are for any RPG::UsableItem object:
  206. #
  207. # hp_recovery
  208. # Returns a flat HP recovery value.
  209. #
  210. # hp_recovery_rate
  211. # Returns the rate of HP recovery.
  212. #
  213. # mp_recovery
  214. # Returns a flat MP recovery value.
  215. #
  216. # mp_recovery_rate
  217. # Returns the rate of MP recovery.
  218. #
  219. # tp_recovery
  220. # Returns a flat TP recovery value.
  221. #
  222. # add_states
  223. # Returns an array of state IDs that are added to the target.
  224. #
  225. # remove_states
  226. # Returns an array of state IDs that are removed from the target.
  227. #
  228. # add_states_with_rates
  229. # Returns a multi-dimensional array where [index][0] is a state_id
  230. # number and [index][1] is the success rate.
  231. # [[state_id, rate],[state_id, rate],[state_id, rate], ...]
  232. # state_id 0 represents 'Normal Attack'.
  233. #
  234. # remove_states_with_rates
  235. # Returns a multi-dimensional array where [index][0] is a state_id
  236. # number and [index][1] is the remove rate.
  237. # [[state_id, rate],[state_id, rate],[state_id, rate], ...]
  238. #
  239. # add_buffs
  240. # Returns an array buffs represented by param_id numbers.
  241. #
  242. # add_debuffs
  243. # Returns an array debuffs represented by param_id numbers.
  244. #
  245. # add_buffs_with_turns
  246. # Returns a multi-dimensional array where [index][0] is a param_id
  247. # number and [index][1] is the buff turn duration.
  248. # [[param_id, turn],[param_id, turn],[param_id, turn], ...]
  249. #
  250. # add_debuffs_with_turns
  251. # Returns a multi-dimensional array where [index][0] is a param_id
  252. # number and [index][1] is the debuff turn duration.
  253. # [[param_id, turn],[param_id, turn],[param_id, turn], ...]
  254. #
  255. # remove_buffs
  256. # Returns an array of removed buffs represented by param_id numbers.
  257. #
  258. # remove_debuffs
  259. # Returns an array of removed debuffs represented by param_id numbers.
  260. #
  261. # escape?
  262. # Returns true or false if the skill/item provides escape from battle.
  263. #
  264. # grow(param_id)
  265. # Returns the total amount of param growth for the given param_id.
  266. #
  267. # learn_skills
  268. # Returns an array of skill IDs that the skill/item teaches.
  269. #
  270. # common_event
  271. # Returns a common event ID number. Otherwise, it returns nil.
  272. #
  273. #--------------------------------------------------------------------------
  274. # ++ Compatibility ++
  275. #--------------------------------------------------------------------------
  276. # There are no default method overwrites.
  277. #
  278. # Requests for compatibility with other scripts are welcome.
  279. #--------------------------------------------------------------------------
  280. # ++ Terms and Conditions ++
  281. #--------------------------------------------------------------------------
  282. # Please do not repost this script elsewhere without permission.
  283. # Free for non-commercial use. For commercial use, contact me first.
  284. #
  285. # Newest versions of this script can be found at
  286. # http://mrbubblewand.wordpress.com/
  287. #==============================================================================
  288.  
  289. $imported ||= {}
  290. $imported["BubsFeaturesReader"] = true
  291.  
  292. #==========================================================================
  293. # ++ This script contains no customization module ++
  294. #==========================================================================
  295.  
  296.  
  297. #==============================================================================
  298. # ++ RPG::EquipItem
  299. #==============================================================================
  300. class RPG::BaseItem
  301. #--------------------------------------------------------------------------
  302. # * Constants (Features)
  303. #--------------------------------------------------------------------------
  304. FEATURE_ELEMENT_RATE = 11 # Element Rate
  305. FEATURE_DEBUFF_RATE = 12 # Debuff Rate
  306. FEATURE_STATE_RATE = 13 # State Rate
  307. FEATURE_STATE_RESIST = 14 # State Resist
  308. FEATURE_PARAM = 21 # Parameter
  309. FEATURE_XPARAM = 22 # Ex-Parameter
  310. FEATURE_SPARAM = 23 # Sp-Parameter
  311. FEATURE_ATK_ELEMENT = 31 # Atk Element
  312. FEATURE_ATK_STATE = 32 # Atk State
  313. FEATURE_ATK_SPEED = 33 # Atk Speed
  314. FEATURE_ATK_TIMES = 34 # Atk Times+
  315. FEATURE_STYPE_ADD = 41 # Add Skill Type
  316. FEATURE_STYPE_SEAL = 42 # Disable Skill Type
  317. FEATURE_SKILL_ADD = 43 # Add Skill
  318. FEATURE_SKILL_SEAL = 44 # Disable Skill
  319. FEATURE_EQUIP_WTYPE = 51 # Equip Weapon
  320. FEATURE_EQUIP_ATYPE = 52 # Equip Armor
  321. FEATURE_EQUIP_FIX = 53 # Lock Equip
  322. FEATURE_EQUIP_SEAL = 54 # Seal Equip
  323. FEATURE_SLOT_TYPE = 55 # Slot Type
  324. FEATURE_ACTION_PLUS = 61 # Action Times+
  325. FEATURE_SPECIAL_FLAG = 62 # Special Flag
  326. FEATURE_COLLAPSE_TYPE = 63 # Collapse Effect
  327. FEATURE_PARTY_ABILITY = 64 # Party Ability
  328. #--------------------------------------------------------------------------
  329. # * Constants (Feature Flags)
  330. #--------------------------------------------------------------------------
  331. FLAG_ID_AUTO_BATTLE = 0 # auto battle
  332. FLAG_ID_GUARD = 1 # guard
  333. FLAG_ID_SUBSTITUTE = 2 # substitute
  334. FLAG_ID_PRESERVE_TP = 3 # preserve TP
  335. #--------------------------------------------------------------------------
  336. # * Access Method by Parameter Abbreviations
  337. #--------------------------------------------------------------------------
  338. def mhp; param(0); end # MHP Maximum Hit Points
  339. def mmp; param(1); end # MMP Maximum Magic Points
  340. def atk; param(2); end # ATK ATtacK power
  341. def def; param(3); end # DEF DEFense power
  342. def mat; param(4); end # MAT Magic ATtack power
  343. def mdf; param(5); end # MDF Magic DeFense power
  344. def agi; param(6); end # AGI AGIlity
  345. def luk; param(7); end # LUK LUcK
  346. def hit; xparam(0); end # HIT HIT rate
  347. def eva; xparam(1); end # EVA EVAsion rate
  348. def cri; xparam(2); end # CRI CRItical rate
  349. def cev; xparam(3); end # CEV Critical EVasion rate
  350. def mev; xparam(4); end # MEV Magic EVasion rate
  351. def mrf; xparam(5); end # MRF Magic ReFlection rate
  352. def cnt; xparam(6); end # CNT CouNTer attack rate
  353. def hrg; xparam(7); end # HRG Hp ReGeneration rate
  354. def mrg; xparam(8); end # MRG Mp ReGeneration rate
  355. def trg; xparam(9); end # TRG Tp ReGeneration rate
  356. def tgr; sparam(0); end # TGR TarGet Rate
  357. def grd; sparam(1); end # GRD GuaRD effect rate
  358. def rec; sparam(2); end # REC RECovery effect rate
  359. def pha; sparam(3); end # PHA PHArmacology
  360. def mcr; sparam(4); end # MCR Mp Cost Rate
  361. def tcr; sparam(5); end # TCR Tp Charge Rate
  362. def pdr; sparam(6); end # PDR Physical Damage Rate
  363. def mdr; sparam(7); end # MDR Magical Damage Rate
  364. def fdr; sparam(8); end # FDR Floor Damage Rate
  365. def exr; sparam(9); end # EXR EXperience Rate
  366. #--------------------------------------------------------------------------
  367. # * Access Method by Parameter Abbreviations (Rates)
  368. #--------------------------------------------------------------------------
  369. def mhp_rate; param_rate(0); end # MHP Maximum Hit Points rate
  370. def mmp_rate; param_rate(1); end # MMP Maximum Magic Points rate
  371. def atk_rate; param_rate(2); end # ATK ATtacK power rate
  372. def def_rate; param_rate(3); end # DEF DEFense power rate
  373. def mat_rate; param_rate(4); end # MAT Magic ATtack power rate
  374. def mdf_rate; param_rate(5); end # MDF Magic DeFense power rate
  375. def agi_rate; param_rate(6); end # AGI AGIlity rate
  376. def luk_rate; param_rate(7); end # LUK LUcK rate
  377. #--------------------------------------------------------------------------
  378. # * Get Feature Object Array (Feature Codes Limited)
  379. #--------------------------------------------------------------------------
  380. # features_with_id, features_sum_all, action_plus_set, special_flag,
  381. # party_ability
  382. def get_features(code)
  383. features.select {|ft| ft.code == code }
  384. end
  385. #--------------------------------------------------------------------------
  386. # * Get Feature Object Array (Feature Codes and Data IDs Limited)
  387. #--------------------------------------------------------------------------
  388. # features_pi, features_sum, features_set
  389. def features_with_id(code, id)
  390. get_features(code).select {|ft| ft.code == code && ft.data_id == id }
  391. end
  392. #--------------------------------------------------------------------------
  393. # * Calculate Complement of Feature Values
  394. #--------------------------------------------------------------------------
  395. # sparam, element_rate, debuff_rate, state_rate
  396. def features_pi(code, id)
  397. features_with_id(code, id).inject(1.0) {|r, ft| r *= ft.value }
  398. end
  399. #--------------------------------------------------------------------------
  400. # * Calculate Sum of Feature Values (Specify Data ID)
  401. #--------------------------------------------------------------------------
  402. # xparam, atk_states_rate
  403. def features_sum(code, id)
  404. features_with_id(code, id).inject(0.0) {|r, ft| r += ft.value }
  405. end
  406. #--------------------------------------------------------------------------
  407. # * Calculate Sum of Feature Values (Data ID Unspecified)
  408. #--------------------------------------------------------------------------
  409. # atk_speed, atk_times_add
  410. def features_sum_all(code)
  411. get_features(code).inject(0.0) {|r, ft| r += ft.value }
  412. end
  413. #--------------------------------------------------------------------------
  414. # * Calculate Set Sum of Features
  415. #--------------------------------------------------------------------------
  416. # state_resists, atk_elements, atk_states, added_skill_types,
  417. # skill_type_sealed?, sealed_skill_types, added_skills, skill_sealed?,
  418. # sealed_skills, equip_wtype_ok?, equip_wtypes, equip_atype_ok?,
  419. # equip_atypes, equip_type_fixed?, fixed_equips, equip_type_sealed?,
  420. # sealed_equips, slot_type, collapse_type
  421. def features_set(code)
  422. get_features(code).inject([]) {|r, ft| r |= [ft.data_id]}
  423. end
  424. #--------------------------------------------------------------------------
  425. # * Get Rate of Parameter Change
  426. #--------------------------------------------------------------------------
  427. def param_rate(param_id)
  428. features_pi(FEATURE_PARAM, param_id)
  429. end
  430. #--------------------------------------------------------------------------
  431. # * Get Ex-Parameter
  432. #--------------------------------------------------------------------------
  433. def xparam(xparam_id)
  434. features_sum(FEATURE_XPARAM, xparam_id)
  435. end
  436. #--------------------------------------------------------------------------
  437. # * Get Sp-Parameter
  438. #--------------------------------------------------------------------------
  439. def sparam(sparam_id)
  440. features_pi(FEATURE_SPARAM, sparam_id)
  441. end
  442. #--------------------------------------------------------------------------
  443. # * Get Element Rate
  444. #--------------------------------------------------------------------------
  445. def element_rate(element_id)
  446. features_pi(FEATURE_ELEMENT_RATE, element_id)
  447. end
  448. #--------------------------------------------------------------------------
  449. # * Get Debuff Rate
  450. #--------------------------------------------------------------------------
  451. def debuff_rate(param_id)
  452. features_pi(FEATURE_DEBUFF_RATE, param_id)
  453. end
  454. #--------------------------------------------------------------------------
  455. # * Get State Rate
  456. #--------------------------------------------------------------------------
  457. def state_rate(state_id)
  458. features_pi(FEATURE_STATE_RATE, state_id)
  459. end
  460. #--------------------------------------------------------------------------
  461. # * Get Array of States to Resist
  462. #--------------------------------------------------------------------------
  463. def state_resist_set
  464. features_set(FEATURE_STATE_RESIST)
  465. end
  466. #--------------------------------------------------------------------------
  467. # * Determine if State Is Resisted
  468. #--------------------------------------------------------------------------
  469. def state_resist?(state_id)
  470. state_resist_set.include?(state_id)
  471. end
  472. #--------------------------------------------------------------------------
  473. # * Get Attack Element
  474. #--------------------------------------------------------------------------
  475. def atk_elements
  476. features_set(FEATURE_ATK_ELEMENT)
  477. end
  478. #--------------------------------------------------------------------------
  479. # * Get Attack State
  480. #--------------------------------------------------------------------------
  481. def atk_states
  482. features_set(FEATURE_ATK_STATE)
  483. end
  484. #--------------------------------------------------------------------------
  485. # * Get Attack State Invocation Rate
  486. #--------------------------------------------------------------------------
  487. def atk_states_rate(state_id)
  488. features_sum(FEATURE_ATK_STATE, state_id)
  489. end
  490. #--------------------------------------------------------------------------
  491. # * Get Attack Speed
  492. #--------------------------------------------------------------------------
  493. def atk_speed
  494. features_sum_all(FEATURE_ATK_SPEED)
  495. end
  496. #--------------------------------------------------------------------------
  497. # * Get Additional Attack Times
  498. #--------------------------------------------------------------------------
  499. def atk_times_add
  500. [features_sum_all(FEATURE_ATK_TIMES), 0].max
  501. end
  502. #--------------------------------------------------------------------------
  503. # * Get Added Skill Types
  504. #--------------------------------------------------------------------------
  505. def added_skill_types
  506. features_set(FEATURE_STYPE_ADD)
  507. end
  508. #--------------------------------------------------------------------------
  509. # * Determine if Skill Type Is Disabled
  510. #--------------------------------------------------------------------------
  511. def skill_type_sealed?(stype_id)
  512. features_set(FEATURE_STYPE_SEAL).include?(stype_id)
  513. end
  514. #--------------------------------------------------------------------------
  515. # * Get Disabled Skill Type ID Array
  516. #--------------------------------------------------------------------------
  517. def sealed_skill_types
  518. features_set(FEATURE_STYPE_SEAL)
  519. end
  520. #--------------------------------------------------------------------------
  521. # * Get Added Skills ID Array
  522. #--------------------------------------------------------------------------
  523. def added_skills
  524. features_set(FEATURE_SKILL_ADD)
  525. end
  526. #--------------------------------------------------------------------------
  527. # * Determine if Skill Is Disabled
  528. #--------------------------------------------------------------------------
  529. def skill_sealed?(skill_id)
  530. features_set(FEATURE_SKILL_SEAL).include?(skill_id)
  531. end
  532. #--------------------------------------------------------------------------
  533. # * Get Sealed Skills ID Array
  534. #--------------------------------------------------------------------------
  535. def sealed_skills
  536. features_set(FEATURE_SKILL_SEAL)
  537. end
  538. #--------------------------------------------------------------------------
  539. # * Determine if Weapon Can Be Equipped
  540. #--------------------------------------------------------------------------
  541. def equip_wtype_ok?(wtype_id)
  542. features_set(FEATURE_EQUIP_WTYPE).include?(wtype_id)
  543. end
  544. #--------------------------------------------------------------------------
  545. # * Get Equip Weapon Types ID Array
  546. #--------------------------------------------------------------------------
  547. def equip_wtypes
  548. features_set(FEATURE_EQUIP_WTYPE)
  549. end
  550. #--------------------------------------------------------------------------
  551. # * Determine if Armor Can Be Equipped
  552. #--------------------------------------------------------------------------
  553. def equip_atype_ok?(atype_id)
  554. features_set(FEATURE_EQUIP_ATYPE).include?(atype_id)
  555. end
  556. #--------------------------------------------------------------------------
  557. # * Get Equip Armor Types ID Array
  558. #--------------------------------------------------------------------------
  559. def equip_atypes
  560. features_set(FEATURE_EQUIP_ATYPE)
  561. end
  562. #--------------------------------------------------------------------------
  563. # * Determine if Equipment Is Locked
  564. #--------------------------------------------------------------------------
  565. def equip_type_fixed?(etype_id)
  566. features_set(FEATURE_EQUIP_FIX).include?(etype_id)
  567. end
  568. #--------------------------------------------------------------------------
  569. # * Get Fixed Equips Index Array
  570. #--------------------------------------------------------------------------
  571. def fixed_equips
  572. features_set(FEATURE_EQUIP_FIX)
  573. end
  574. #--------------------------------------------------------------------------
  575. # * Determine if Equipment Is Sealed
  576. #--------------------------------------------------------------------------
  577. def equip_type_sealed?(etype_id)
  578. features_set(FEATURE_EQUIP_SEAL).include?(etype_id)
  579. end
  580. #--------------------------------------------------------------------------
  581. # * Get Sealed Equips Index Array
  582. #--------------------------------------------------------------------------
  583. def sealed_equips
  584. features_set(FEATURE_EQUIP_SEAL)
  585. end
  586. #--------------------------------------------------------------------------
  587. # * Get Slot Type
  588. #--------------------------------------------------------------------------
  589. def slot_type
  590. features_set(FEATURE_SLOT_TYPE).max || 0
  591. end
  592. #--------------------------------------------------------------------------
  593. # * Determine if Dual Wield
  594. #--------------------------------------------------------------------------
  595. def dual_wield?
  596. slot_type == 1
  597. end
  598. #--------------------------------------------------------------------------
  599. # * Get Array of Additional Action Time Probabilities
  600. #--------------------------------------------------------------------------
  601. def action_plus_set
  602. get_features(FEATURE_ACTION_PLUS).collect {|ft| ft.value }
  603. end
  604. alias action_times_plus action_plus_set
  605. #--------------------------------------------------------------------------
  606. # * Determine if Special Flag
  607. #--------------------------------------------------------------------------
  608. def special_flag(flag_id)
  609. get_features(FEATURE_SPECIAL_FLAG).any? {|ft| ft.data_id == flag_id }
  610. end
  611. #--------------------------------------------------------------------------
  612. # * Get Collapse Effect
  613. #--------------------------------------------------------------------------
  614. def collapse_type
  615. features_set(FEATURE_COLLAPSE_TYPE).max || 0
  616. end
  617. #--------------------------------------------------------------------------
  618. # * Determine if Auto Battle
  619. #--------------------------------------------------------------------------
  620. def auto_battle?
  621. special_flag(FLAG_ID_AUTO_BATTLE)
  622. end
  623. #--------------------------------------------------------------------------
  624. # * Determine if Guard
  625. #--------------------------------------------------------------------------
  626. def guard?
  627. special_flag(FLAG_ID_GUARD)
  628. end
  629. #--------------------------------------------------------------------------
  630. # * Determine if Substitute
  631. #--------------------------------------------------------------------------
  632. def substitute?
  633. special_flag(FLAG_ID_SUBSTITUTE)
  634. end
  635. #--------------------------------------------------------------------------
  636. # * Determine if Preserve TP
  637. #--------------------------------------------------------------------------
  638. def preserve_tp?
  639. special_flag(FLAG_ID_PRESERVE_TP)
  640. end
  641. #--------------------------------------------------------------------------
  642. # * Determine Party Ability
  643. #--------------------------------------------------------------------------
  644. def party_ability(ability_id)
  645. get_features(FEATURE_PARTY_ABILITY).any? {|ft| ft.data_id == ability_id}
  646. end
  647. #--------------------------------------------------------------------------
  648. # * Halve Encounters?
  649. #--------------------------------------------------------------------------
  650. def encounter_half?
  651. party_ability(ABILITY_ENCOUNTER_HALF)
  652. end
  653. #--------------------------------------------------------------------------
  654. # * Disable Encounters?
  655. #--------------------------------------------------------------------------
  656. def encounter_none?
  657. party_ability(ABILITY_ENCOUNTER_NONE)
  658. end
  659. #--------------------------------------------------------------------------
  660. # * Disable Surprise?
  661. #--------------------------------------------------------------------------
  662. def cancel_surprise?
  663. party_ability(ABILITY_CANCEL_SURPRISE)
  664. end
  665. #--------------------------------------------------------------------------
  666. # * Increase Preemptive Strike Rate?
  667. #--------------------------------------------------------------------------
  668. def raise_preemptive?
  669. party_ability(ABILITY_RAISE_PREEMPTIVE)
  670. end
  671. #--------------------------------------------------------------------------
  672. # * Double Money Earned?
  673. #--------------------------------------------------------------------------
  674. def gold_double?
  675. party_ability(ABILITY_GOLD_DOUBLE)
  676. end
  677. #--------------------------------------------------------------------------
  678. # * Double Item Acquisition Rate?
  679. #--------------------------------------------------------------------------
  680. def drop_item_double?
  681. party_ability(ABILITY_DROP_ITEM_DOUBLE)
  682. end
  683. #--------------------------------------------------------------------------
  684. # * Get Feature Flag Keys
  685. #--------------------------------------------------------------------------
  686. def get_feature_flags
  687. array = []
  688. array.push(:dual_wield) if dual_wield?
  689. array.push(:auto_battle) if auto_battle?
  690. array.push(:guard) if guard?
  691. array.push(:substitute) if substitute?
  692. array.push(:preserve_tp) if preserve_tp?
  693. array.push(:encounter_half) if encounter_half?
  694. array.push(:encounter_none) if encounter_none?
  695. array.push(:cancel_surprise) if cancel_surprise?
  696. array.push(:raise_preemptive) if raise_preemptive?
  697. array.push(:gold_double) if gold_double?
  698. array.push(:drop_item_double) if drop_item_double?
  699. return array
  700. end
  701.  
  702. #--------------------------------------------------------------------------
  703. # * Get Feature By Key
  704. #--------------------------------------------------------------------------
  705. def feature_by_key(key)
  706. case key
  707. when :mhp
  708. mhp
  709. when :mmp
  710. mmp
  711. when :atk
  712. atk
  713. when :def
  714. self.def
  715. when :mat
  716. mat
  717. when :mdf
  718. mdf
  719. when :agi
  720. agi
  721. when :luk
  722. luk
  723.  
  724. when :mhp
  725. mhp
  726. when :mmp
  727. mmp
  728. when :atk
  729. atk
  730. when :def
  731. self.def
  732. when :mat
  733. mat
  734. when :mdf
  735. mdf
  736. when :agi
  737. agi
  738. when :luk
  739. luk
  740.  
  741. when :mhp_rate
  742. mhp_rate
  743. when :mmp_rate
  744. mmp_rate
  745. when :atk_rate
  746. atk_rate
  747. when :def_rate
  748. def_rate
  749. when :mat_rate
  750. mat_rate
  751. when :mdf_rate
  752. mdf_rate
  753. when :agi_rate
  754. agi_rate
  755. when :luk_rate
  756. luk_rate
  757.  
  758. when :hit
  759. hit
  760. when :eva
  761. eva
  762. when :cri
  763. cri
  764. when :cev
  765. cev
  766. when :mev
  767. mev
  768. when :mrf
  769. mrf
  770. when :cnt
  771. cnt
  772. when :hrg
  773. hrg
  774. when :mrg
  775. mrg
  776. when :trg
  777. trg
  778.  
  779. when :tgr
  780. tgr
  781. when :grd
  782. grd
  783. when :rec
  784. rec
  785. when :pha
  786. pha
  787. when :mcr
  788. mcr
  789. when :tcr
  790. tcr
  791. when :pdr
  792. pdr
  793. when :mdr
  794. mdr
  795. when :fdr
  796. fdr
  797. when :exr
  798. exr
  799.  
  800. when :element_rate
  801. element_rate
  802. when :debuff_rate
  803. debuff_rate
  804. when :state_rate
  805. state_rate
  806. when :state_resist_set
  807. state_resist_set
  808.  
  809. when :atk_elements
  810. atk_elements
  811. when :atk_states
  812. atk_states
  813. when :atk_speed
  814. atk_speed
  815. when :atk_times_add
  816. atk_times_add
  817.  
  818. when :added_skill_types
  819. added_skill_types
  820. when :added_skills
  821. added_skills
  822. when :sealed_skill_types
  823. sealed_skill_types
  824. when :sealed_skills
  825. sealed_skills
  826.  
  827. when :equip_wtypes
  828. equip_wtypes
  829. when :equip_atypes
  830. equip_atypes
  831. when :fixed_equips
  832. fixed_equips
  833. when :sealed_equips
  834. sealed_equips
  835. when :dual_wield
  836. dual_wield?
  837.  
  838. when :action_times_plus
  839. action_times_plus
  840.  
  841. when :auto_battle
  842. auto_battle?
  843. when :guard
  844. guard?
  845. when :substitute
  846. substitute?
  847. when :preserve_tp
  848. preserve_tp?
  849.  
  850. when :collapse_effect
  851. collapse_effect
  852.  
  853. when :encounter_half
  854. encounter_half?
  855. when :encounter_none
  856. encounter_none?
  857. when :cancel_surprise
  858. cancel_surprise?
  859. when :raise_preemptive
  860. raise_preemptive?
  861. when :gold_double
  862. gold_double?
  863. when :drop_item_double
  864. drop_item_double?
  865. end
  866. end
  867.  
  868. end # class RPG::BaseItem
  869.  
  870.  
  871. #==============================================================================
  872. # ++ RPG::UsableItem
  873. #==============================================================================
  874. class RPG::UsableItem
  875. #--------------------------------------------------------------------------
  876. # * Constants (Effects)
  877. #--------------------------------------------------------------------------
  878. EFFECT_RECOVER_HP = 11 # HP Recovery
  879. EFFECT_RECOVER_MP = 12 # MP Recovery
  880. EFFECT_GAIN_TP = 13 # TP Gain
  881. EFFECT_ADD_STATE = 21 # Add State
  882. EFFECT_REMOVE_STATE = 22 # Remove State
  883. EFFECT_ADD_BUFF = 31 # Add Buff
  884. EFFECT_ADD_DEBUFF = 32 # Add Debuff
  885. EFFECT_REMOVE_BUFF = 33 # Remove Buff
  886. EFFECT_REMOVE_DEBUFF = 34 # Remove Debuff
  887. EFFECT_SPECIAL = 41 # Special Effect
  888. EFFECT_GROW = 42 # Raise Parameter
  889. EFFECT_LEARN_SKILL = 43 # Learn Skill
  890. EFFECT_COMMON_EVENT = 44 # Common Events
  891. #--------------------------------------------------------------------------
  892. # * Constants (Special Effects)
  893. #--------------------------------------------------------------------------
  894. SPECIAL_EFFECT_ESCAPE = 0 # Escape
  895. #--------------------------------------------------------------------------
  896. # * Get Effect Object Array (Effect Codes Limited)
  897. #--------------------------------------------------------------------------
  898. def get_effects(code)
  899. effects.select {|ef| ef.code == code }
  900. end
  901. #--------------------------------------------------------------------------
  902. # * Get Effect Object Array (Effect Codes and Data IDs Limited)
  903. #--------------------------------------------------------------------------
  904. def effects_with_id(code, id)
  905. get_effects(code).select {|ef| ef.code == code && ef.data_id == id }
  906. end
  907. #--------------------------------------------------------------------------
  908. # * Calculate Complement of Effect Value1
  909. #--------------------------------------------------------------------------
  910. def effects_pi_value1(code, id)
  911. effects_with_id(code, id).inject(1.0) {|r, ef| r *= ef.value1 }
  912. end
  913. #--------------------------------------------------------------------------
  914. # * Calculate Sum of Effect Value 1 (Specify Data ID)
  915. #--------------------------------------------------------------------------
  916. def effects_sum_value1(code, id)
  917. effects_with_id(code, id).inject(0.0) {|r, ef| r += ef.value1 }
  918. end
  919. #--------------------------------------------------------------------------
  920. # * Calculate Sum of Effect Value 2 (Specify Data ID)
  921. #--------------------------------------------------------------------------
  922. def effects_sum_value2(code, id)
  923. effects_with_id(code, id).inject(0.0) {|r, ef| r += ef.value2 }
  924. end
  925. #--------------------------------------------------------------------------
  926. # * Calculate Sum of Effect Value 1 (Data ID Unspecified)
  927. #--------------------------------------------------------------------------
  928. def effects_sum_all_value1(code)
  929. get_effects(code).inject(0.0) {|r, ef| r += ef.value1 }
  930. end
  931. #--------------------------------------------------------------------------
  932. # * Calculate Sum of Effect Value 2 (Data ID Unspecified)
  933. #--------------------------------------------------------------------------
  934. def effects_sum_all_value2(code)
  935. get_effects(code).inject(0.0) {|r, ef| r += ef.value2 }
  936. end
  937. #--------------------------------------------------------------------------
  938. # * Calculate Set Sum of Effects
  939. #--------------------------------------------------------------------------
  940. def effects_set(code)
  941. get_effects(code).inject([]) {|r, ef| r.push(ef.data_id) }
  942. end
  943. #--------------------------------------------------------------------------
  944. # * Get Effect ID with Value1
  945. #--------------------------------------------------------------------------
  946. def effects_set_with_value1(code)
  947. get_effects(code).inject([]) {|r, ef| r.push([ef.data_id, ef.value1]) }
  948. end
  949. #--------------------------------------------------------------------------
  950. # * Get HP Recovery Value
  951. #--------------------------------------------------------------------------
  952. def hp_recovery
  953. effects_sum_all_value2(EFFECT_RECOVER_HP)
  954. end
  955. #--------------------------------------------------------------------------
  956. # * Get HP Recovery Rate
  957. #--------------------------------------------------------------------------
  958. def hp_recovery_rate
  959. effects_sum_all_value1(EFFECT_RECOVER_HP)
  960. end
  961. #--------------------------------------------------------------------------
  962. # * Get MP Recovery Value
  963. #--------------------------------------------------------------------------
  964. def mp_recovery
  965. effects_sum_all_value2(EFFECT_RECOVER_MP)
  966. end
  967. #--------------------------------------------------------------------------
  968. # * Get MP Recovery Rate
  969. #--------------------------------------------------------------------------
  970. def mp_recovery_rate
  971. effects_sum_all_value1(EFFECT_RECOVER_MP)
  972. end
  973. #--------------------------------------------------------------------------
  974. # * Get TP Recovery Value
  975. #--------------------------------------------------------------------------
  976. def tp_recovery
  977. effects_sum_all_value1(EFFECT_GAIN_TP)
  978. end
  979. #--------------------------------------------------------------------------
  980. # * Get Add States IDs Array
  981. #--------------------------------------------------------------------------
  982. # state_id 0 represents 'Normal Attack'.
  983. def add_states
  984. effects_set(EFFECT_ADD_STATE)
  985. end
  986. #--------------------------------------------------------------------------
  987. # * Get Remove States IDs Array
  988. #--------------------------------------------------------------------------
  989. def remove_states
  990. effects_set(EFFECT_REMOVE_STATE)
  991. end
  992. #--------------------------------------------------------------------------
  993. # * Get Add States IDs with Rates Array
  994. #--------------------------------------------------------------------------
  995. # returns a multi-dimensional array where [index][0] is a
  996. # state_id number and [index][1] is the success rate.
  997. # [[state_id, rate],[state_id, rate],[state_id, rate], ...]
  998. #
  999. # state_id 0 represents 'Normal Attack'.
  1000. def add_states_with_rates
  1001. effects_set_with_value1(EFFECT_ADD_STATE)
  1002. end
  1003. #--------------------------------------------------------------------------
  1004. # * Get Remove States IDs with Rates Array
  1005. #--------------------------------------------------------------------------
  1006. # returns a multi-dimensional array where [index][0] is a
  1007. # state_id number and [index][1] is the success rate.
  1008. # [[state_id, rate],[state_id, rate],[state_id, rate], ...]
  1009. def remove_states_with_rates
  1010. effects_set_with_value1(EFFECT_REMOVE_STATE)
  1011. end
  1012. #--------------------------------------------------------------------------
  1013. # * Get Add Buffs Param Index Array
  1014. #--------------------------------------------------------------------------
  1015. def add_buffs
  1016. effects_set(EFFECT_ADD_BUFF)
  1017. end
  1018. #--------------------------------------------------------------------------
  1019. # * Get Add Debuffs Param Index Array
  1020. #--------------------------------------------------------------------------
  1021. def add_debuffs
  1022. effects_set(EFFECT_ADD_DEBUFF)
  1023. end
  1024. #--------------------------------------------------------------------------
  1025. # * Get Add Buffs Param Index with Turns Array
  1026. #--------------------------------------------------------------------------
  1027. # returns a multi-dimensional array where [index][0] is a
  1028. # param_id value and [index][1] is the turn duration.
  1029. # [[param_index, turn],[param_index, turn],[param_index, turn], ...]
  1030. def add_buffs_with_turns
  1031. effects_set_with_value1(EFFECT_ADD_BUFF)
  1032. end
  1033. #--------------------------------------------------------------------------
  1034. # * Get Add Debuffs Param Index with Turns Array
  1035. #--------------------------------------------------------------------------
  1036. # returns a multi-dimensional array where [index][0] is a
  1037. # param_id value and [index][1] is the turn duration.
  1038. # [[param_index, turn],[param_index, turn],[param_index, turn], ...]
  1039. def add_debuffs_with_turns
  1040. effects_set_with_value1(EFFECT_ADD_DEBUFF)
  1041. end
  1042. #--------------------------------------------------------------------------
  1043. # * Get Remove Buffs Param Index
  1044. #--------------------------------------------------------------------------
  1045. def remove_buffs
  1046. effects_set_with_value1(EFFECT_REMOVE_BUFF)
  1047. end
  1048. #--------------------------------------------------------------------------
  1049. # * Get Remove Debuffs Param Index
  1050. #--------------------------------------------------------------------------
  1051. def remove_debuffs
  1052. effects_set_with_value1(EFFECT_REMOVE_DEBUFF)
  1053. end
  1054. #--------------------------------------------------------------------------
  1055. # * Determine Escape Item/Skill
  1056. #--------------------------------------------------------------------------
  1057. def escape?
  1058. !effects_set(EFFECT_SPECIAL).empty?
  1059. end
  1060. #--------------------------------------------------------------------------
  1061. # * Get Param Growth with Values
  1062. #--------------------------------------------------------------------------
  1063. def grow(param_id)
  1064. effects_sum_value1(EFFECT_GROW, param_id)
  1065. end
  1066. #--------------------------------------------------------------------------
  1067. # * Get Learn Skills IDs Array
  1068. #--------------------------------------------------------------------------
  1069. def learn_skills
  1070. effects_set(EFFECT_LEARN_SKILL)
  1071. end
  1072. #--------------------------------------------------------------------------
  1073. # * Get Common Event ID
  1074. #--------------------------------------------------------------------------
  1075. def common_event
  1076. effects_set(EFFECT_COMMON_EVENT).last
  1077. end
  1078. #--------------------------------------------------------------------------
  1079. # * Get Effect By Key
  1080. #--------------------------------------------------------------------------
  1081. def effect_by_key(key)
  1082. case key
  1083. when :hp_recovery
  1084. hp_recovery
  1085. when :hp_recovery_rate
  1086. hp_recovery_rate
  1087. when :mp_recovery
  1088. mp_recovery
  1089. when :mp_recovery_rate
  1090. mp_recovery_rate
  1091. when :tp_recovery
  1092. tp_recovery
  1093. when :add_states
  1094. add_states
  1095. when :remove_states
  1096. remove_states
  1097. when :add_states_with_rates
  1098. add_states_with_rates
  1099. when :remove_states_with_rates
  1100. remove_states_with_rates
  1101. when :add_buffs
  1102. add_buffs
  1103. when :add_debuffs
  1104. add_debuffs
  1105. when :add_buffs_with_turns
  1106. add_buffs_with_turns
  1107. when :add_debuffs_with_turns
  1108. add_debuffs_with_turns
  1109. when :remove_buffs
  1110. remove_buffs
  1111. when :remove_debuffs
  1112. remove_debuffs
  1113. when :escape
  1114. escape?
  1115. when :learn_skills
  1116. learn_skills
  1117. when :comment_event
  1118. common_event
  1119. end
  1120. end
  1121.  
  1122. end # class RPG::UsableItem
  1123.  
  1124.  
  1125. #==============================================================================
  1126. # ++ RPG::EquipItem
  1127. #==============================================================================
  1128. class RPG::EquipItem
  1129. #--------------------------------------------------------------------------
  1130. # * Access Method by Parameter Abbreviations
  1131. #--------------------------------------------------------------------------
  1132. def mhp; param(0); end # MHP Maximum Hit Points
  1133. def mmp; param(1); end # MMP Maximum Magic Points
  1134. def atk; param(2); end # ATK ATtacK power
  1135. def def; param(3); end # DEF DEFense power
  1136. def mat; param(4); end # MAT Magic ATtack power
  1137. def mdf; param(5); end # MDF Magic DeFense power
  1138. def agi; param(6); end # AGI AGIlity
  1139. def luk; param(7); end # LUK LUcK
  1140. #--------------------------------------------------------------------------
  1141. # * Get Parameter
  1142. #--------------------------------------------------------------------------
  1143. def param(param_id)
  1144. params[param_id]
  1145. end
  1146.  
  1147. end # class RPG::EquipItem
Advertisement
Add Comment
Please, Sign In to add comment