Guest User

Tsukuhime - Effect Manager

a guest
Aug 7th, 2016
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2. #==============================================================================
  3. ** Effect Manager
  4. Version: 2.6
  5. Author: Hime
  6. Date: Dec 10, 2012
  7. ------------------------------------------------------------------------------
  8. ** Change log
  9. 2.6 Dec 10, 2012
  10. - Added "pre_attack" and "pre_guard" triggers.
  11. 2.5 Nov 23, 2012
  12. - Added "troop" trigger for battle event effect triggers
  13. - Added "add_effect_message" method to Game_ActionResult
  14. - Added small delay between each effect message
  15. - Crit_attack triggers and normal attack triggers are mutually exclusive now
  16. 2.4 Nov 17, 2012
  17. - Renamed "critical" trigger to "crit_attack" trigger
  18. - Added "crit_guard" trigger
  19. 2.3
  20. - Removed global effect overwrite. Replaced with a proper global effect check
  21. 2.2
  22. - Added effect conditions
  23. 2.1 Nov 3, 2012
  24. - Implemented "equip" and "unequip" triggers
  25. - Implemented "turn_start", "battle_start", and "battle_end" triggers
  26. - Implemented "level_up", "level_down" triggers
  27. - Refactored code so that triggers are easy to implement for all effect objects
  28. 2.0 Oct 31, 2012
  29. - Standardized method name format for effect triggers
  30. - Provided effect triggers for note tags
  31. 1.6 Oct 30, 2012
  32. - Added experimental "Effect Callback" for scenes
  33. 1.52 Oct 28, 2012
  34. - Fixed bug where the wrong value was being checked during effect loading
  35. Oct 21, 2012
  36. - added weapon/armor turn end effects
  37. - Fixed issue where turn end effect results weren't displayed
  38. Oct 20, 2012
  39. - fixed bug where "Common event" effect wasn't activating
  40. Oct 16, 2012
  41. - Added support for global item/skill effects.
  42. Oct 11, 2012
  43. - Redefined effect categories. Restructured code to reflect the new design
  44. - added signatures for class, weapon, armor passive effects
  45. Oct 10, 2012
  46. - added signatures for class effects: class_attack, class_guard
  47. Oct 8, 2012
  48. - added "initial" values to the action result
  49. - dying no longer clears states or buffs
  50. - added two types of state effects: state_attack and state_guard
  51. - added two types of state effects: state_add and state_remove
  52. Oct 7, 2012
  53. - added duplicate code to UsableItem to force it to run note checking.
  54. - note parser now sends add_effect method an array of arguments rather than
  55. just a string for the arguments
  56. - Extended effects to all RPG::BaseItem classes, including actors, classes,
  57. weapon, armors, items, skills, enemies, and states
  58. Oct 6, 2012
  59. - Effect code can now be anything that you want as long as it is
  60. a valid hash key. I would recommend symbols or strings. You can still
  61. use a number
  62. Oct 5, 2012
  63. - added logic to allow users to define how the Effect object should
  64. be created
  65. Oct 4, 2012
  66. - changed regex to allow arbitrary number of arguments for the effect.
  67. Oct 3, 2012
  68. - added effect messages
  69. - initial release
  70. ------------------------------------------------------------------------------
  71. ** Terms of Use
  72. * Free to use in non-commercial projects
  73. * Contact me for commercial use
  74. * No real support. The script is provided as-is
  75. * Will do bug fixes, but no compatibility patches
  76. * Features may be requested but no guarantees, especially if it is non-trivial
  77. * Preserve this header
  78. ------------------------------------------------------------------------------
  79. ** Compatibility
  80.  
  81. Should be compatible with most systems.
  82. This script replaces one method
  83. -Game_Battler # item_effect_apply
  84.  
  85. ------------------------------------------------------------------------------
  86. ** Description
  87.  
  88. This script replaces the default Effects handlers with a plugin-based
  89. effect system. It is meant to allow developers to easily develop new
  90. effects without having to concern with the minor details.
  91.  
  92. You can define new effects by simply registering it, defining a method,
  93. and then note-tagging your database objects.
  94.  
  95. Additional item/skill effects can be easily added.
  96. This script extends effects to all RPG::BaseItem classes, although only
  97. some have been implemented.
  98.  
  99. ------------------------------------------------------------------------------
  100. ** Terminology
  101.  
  102. This script uses specific terminology that I have defined.
  103.  
  104. * Effect plugin
  105. Any script that is registered to the Effect Manager are called "plugins".
  106.  
  107. * Effect objects
  108. Or simply "objects". These are any objects that you can add effects to.
  109. The default engine allows items and skills to have effects. This script
  110. extends this to actors, class, weapons, armors, enemies, and states.
  111.  
  112. * Id String
  113. The name of an effect. Used throughout your script and notetags.
  114. Every plugin must have a unique idstring.
  115.  
  116. * Effect Type
  117. Determined by the object the effect is assigned to.
  118. For example, effects that are assigned to a weapon are "weapon effects"
  119.  
  120. * Effect Triggers
  121. Specifies when an effect will be activated.
  122. For example, an "attack trigger" requires your battler to be "attacking"
  123. another target.
  124.  
  125. * Effect Conditions
  126. Conditions that must be met in order for an effect to activate.
  127. These are checked after an effect is triggered, but before the effect
  128. is applied
  129.  
  130. ------------------------------------------------------------------------------
  131. ** Usage
  132.  
  133. All effects that are written for this script are added to objects using
  134. note tags.
  135.  
  136. The basic format of the note tag is
  137.  
  138. <eff: idstring arg1 arg2 ... >
  139.  
  140. Where
  141. `idstring` is the name of effect that you want to add,
  142. `arg1, arg2, ...` are a list of arguments that the effect requires
  143.  
  144. You can specify effects with conditions by using the format:
  145.  
  146. <cond_eff: idstring cond arg1 arg2 ... >
  147.  
  148. Where
  149. `cond` is a ruby expression that evaluates to true or false that contains
  150. no spaces
  151.  
  152. The only difference between the two note-tags is that one allows you to
  153. specify conditions while the other does not.
  154.  
  155. Instructions should be provided with the effect plugin describing what each
  156. argument represents.
  157.  
  158. By default, if you simply write the idstring of the effect, then it is assumed
  159. to activate under any effect trigger. If you wish to specify the triggers that
  160. it will activate under, you should write it as
  161.  
  162. <eff: idstring-TRIGGER arg1 arg2 ... >
  163.  
  164. Where `TRIGGER` is an effect trigger. You can look at the list of triggers
  165. available in the reference list below, although a plugin may choose not to
  166. implement every trigger available. Check with the plugin author to see what
  167. kinds of triggers are available.
  168.  
  169. ------------------------------------------------------------------------------
  170. ** Reference
  171.  
  172. This is a list of effect types that are currently supported:
  173.  
  174. * actor - applies to actors
  175. * class - applies to classes
  176. * item - applies to items/skills
  177. * skill - applies to skills
  178. * weapon - applies to weapons
  179. * armor - applies to armors
  180. * enemy - applies to enemies
  181. * state - applies to states
  182.  
  183. Note that actors and enemies currently only support passive triggers.
  184.  
  185. This is a list of effect triggers that are currently supported:
  186.  
  187. * attack - triggered when an action hits a battler
  188. * guard - triggered when a battler is hit by an action
  189. * crit_attack - triggered when a critical hit is inflicted
  190. * crit_guard - triggered when a battler received a critical hit
  191. * pre_attack - triggered before damage from action is applied, attack side
  192. * pre_guard - triggered before damage from action is applied, guard side
  193. * miss_attack - triggered when an action misses, attack side
  194. * miss_guard - triggered when an action misses, guard side
  195. * level_up - when you increase a level
  196. * level_down - when you decrease a level
  197. * battle_start - triggered at the beginning of the battle
  198. * battle_end - triggered at the end of the battle
  199. * turn_start - triggered at the start of each turn
  200. * turn_end - triggered at the end of each turn
  201. * equip - equip trigger. When you equip a weapon/armor
  202. * unequip - equip trigger. When you unequip a weapon/armor
  203. * add - state trigger. When a state is added
  204. * remove - state trigger. When a state is removed.
  205. * global - special trigger. When an item/skill is used
  206. * troop - special trigger. When a battle event has executed
  207.  
  208. There are two general types of methods signatures
  209.  
  210. 1. TYPE_effect_NAME_TRIGGER(user, obj, effect)
  211.  
  212. This applies to any trigger where two battlers are involved, such as
  213. attack, guard, or critical.
  214.  
  215. 2. TYPE_effect_NAME_TRIGGER(obj, effect)
  216.  
  217. This applies to any trigger that involve only one battler. Basically every
  218. other trigger since there is no other battler.
  219.  
  220. ------------------------------------------------------------------------------
  221. ** Plugin Developers
  222.  
  223. This section is for users that wish to develop their own plugins for the
  224. Effect Manager. It will walk through various features that are available
  225. for you.
  226.  
  227. == Making your plugin ==
  228.  
  229. So we start by understanding how to write an effect plugin.
  230. Defining new effects is a simple 3-step process
  231.  
  232. 1: at the top of your script, add a single call to register your effect.
  233.  
  234. Effect_Manager.register_effect(idstring, api_version)
  235.  
  236. where
  237. `idstring` is a string that you will use to refer to your effect.
  238. `api_version` is the version of the Effect Manager that your script
  239. runs under. If the user's version is outdated, a popup
  240. will appear alerting that the plugin is incompatible. The
  241. default version required is 2.0
  242.  
  243. As an example, we'll register a new effect called "test_effect"
  244.  
  245. Effect_Manager.register_effect(:test_effect, 2.0)
  246.  
  247. 2: Define the method for your effect in Game_Battler or its child classes.
  248. Depending on where it should be triggered, the name will be different.
  249.  
  250. The format of the method name is defined above in the reference, so for
  251. example you might have something like
  252.  
  253. def item_effect_test_effect(user, item, effect)
  254. args = effect.value1
  255. end
  256.  
  257. 3: Instruct your users to tag their objects with the following note tag:
  258.  
  259. <eff: test_effect arg1 arg2 arg3 ...>
  260.  
  261. == Storing and retrieving arguments ==
  262.  
  263. By default, any arguments that are passed to your effect will be stored in
  264. an effect object as an array of strings. In step 2 above, you see that you are
  265. given a reference to your effect. You can access the arguments using
  266.  
  267. effect.value1
  268.  
  269. If you would like to type cast your arguments beforehand, you can define this
  270. method in any RPG::BaseItem classes:
  271.  
  272. def add_effect_IDSTRING(code, data_id, args)
  273. # type cast your args here
  274.  
  275. # now add the effect to the object
  276. add_effect(code, data_id, args)
  277. end
  278.  
  279. Simply replace IDSTRING with the name that you registered in step 1.
  280.  
  281. == Working with custom messages ==
  282.  
  283. A simple way to inform users that something has happened is to simply add
  284. messages to $game_message:
  285.  
  286. $game_message.add_message("your results")
  287.  
  288. In addition, I have provided you a special way to store messages from your
  289. effects so that they will appear in the battle log during battle.
  290.  
  291. The Game_ActionResult class holds an `effect_results` array that will store
  292. an array of strings. So the usual way of adding an effect message is
  293.  
  294. @result.effect_results.append(YOUR_MESSAGE)
  295.  
  296. == Using effect callbacks ==
  297.  
  298. Sometimes, your effects require user input, which may occur on a different
  299. scene. Because the effect evaluation will end when you switch to another
  300. scene, you will need a way to remember which effect is currently activated.
  301.  
  302. This can be accomplished using the following sequence of calls
  303.  
  304. SceneManager.call(YOUR_NEW_SCENE)
  305. SceneManager.set_effect_callback(:method_name, effect)
  306.  
  307. By setting the effect callback, you are able to trigger a custom method
  308. for your effect processing.
  309.  
  310. == Other stuff that may be of interest ==
  311.  
  312. I have added some extra attributes for convenience in the following classes.
  313.  
  314. Game_ActionResult
  315. old_hp : stores the battler's HP before damage is applied
  316. old_mp : stores the battler's MP before damage is applied
  317. old_tp : stores the battler's TP before damage is applied
  318.  
  319. If you need to access the current action to get any information about what
  320. was executed, you can use the following
  321.  
  322. user.current_action
  323. user.current_action.item
  324.  
  325. #==============================================================================
  326. =end
  327. $imported = {} if $imported.nil?
  328. $imported["Effect_Manager"] = 2.6
  329. #==============================================================================
  330. # ** Rest of the script
  331. #==============================================================================
  332.  
  333. module Effect_Manager
  334.  
  335. # The format of all note tags
  336. triggers = "(-attack|-guard|-crit_attack|-crit_guard|" \
  337. "-attack_damage|-guard_damage|-level_up|-level_down|" \
  338. "-miss_attack|-miss_guard" \
  339. "-battle_start|-battle_end|-turn_start|-turn_end|" \
  340. "-global|-equip|-unequip|-add|-remove)?"
  341. Effect_Regex = /<eff: (\w+)#{triggers}(.*)>/i
  342. Ext_Regex = /<eff:\s*(\w+)#{triggers}>(.*?)<\/eff>/im
  343. CondEff_Regex = /<cond_eff: (\w+)#{triggers} ['"](.*)['"](.*)>/i
  344.  
  345. # Default effect code constants
  346.  
  347. EFFECT_RECOVER_HP = 11 # HP Recovery
  348. EFFECT_RECOVER_MP = 12 # MP Recovery
  349. EFFECT_GAIN_TP = 13 # TP Gain
  350. EFFECT_ADD_STATE = 21 # Add State
  351. EFFECT_REMOVE_STATE = 22 # Remove State
  352. EFFECT_ADD_BUFF = 31 # Add Buff
  353. EFFECT_ADD_DEBUFF = 32 # Add Debuff
  354. EFFECT_REMOVE_BUFF = 33 # Remove Buff
  355. EFFECT_REMOVE_DEBUFF = 34 # Remove Debuff
  356. EFFECT_SPECIAL = 41 # Special Effect
  357. EFFECT_GROW = 42 # Raise Parameter
  358. EFFECT_LEARN_SKILL = 43 # Learn Skill
  359. EFFECT_COMMON_EVENT = 44 # Common Events
  360.  
  361. # Mapping object types to effect types
  362. Effect_Types = {
  363. RPG::Actor => "actor",
  364. RPG::Class => "class",
  365. RPG::Item => "item",
  366. RPG::Skill => "item", # default engine treats them the same
  367. RPG::Weapon => "weapon",
  368. RPG::Armor => "armor",
  369. RPG::Enemy => "enemy",
  370. RPG::State => "state"
  371. }
  372.  
  373. # Mapping params to ID's
  374. Param_Table = {
  375. "mhp" => 0,
  376. "mmp" => 1,
  377. "atk" => 2,
  378. "def" => 3,
  379. "mat" => 4,
  380. "mdf" => 5,
  381. "agi" => 6,
  382. "luk" => 7
  383. }
  384.  
  385. # registers a new effect.
  386. # code -> a number that has not been reserved by another effect
  387. # data_id -> a special ID for the effect. Currently not used.
  388. # method_name -> a symbol. Name of the method to call for this effect
  389. # idstring -> a string. Used for note-tagging and other user-related things
  390. def self.register_effect(idstring, api_version=2.0)
  391. idstring = idstring.to_s
  392. key = idstring.to_sym
  393. if $imported["Effect_Manager"] < api_version
  394. outdated_api_warn(idstring, api_version)
  395. elsif @method_table.include?(key)
  396. dupe_entry_warn(key, @method_table[key])
  397. else
  398. @method_table[key] = idstring
  399. @regex_table[key] = idstring
  400. end
  401. end
  402.  
  403. # The initial table is the same as the one in the default scripts
  404. def self.initialize_tables
  405. @regex_table = {}
  406. @method_table = {
  407. EFFECT_RECOVER_HP => :item_effect_recover_hp,
  408. EFFECT_RECOVER_MP => :item_effect_recover_mp,
  409. EFFECT_GAIN_TP => :item_effect_gain_tp,
  410. EFFECT_ADD_STATE => :item_effect_add_state,
  411. EFFECT_REMOVE_STATE => :item_effect_remove_state,
  412. EFFECT_ADD_BUFF => :item_effect_add_buff,
  413. EFFECT_ADD_DEBUFF => :item_effect_add_debuff,
  414. EFFECT_REMOVE_BUFF => :item_effect_remove_buff,
  415. EFFECT_REMOVE_DEBUFF => :item_effect_remove_debuff,
  416. EFFECT_SPECIAL => :item_effect_special,
  417. EFFECT_GROW => :item_effect_grow,
  418. EFFECT_LEARN_SKILL => :item_effect_learn_skill,
  419. EFFECT_COMMON_EVENT => :item_effect_common_event,
  420. }
  421. end
  422.  
  423. # Returns the effect code for the particular string.
  424. def self.get_effect_code(sym)
  425. @regex_table[sym]
  426. end
  427.  
  428. def self.outdated_api_warn(idstring, version)
  429. msgbox("Warning: `%s` effect requires version %.2f of the script" %[idstring, version])
  430. end
  431.  
  432. def self.dupe_entry_warn(your_id, existing_name)
  433. msgbox("Warning: idstring %s has already been reserved" %[existing_name.to_s])
  434. end
  435.  
  436. def self.method_table
  437. @method_table
  438. end
  439.  
  440. # Setup the tables
  441. initialize_tables
  442. end
  443.  
  444. module RPG
  445.  
  446. class UsableItem::Effect
  447. attr_accessor :trigger
  448. attr_accessor :condition
  449. end
  450.  
  451. class BaseItem
  452. def effects
  453. load_notetag_effect_manager unless @effect_checked
  454. return @effects
  455. end
  456.  
  457. # Go through each line looking for effects. Note that the data id
  458. # is currently hardcoded to 0 since we don't really need it.
  459. def load_notetag_effect_manager
  460. @effects ||= []
  461. @effect_checked = true
  462.  
  463. # check for effects
  464. results = self.note.scan(Effect_Manager::Effect_Regex)
  465. results.each {|code, trigger, args|
  466. code = Effect_Manager.get_effect_code(code.to_sym)
  467. if code
  468. check_effect(code, trigger, args)
  469. @effects[-1].trigger = trigger ? trigger.gsub!("-", "") : nil
  470. end
  471. }
  472.  
  473. # check for conditional effects
  474. results = self.note.scan(Effect_Manager::CondEff_Regex)
  475. results.each {|code, trigger, cond, args|
  476. code = Effect_Manager.get_effect_code(code.to_sym)
  477. if code
  478. check_effect(code, trigger, args)
  479. @effects[-1].trigger = trigger ? trigger.gsub!("-", "") : nil
  480. @effects[-1].condition = cond
  481. end
  482. }
  483. end
  484.  
  485. def check_effect(code, trigger, args)
  486. if self.class.method_defined?("add_effect_#{code}")
  487. send("add_effect_#{code}", code.to_sym, 0, args.split)
  488. else
  489. add_effect(code.to_sym, 0, args.split)
  490. end
  491. end
  492.  
  493. def add_effect(code, data_id, args)
  494. @effects.push(RPG::UsableItem::Effect.new(code, data_id, args))
  495. end
  496. end
  497.  
  498. # Can't rely on inheritance because effects is declared as an
  499. # attr_accessor
  500. class UsableItem
  501. def effects
  502. load_notetag_effect_manager unless @effect_checked
  503. return @effects
  504. end
  505. end
  506. end
  507.  
  508. # Set the effect callback for the current scene
  509. module SceneManager
  510.  
  511. def self.set_effect_callback(method, effect)
  512. SceneManager.scene.set_effect_callback(method, effect)
  513. end
  514. end
  515.  
  516. # Want to store effect messages to be displayed by the battle log
  517. # Also want to store information like the battler's initial values because
  518. # effects are applied AFTER damage has been evaluated.
  519. class Game_ActionResult
  520.  
  521. attr_accessor :effect_results
  522. attr_reader :old_hp
  523. attr_reader :old_mp
  524. attr_reader :old_tp
  525.  
  526. alias :th_effect_manager_clear :clear
  527. def clear
  528. th_effect_manager_clear
  529. clear_effect_results
  530. clear_old_values
  531. end
  532.  
  533. def clear_old_values
  534. @old_hp = 0
  535. @old_mp = 0
  536. @old_tp = 0
  537. end
  538.  
  539. def clear_effect_results
  540. @effect_results = []
  541. end
  542.  
  543. alias :th_effect_manager_make_damage :make_damage
  544. def make_damage(value, item)
  545. @old_hp = @battler.hp
  546. @old_mp = @battler.mp
  547. @old_tp = @battler.tp
  548. th_effect_manager_make_damage(value, item)
  549. end
  550.  
  551. # Adds a message to the list of effect messages that should be
  552. # displayed
  553. def add_effect_message(msg)
  554. @effect_results.push(msg)
  555. end
  556. end
  557.  
  558. class Game_Battler < Game_BattlerBase
  559.  
  560. def effect_objects
  561. states
  562. end
  563.  
  564. #---------------------------------------------------------------------------
  565. # * adding some additional effect checks
  566. #---------------------------------------------------------------------------
  567.  
  568. # Trigger any attack/guard related effects
  569. alias :th_effect_manager_item_apply :item_apply
  570. def item_apply(user, item)
  571. th_effect_manager_item_apply(user, item)
  572. if @result.hit?
  573. if @result.critical
  574. check_critical_effects(user, item)
  575. check_crit_guard_effects(user, item)
  576. else
  577. check_attack_effects(user, item)
  578. check_guard_effects(user, item)
  579. end
  580. else
  581. check_miss_attack_effects(user, item)
  582. check_miss_guard_effects(user, item)
  583. end
  584. end
  585.  
  586. alias :th_effect_manager_make_dmg_value :make_damage_value
  587. def make_damage_value(user, item)
  588. th_effect_manager_make_dmg_value(user, item)
  589. check_pre_attack_effects(user, item)
  590. check_pre_guard_effects(user, item)
  591. end
  592.  
  593. # trigger any global effects
  594. alias :th_effect_manager_use_item :use_item
  595. def use_item(item)
  596. th_effect_manager_use_item(item)
  597. check_effects([item], "global")
  598. end
  599.  
  600. # new. Trigger turn start effects
  601. def on_turn_start
  602. check_turn_start_effects
  603. end
  604.  
  605. # Trigger turn end effects
  606. alias :th_effect_manager_turn_end :on_turn_end
  607. def on_turn_end
  608. th_effect_manager_turn_end
  609. check_turn_end_effects
  610. end
  611.  
  612. # Trigger battle start effects
  613. alias :th_effect_manager_battle_start :on_battle_start
  614. def on_battle_start
  615. th_effect_manager_battle_start
  616. check_battle_start_effects
  617. end
  618.  
  619. # Trigger battle end effects
  620. alias :th_effect_manager_battle_end :on_battle_end
  621. def on_battle_end
  622. check_battle_end_effects
  623. th_effect_manager_battle_end
  624. end
  625.  
  626. # Trigger state addition effects
  627. alias :th_effect_manager_add_new_state :add_new_state
  628. def add_new_state(state_id)
  629. check_state_add_effects(state_id)
  630. th_effect_manager_add_new_state(state_id)
  631. end
  632.  
  633. # Trigger state removal effects
  634. def erase_state(state_id)
  635. super
  636. check_state_remove_effects(state_id)
  637. end
  638.  
  639. #=============================================================================
  640. # * Apply the effect
  641. #=============================================================================
  642.  
  643. def get_effect_method_name(effect, type="", trigger="")
  644. method_name = Effect_Manager.method_table[effect.code].to_s
  645. return "" unless method_name
  646. # no specific effect trigger specified, then assume any trigger valid
  647. # or maybe it is just a default effect
  648. if effect.trigger.nil?
  649. if trigger.empty?
  650. method_name = sprintf("%s_effect_%s", type, method_name)
  651. else
  652. method_name = sprintf("%s_effect_%s_%s", type, method_name, trigger)
  653. end
  654. # otherwise, check if it's the specified trigger
  655.  
  656. elsif effect.trigger == trigger
  657. method_name = sprintf("%s_effect_%s_%s", type, method_name, trigger)
  658. else
  659. method_name = ""
  660. end
  661. return method_name.to_sym
  662. end
  663.  
  664. def eval_effect_cond(condition, a, b, v=$game_variables, s=$game_switches)
  665. return true unless condition
  666. eval(condition) rescue false
  667. end
  668.  
  669. def check_effect_condition(user, effect)
  670. user ? eval_effect_cond(effect.condition, user, self) : eval_effect_cond(effect.condition, self, self)
  671. end
  672.  
  673. # Apply custom effects. This should ignore all default effects since
  674. # they don't have anything special and shouldn't be called here anyways
  675. def effect_apply(user, obj, effect, type, trigger)
  676. return if effect.code.is_a?(Fixnum)
  677. return unless check_effect_condition(user, effect)
  678. method_name = get_effect_method_name(effect, type, trigger)
  679. if respond_to?(method_name)
  680. # someone used this against this battler
  681. if user
  682. send(method_name, user, obj, effect)
  683.  
  684. # effect was triggered by the system
  685. else
  686. send(method_name, obj, effect)
  687. end
  688. end
  689. end
  690.  
  691. # overwritten. Table is now grabbed from a dynamically-created table
  692. def item_effect_apply(user, item, effect)
  693. return unless check_effect_condition(user, effect)
  694. method_name = Effect_Manager.method_table[effect.code]
  695. unless method_name.to_s.start_with?("item_effect")
  696. method_name = get_effect_method_name(effect, "item", "")
  697. end
  698. send(method_name, user, item, effect) if respond_to?(method_name)
  699. end
  700.  
  701. #---------------------------------------------------------------------------
  702. # Check if there are effects to apply other than the item used
  703. #---------------------------------------------------------------------------
  704.  
  705. # This method basically checks the effects for all effect objects
  706. def check_effects(objects, trigger, user=nil, item=nil)
  707. objects.each {|obj|
  708. type = type || Effect_Manager::Effect_Types[obj.class]
  709. obj.effects.each {|effect|
  710. effect_apply(user, obj, effect, type, trigger)
  711. }
  712. }
  713. end
  714.  
  715. # Triggers for all effect objects
  716.  
  717. # Triggered after basic damage calculation is done, but before damage
  718. # is executed
  719. def check_pre_attack_effects(user, item)
  720. check_effects(user.effect_objects, "pre_attack", user, item)
  721. end
  722.  
  723. # Same as attack_damage, except on the guard side
  724. def check_pre_guard_effects(user, item)
  725. check_effects(effect_objects, "pre_guard", user, item)
  726. end
  727.  
  728. # Attack effects are applied whenever the battler successfully hits
  729. def check_attack_effects(user, item)
  730. check_effects(user.effect_objects, "attack", user, item)
  731. end
  732.  
  733. # Guard effects are applied whenever you are hit
  734. def check_guard_effects(user, item)
  735. check_effects(effect_objects, "guard", user, item)
  736. end
  737.  
  738. # Critical effects applied when critical hit is dealt
  739. def check_critical_effects(user, item)
  740. check_effects(user.effect_objects, "crit_attack", user, item)
  741. end
  742.  
  743. def check_crit_guard_effects(user, item)
  744. check_effects(effect_objects, "crit_guard", user, item)
  745. end
  746.  
  747. def check_miss_attack_effects(user, item)
  748. check_effects(user.effect_objects, "miss_attack", user, item)
  749. end
  750.  
  751. def check_miss_guard_effects(user, item)
  752. check_effects(effect_objects, "miss_guard", user, item)
  753. end
  754.  
  755. def check_global_effects(user, item)
  756. check_effects(user.effect_objects, "global")
  757. end
  758.  
  759. def check_troop_effects
  760. check_effects(effect_objects, "troop")
  761. end
  762.  
  763. def check_level_up_effects
  764. check_effects(effect_objects, "level_up")
  765. end
  766.  
  767. def check_level_down_effects
  768. check_effects(effect_objects, "level_down")
  769. end
  770.  
  771. # Effects are applied at the start of the battle
  772. def check_battle_start_effects
  773. check_effects(effect_objects, "battle_start")
  774. end
  775.  
  776. # Effects triggered at the end of the battle
  777. def check_battle_end_effects
  778. check_effects(effect_objects, "battle_end")
  779. end
  780.  
  781. # Effects triggered at the start of each turn
  782. def check_turn_start_effects
  783. check_effects(effect_objects, "turn_start")
  784. end
  785.  
  786. # Effects triggered at the end of each turn
  787. def check_turn_end_effects
  788. check_effects(effect_objects, "turn_end")
  789. end
  790.  
  791. def check_die_effects
  792. check_effects(effect_objects, "die")
  793. end
  794.  
  795. # Triggers for specific objects
  796.  
  797. def check_equip_effects(equip)
  798. end
  799.  
  800. def check_unequip_effects(equip)
  801. end
  802.  
  803. def check_state_add_effects(state_id)
  804. state = $data_states[state_id]
  805. state.effects.each {|effect| effect_apply(nil, state, effect, "state", "add")}
  806. end
  807.  
  808. def check_state_remove_effects(state_id)
  809. state = $data_states[state_id]
  810. state.effects.each {|effect| effect_apply(nil, state, effect, "state", "remove")}
  811. end
  812. end
  813.  
  814. # Attack effects process the user's effects
  815. class Game_Enemy < Game_Battler
  816.  
  817. def effect_objects
  818. super + [enemy]
  819. end
  820. end
  821.  
  822. class Game_Actor < Game_Battler
  823.  
  824. def effect_objects
  825. super + [actor] + [self.class] + weapons + armors + skills
  826. end
  827.  
  828. alias :th_effect_manager_level_up :level_up
  829. def level_up
  830. th_effect_manager_level_up
  831. check_level_up_effects
  832. end
  833.  
  834. alias :th_effect_manager_level_down :level_down
  835. def level_down
  836. th_effect_manager_level_down
  837. check_level_down_effects
  838. end
  839.  
  840. # Trigger equip/unequip effects
  841. alias :th_effect_manager_change_equip :change_equip
  842. def change_equip(slot_id, item)
  843.  
  844. # keep track of the old one...just in case we actually need it
  845. old_item = @equips[slot_id].object
  846. th_effect_manager_change_equip(slot_id, item)
  847.  
  848. # Now to check effect triggers
  849. if item
  850. # We are equipping something different
  851. if item != old_item
  852. # There was something in the slot
  853. if old_item
  854. check_equip_effects(item)
  855. check_unequip_effects(old_item)
  856. else
  857. check_equip_effects(item)
  858. end
  859. end
  860. else
  861. # We are unequipping something
  862. if old_item
  863. check_unequip_effects(old_item)
  864. end
  865. end
  866. end
  867.  
  868. def check_equip_effects(equip)
  869. super
  870. check_effects([equip], "equip")
  871. end
  872.  
  873. def check_unequip_effects(equip)
  874. super
  875. check_effects([equip], "unequip")
  876. end
  877. end
  878.  
  879.  
  880. class Game_Troop < Game_Unit
  881.  
  882. #-----------------------------------------------------------------------------
  883. # Add "Troop" trigger, which is activated after a troop event is executed.
  884. #-----------------------------------------------------------------------------
  885. alias :th_effect_manager_setup_battle_event :setup_battle_event
  886. def setup_battle_event
  887. return if @interpreter.running? || @interpreter.setup_reserved_common_event
  888. th_effect_manager_setup_battle_event
  889.  
  890. # This assumes that the interpreter does not finish executing before
  891. # we get here
  892. if $game_troop.interpreter.running?
  893. @interpreter.call_troop_effect
  894. end
  895. end
  896. end
  897.  
  898. class Game_Interpreter
  899.  
  900. # Trigger troop effects after execution completes
  901. def call_troop_effect
  902. @troop_effect = true
  903. end
  904.  
  905. alias :th_effect_manager_run :run
  906. def run
  907. th_effect_manager_run
  908. if @troop_effect
  909. ($game_party.members | $game_troop.members).each {|member| member.check_troop_effects}
  910. @troop_effect = false
  911. end
  912. end
  913. end
  914.  
  915. # Allow scenes to store an effect callback, which can be set when the scene
  916. # is called
  917. class Scene_Base
  918.  
  919. def set_effect_callback(method, effect)
  920. @effect_callback = method
  921. @effect = effect
  922. end
  923. end
  924.  
  925. class Scene_Battle < Scene_Base
  926.  
  927. alias :th_effect_manager_turn_start :turn_start
  928. def turn_start
  929. th_effect_manager_turn_start
  930. all_battle_members.each do |battler|
  931. battler.on_turn_start
  932. refresh_status
  933. end
  934. end
  935. end
  936.  
  937. # Display all of the effect messages. Since I couldn't find a nice place to
  938. # put it I simply put it before the affected status, which is ok to come near
  939. # the end...
  940. class Window_BattleLog
  941.  
  942. alias :th_effect_manager_display_status :display_affected_status
  943. def display_affected_status(target, item)
  944. target.result.effect_results.each {|msg|
  945. add_text(msg)
  946. wait
  947. }
  948. th_effect_manager_display_status(target, item)
  949. end
  950. end
RAW Paste Data