查看: 3667|回复: 2

[已经解决] 怎么弄出武器吸血的效果

[复制链接]
梦石
0
星屑
771
在线时间
83 小时
注册时间
2020-4-10
回帖
38
发表于 2021-2-27 10:02:38 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
想弄出一个类似tr的吸血飞刀的那种攻击附带吸血的武器,怎么整啊
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2021-2-27 10:24:18 | 显示全部楼层
本帖最后由 alexncf125 于 2021-2-27 10:30 编辑

前置
  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. Should be compatible with most systems.
  81. This script replaces one method
  82.    -Game_Battler # item_effect_apply  

  83. ------------------------------------------------------------------------------
  84. ** Description

  85. This script replaces the default Effects handlers with a plugin-based
  86. effect system. It is meant to allow developers to easily develop new
  87. effects without having to concern with the minor details.

  88. You can define new effects by simply registering it, defining a method,
  89. and then note-tagging your database objects.

  90. Additional item/skill effects can be easily added.
  91. This script extends effects to all RPG::BaseItem classes, although only
  92. some have been implemented.

  93. ------------------------------------------------------------------------------
  94. ** Terminology

  95. This script uses specific terminology that I have defined.

  96. *   Effect plugin
  97.    Any script that is registered to the Effect Manager are called "plugins".

  98. *   Effect objects
  99.    Or simply "objects". These are any objects that you can add effects to.
  100.    The default engine allows items and skills to have effects. This script
  101.    extends this to actors, class, weapons, armors, enemies, and states.

  102. *   Id String   
  103.    The name of an effect. Used throughout your script and notetags.
  104.    Every plugin must have a unique idstring.

  105. *   Effect Type
  106.    Determined by the object the effect is assigned to.
  107.    For example, effects that are assigned to a weapon are "weapon effects"
  108.    
  109. *   Effect Triggers
  110.    Specifies when an effect will be activated.
  111.    For example, an "attack trigger" requires your battler to be "attacking"
  112.    another target.
  113.    
  114. *   Effect Conditions
  115.    Conditions that must be met in order for an effect to activate.
  116.    These are checked after an effect is triggered, but before the effect
  117.    is applied

  118. ------------------------------------------------------------------------------
  119. ** Usage

  120. All effects that are written for this script are added to objects using
  121. note tags.

  122. The basic format of the note tag is

  123.     <eff: idstring arg1 arg2 ... >
  124.    
  125. Where
  126.    `idstring`        is the name of effect that you want to add,
  127.    `arg1, arg2, ...` are a list of arguments that the effect requires
  128.    
  129. You can specify effects with conditions by using the format:

  130.     <cond_eff: idstring cond arg1 arg2 ... >
  131.    
  132. Where
  133.    `cond`  is a ruby expression that evaluates to true or false that contains
  134.            no spaces
  135.    
  136. The only difference between the two note-tags is that one allows you to
  137. specify conditions while the other does not.
  138.    
  139. Instructions should be provided with the effect plugin describing what each
  140. argument represents.

  141. By default, if you simply write the idstring of the effect, then it is assumed
  142. to activate under any effect trigger. If you wish to specify the triggers that
  143. it will activate under, you should write it as

  144.     <eff: idstring-TRIGGER arg1 arg2 ... >
  145.    
  146. Where `TRIGGER` is an effect trigger. You can look at the list of triggers
  147. available in the reference list below, although a plugin may choose not to
  148. implement every trigger available. Check with the plugin author to see what
  149. kinds of triggers are available.

  150. ------------------------------------------------------------------------------
  151. ** Reference

  152. This is a list of effect types that are currently supported:

  153. * actor       - applies to actors
  154. * class       - applies to classes
  155. * item        - applies to items/skills
  156. * skill       - applies to skills
  157. * weapon      - applies to weapons
  158. * armor       - applies to armors
  159. * enemy       - applies to enemies
  160. * state       - applies to states

  161. Note that actors and enemies currently only support passive triggers.

  162. This is a list of effect triggers that are currently supported:

  163. * attack        - triggered when an action hits a battler
  164. * guard         - triggered when a battler is hit by an action
  165. * crit_attack   - triggered when a critical hit is inflicted
  166. * crit_guard    - triggered when a battler received a critical hit
  167. * pre_attack    - triggered before damage from action is applied, attack side
  168. * pre_guard     - triggered before damage from action is applied, guard side
  169. * miss_attack   - triggered when an action misses, attack side
  170. * miss_guard    - triggered when an action misses, guard side
  171. * level_up      - when you increase a level
  172. * level_down    - when you decrease a level
  173. * battle_start  - triggered at the beginning of the battle
  174. * battle_end    - triggered at the end of the battle
  175. * turn_start    - triggered at the start of each turn
  176. * turn_end      - triggered at the end of each turn
  177. * equip         - equip trigger. When you equip a weapon/armor
  178. * unequip       - equip trigger. When you unequip a weapon/armor
  179. * add           - state trigger. When a state is added
  180. * remove        - state trigger. When a state is removed.
  181. * global        - special trigger. When an item/skill is used
  182. * troop         - special trigger. When a battle event has executed

  183. There are two general types of methods signatures

  184. 1. TYPE_effect_NAME_TRIGGER(user, obj, effect)

  185.    This applies to any trigger where two battlers are involved, such as
  186.    attack, guard, or critical.
  187.    
  188. 2. TYPE_effect_NAME_TRIGGER(obj, effect)

  189.    This applies to any trigger that involve only one battler. Basically every
  190.    other trigger since there is no other battler.

  191. ------------------------------------------------------------------------------
  192. ** Plugin Developers

  193. This section is for users that wish to develop their own plugins for the
  194. Effect Manager. It will walk through various features that are available
  195. for you.
  196.    
  197.    == Making your plugin ==

  198. So we start by understanding how to write an effect plugin.
  199. Defining new effects is a simple 3-step process

  200. 1: at the top of your script, add a single call to register your effect.

  201.     Effect_Manager.register_effect(idstring, api_version)
  202.    
  203.     where
  204.       `idstring`    is a string that you will use to refer to your effect.
  205.       `api_version` is the version of the Effect Manager that your script
  206.                     runs under. If the user's version is outdated, a popup
  207.                     will appear alerting that the plugin is incompatible. The
  208.                     default version required is 2.0
  209.                     
  210.     As an example, we'll register a new effect called "test_effect"
  211.    
  212.        Effect_Manager.register_effect(:test_effect, 2.0)
  213.       
  214. 2: Define the method for your effect in Game_Battler or its child classes.
  215.     Depending on where it should be triggered, the name will be different.
  216.    
  217.     The format of the method name is defined above in the reference, so for
  218.     example you might have something like
  219.    
  220.        def item_effect_test_effect(user, item, effect)
  221.          args = effect.value1
  222.        end
  223.    
  224. 3: Instruct your users to tag their objects with the following note tag:

  225.        <eff: test_effect arg1 arg2 arg3 ...>

  226.    == Storing and retrieving arguments ==
  227.       
  228. By default, any arguments that are passed to your effect will be stored in
  229. an effect object as an array of strings. In step 2 above, you see that you are
  230. given a reference to your effect. You can access the arguments using

  231.     effect.value1
  232.    
  233. If you would like to type cast your arguments beforehand, you can define this
  234. method in any RPG::BaseItem classes:

  235.     def add_effect_IDSTRING(code, data_id, args)
  236.       # type cast your args here
  237.       
  238.       # now add the effect to the object
  239.       add_effect(code, data_id, args)
  240.     end
  241.    
  242. Simply replace IDSTRING with the name that you registered in step 1.

  243.    == Working with custom messages ==
  244.    
  245. A simple way to inform users that something has happened is to simply add
  246. messages to $game_message:

  247.    $game_message.add_message("your results")
  248.    
  249. In addition, I have provided you a special way to store messages from your
  250. effects so that they will appear in the battle log during battle.

  251. The Game_ActionResult class holds an `effect_results` array that will store
  252. an array of strings. So the usual way of adding an effect message is

  253.     @result.effect_results.append(YOUR_MESSAGE)
  254.    
  255.     == Using effect callbacks ==
  256.    
  257. Sometimes, your effects require user input, which may occur on a different
  258. scene. Because the effect evaluation will end when you switch to another
  259. scene, you will need a way to remember which effect is currently activated.

  260. This can be accomplished using the following sequence of calls

  261.    SceneManager.call(YOUR_NEW_SCENE)
  262.    SceneManager.set_effect_callback(:method_name, effect)
  263.    
  264. By setting the effect callback, you are able to trigger a custom method
  265. for your effect processing.
  266.    
  267.     == Other stuff that may be of interest ==
  268.    
  269. I have added some extra attributes for convenience in the following classes.

  270. Game_ActionResult
  271.    old_hp : stores the battler's HP before damage is applied
  272.    old_mp : stores the battler's MP before damage is applied
  273.    old_tp : stores the battler's TP before damage is applied
  274.    
  275. If you need to access the current action to get any information about what
  276. was executed, you can use the following

  277.    user.current_action
  278.    user.current_action.item
  279.    
  280. #==============================================================================
  281. =end
  282. $imported = {} if $imported.nil?
  283. $imported["Effect_Manager"] = 2.6
  284. #==============================================================================
  285. # ** Rest of the script
  286. #==============================================================================

  287. module Effect_Manager
  288.   
  289.   # The format of all note tags
  290.   triggers = "(-attack|-guard|-crit_attack|-crit_guard|"         \
  291.              "-attack_damage|-guard_damage|-level_up|-level_down|" \
  292.              "-miss_attack|-miss_guard" \
  293.              "-battle_start|-battle_end|-turn_start|-turn_end|" \
  294.              "-global|-equip|-unequip|-add|-remove)?"           
  295.   Effect_Regex = /<eff: (\w+)#{triggers}(.*)>/i
  296.   Ext_Regex = /<eff:\s*(\w+)#{triggers}>(.*?)<\/eff>/im
  297.   CondEff_Regex = /<cond_eff: (\w+)#{triggers} ['"](.*)['"](.*)>/i
  298.   
  299.   # Default effect code constants
  300.   
  301.   EFFECT_RECOVER_HP     = 11              # HP Recovery
  302.   EFFECT_RECOVER_MP     = 12              # MP Recovery
  303.   EFFECT_GAIN_TP        = 13              # TP Gain
  304.   EFFECT_ADD_STATE      = 21              # Add State
  305.   EFFECT_REMOVE_STATE   = 22              # Remove State
  306.   EFFECT_ADD_BUFF       = 31              # Add Buff
  307.   EFFECT_ADD_DEBUFF     = 32              # Add Debuff
  308.   EFFECT_REMOVE_BUFF    = 33              # Remove Buff
  309.   EFFECT_REMOVE_DEBUFF  = 34              # Remove Debuff
  310.   EFFECT_SPECIAL        = 41              # Special Effect
  311.   EFFECT_GROW           = 42              # Raise Parameter
  312.   EFFECT_LEARN_SKILL    = 43              # Learn Skill
  313.   EFFECT_COMMON_EVENT   = 44              # Common Events
  314.   
  315.   # Mapping object types to effect types
  316.   Effect_Types = {
  317.     RPG::Actor   => "actor",
  318.     RPG::Class   => "class",
  319.     RPG::Item    => "item",
  320.     RPG::Skill   => "item",    # default engine treats them the same
  321.     RPG::Weapon  => "weapon",
  322.     RPG::Armor   => "armor",
  323.     RPG::Enemy   => "enemy",
  324.     RPG::State   => "state"
  325.   }
  326.   
  327.   # Mapping params to ID's
  328.   Param_Table = {
  329.     "mhp" => 0,
  330.     "mmp" => 1,
  331.     "atk" => 2,
  332.     "def" => 3,
  333.     "mat" => 4,
  334.     "mdf" => 5,
  335.     "agi" => 6,
  336.     "luk" => 7
  337.   }
  338.   
  339.   # registers a new effect.
  340.   #   code -> a number that has not been reserved by another effect
  341.   #   data_id -> a special ID for the effect. Currently not used.
  342.   #   method_name -> a symbol. Name of the method to call for this effect
  343.   #   idstring -> a string. Used for note-tagging and other user-related things  
  344.   def self.register_effect(idstring, api_version=2.0)
  345.     idstring = idstring.to_s
  346.     key = idstring.to_sym
  347.     if $imported["Effect_Manager"] < api_version
  348.       outdated_api_warn(idstring, api_version)
  349.     elsif @method_table.include?(key)
  350.       dupe_entry_warn(key, @method_table[key])
  351.     else
  352.       @method_table[key] = idstring
  353.       @regex_table[key] = idstring
  354.     end
  355.   end
  356.   
  357.   # The initial table is the same as the one in the default scripts
  358.   def self.initialize_tables
  359.     @regex_table = {}
  360.     @method_table = {
  361.       EFFECT_RECOVER_HP    => :item_effect_recover_hp,
  362.       EFFECT_RECOVER_MP    => :item_effect_recover_mp,
  363.       EFFECT_GAIN_TP       => :item_effect_gain_tp,
  364.       EFFECT_ADD_STATE     => :item_effect_add_state,
  365.       EFFECT_REMOVE_STATE  => :item_effect_remove_state,
  366.       EFFECT_ADD_BUFF      => :item_effect_add_buff,
  367.       EFFECT_ADD_DEBUFF    => :item_effect_add_debuff,
  368.       EFFECT_REMOVE_BUFF   => :item_effect_remove_buff,
  369.       EFFECT_REMOVE_DEBUFF => :item_effect_remove_debuff,
  370.       EFFECT_SPECIAL       => :item_effect_special,
  371.       EFFECT_GROW          => :item_effect_grow,
  372.       EFFECT_LEARN_SKILL   => :item_effect_learn_skill,
  373.       EFFECT_COMMON_EVENT  => :item_effect_common_event,
  374.     }
  375.   end
  376.   
  377.   # Returns the effect code for the particular string.
  378.   def self.get_effect_code(sym)
  379.     @regex_table[sym]
  380.   end
  381.   
  382.   def self.outdated_api_warn(idstring, version)
  383.     msgbox("Warning: `%s` effect requires version %.2f of the script" %[idstring, version])
  384.   end
  385.   
  386.   def self.dupe_entry_warn(your_id, existing_name)
  387.     msgbox("Warning: idstring %s has already been reserved" %[existing_name.to_s])
  388.   end
  389.   
  390.   def self.method_table
  391.     @method_table
  392.   end
  393.   
  394.   # Setup the tables
  395.   initialize_tables
  396. end

  397. module RPG
  398.   
  399.   class UsableItem::Effect
  400.     attr_accessor :trigger
  401.     attr_accessor :condition
  402.   end
  403.   
  404.   class BaseItem
  405.     def effects
  406.       load_notetag_effect_manager unless @effect_checked
  407.       return @effects
  408.     end
  409.    
  410.     # Go through each line looking for effects. Note that the data id
  411.     # is currently hardcoded to 0 since we don't really need it.
  412.     def load_notetag_effect_manager
  413.       @effects ||= []
  414.       @effect_checked = true
  415.       
  416.       # check for effects
  417.       results = self.note.scan(Effect_Manager::Effect_Regex)
  418.       results.each {|code, trigger, args|
  419.         code = Effect_Manager.get_effect_code(code.to_sym)
  420.         if code
  421.           check_effect(code, trigger, args)
  422.           @effects[-1].trigger = trigger ? trigger.gsub!("-", "") : nil
  423.         end
  424.       }
  425.       
  426.       # check for conditional effects
  427.       results = self.note.scan(Effect_Manager::CondEff_Regex)
  428.       results.each {|code, trigger, cond, args|
  429.         code = Effect_Manager.get_effect_code(code.to_sym)
  430.         if code
  431.           check_effect(code, trigger, args)
  432.           @effects[-1].trigger = trigger ? trigger.gsub!("-", "") : nil
  433.           @effects[-1].condition = cond
  434.         end
  435.       }
  436.     end
  437.    
  438.     def check_effect(code, trigger, args)
  439.       if self.class.method_defined?("add_effect_#{code}")
  440.         send("add_effect_#{code}", code.to_sym, 0, args.split)
  441.       else
  442.         add_effect(code.to_sym, 0, args.split)
  443.       end
  444.     end
  445.    
  446.     def add_effect(code, data_id, args)
  447.       @effects.push(RPG::UsableItem::Effect.new(code, data_id, args))
  448.     end
  449.   end
  450.   
  451.   # Can't rely on inheritance because effects is declared as an
  452.   # attr_accessor
  453.   class UsableItem
  454.     def effects
  455.       load_notetag_effect_manager unless @effect_checked
  456.       return @effects
  457.     end
  458.   end
  459. end

  460. # Set the effect callback for the current scene
  461. module SceneManager
  462.   
  463.   def self.set_effect_callback(method, effect)
  464.     SceneManager.scene.set_effect_callback(method, effect)
  465.   end
  466. end

  467. # Want to store effect messages to be displayed by the battle log
  468. # Also want to store information like the battler's initial values because
  469. # effects are applied AFTER damage has been evaluated.
  470. class Game_ActionResult
  471.   
  472.   attr_accessor :effect_results
  473.   attr_reader :old_hp
  474.   attr_reader :old_mp
  475.   attr_reader :old_tp
  476.   
  477.   alias :th_effect_manager_clear :clear
  478.   def clear
  479.     th_effect_manager_clear
  480.     clear_effect_results
  481.     clear_old_values
  482.   end
  483.   
  484.   def clear_old_values
  485.     @old_hp = 0
  486.     @old_mp = 0
  487.     @old_tp = 0
  488.   end
  489.   
  490.   def clear_effect_results
  491.     @effect_results = []
  492.   end
  493.   
  494.   alias :th_effect_manager_make_damage :make_damage
  495.   def make_damage(value, item)
  496.     @old_hp = @battler.hp
  497.     @old_mp = @battler.mp
  498.     @old_tp = @battler.tp
  499.     th_effect_manager_make_damage(value, item)
  500.   end
  501.   
  502.   # Adds a message to the list of effect messages that should be
  503.   # displayed
  504.   def add_effect_message(msg)
  505.     @effect_results.push(msg)
  506.   end
  507. end

  508. class Game_Battler < Game_BattlerBase
  509.   
  510.   def effect_objects
  511.     states
  512.   end

  513.   #---------------------------------------------------------------------------
  514.   # * adding some additional effect checks
  515.   #---------------------------------------------------------------------------
  516.   
  517.   # Trigger any attack/guard related effects
  518.   alias :th_effect_manager_item_apply :item_apply
  519.   def item_apply(user, item)
  520.     th_effect_manager_item_apply(user, item)
  521.     if @result.hit?
  522.       if @result.critical
  523.         check_critical_effects(user, item)
  524.         check_crit_guard_effects(user, item)
  525.       else
  526.         check_attack_effects(user, item)
  527.         check_guard_effects(user, item)
  528.       end
  529.     else
  530.       check_miss_attack_effects(user, item)
  531.       check_miss_guard_effects(user, item)
  532.     end
  533.   end
  534.   
  535.   alias :th_effect_manager_make_dmg_value :make_damage_value
  536.   def make_damage_value(user, item)
  537.     th_effect_manager_make_dmg_value(user, item)
  538.     check_pre_attack_effects(user, item)   
  539.     check_pre_guard_effects(user, item)
  540.   end
  541.   
  542.   # trigger any global effects
  543.   alias :th_effect_manager_use_item :use_item
  544.   def use_item(item)
  545.     th_effect_manager_use_item(item)
  546.     check_effects([item], "global")
  547.   end
  548.   
  549.   # new. Trigger turn start effects
  550.   def on_turn_start
  551.     check_turn_start_effects
  552.   end
  553.   
  554.   # Trigger turn end effects
  555.   alias :th_effect_manager_turn_end :on_turn_end
  556.   def on_turn_end
  557.     th_effect_manager_turn_end
  558.     check_turn_end_effects
  559.   end
  560.   
  561.   # Trigger battle start effects
  562.   alias :th_effect_manager_battle_start :on_battle_start
  563.   def on_battle_start
  564.     th_effect_manager_battle_start
  565.     check_battle_start_effects
  566.   end
  567.   
  568.   # Trigger battle end effects
  569.   alias :th_effect_manager_battle_end :on_battle_end
  570.   def on_battle_end
  571.     check_battle_end_effects
  572.     th_effect_manager_battle_end
  573.   end
  574.   
  575.   # Trigger state addition effects
  576.   alias :th_effect_manager_add_new_state :add_new_state
  577.   def add_new_state(state_id)
  578.     check_state_add_effects(state_id)
  579.     th_effect_manager_add_new_state(state_id)
  580.   end
  581.   
  582.   # Trigger state removal effects
  583.   def erase_state(state_id)
  584.     super
  585.     check_state_remove_effects(state_id)
  586.   end
  587.   
  588.   #=============================================================================
  589.   # * Apply the effect
  590.   #=============================================================================
  591.   
  592.   def get_effect_method_name(effect, type="", trigger="")
  593.     method_name = Effect_Manager.method_table[effect.code].to_s
  594.     return "" unless method_name
  595.     # no specific effect trigger specified, then assume any trigger valid
  596.     # or maybe it is just a default effect
  597.     if effect.trigger.nil?      
  598.       if trigger.empty?
  599.         method_name = sprintf("%s_effect_%s", type, method_name)
  600.       else
  601.         method_name = sprintf("%s_effect_%s_%s", type, method_name, trigger)
  602.       end
  603.     # otherwise, check if it's the specified trigger
  604.    
  605.     elsif effect.trigger == trigger
  606.       method_name = sprintf("%s_effect_%s_%s", type, method_name, trigger)
  607.     else
  608.       method_name = ""
  609.     end
  610.     return method_name.to_sym
  611.   end
  612.   
  613.   def eval_effect_cond(condition, a, b, v=$game_variables, s=$game_switches)
  614.     return true unless condition
  615.     eval(condition) rescue false
  616.   end
  617.   
  618.   def check_effect_condition(user, effect)
  619.     user ? eval_effect_cond(effect.condition, user, self) : eval_effect_cond(effect.condition, self, self)
  620.   end
  621.         
  622.   # Apply custom effects. This should ignore all default effects since
  623.   # they don't have anything special and shouldn't be called here anyways
  624.   def effect_apply(user, obj, effect, type, trigger)
  625.     return if effect.code.is_a?(Fixnum)
  626.     return unless check_effect_condition(user, effect)
  627.     method_name = get_effect_method_name(effect, type, trigger)
  628.     if respond_to?(method_name)
  629.       # someone used this against this battler
  630.       if user
  631.         send(method_name, user, obj, effect)
  632.         
  633.       # effect was triggered by the system
  634.       else
  635.         send(method_name, obj, effect)
  636.       end
  637.     end
  638.   end
  639.   
  640.   # overwritten. Table is now grabbed from a dynamically-created table
  641.   def item_effect_apply(user, item, effect)
  642.     return unless check_effect_condition(user, effect)
  643.     method_name = Effect_Manager.method_table[effect.code]
  644.     unless method_name.to_s.start_with?("item_effect")
  645.       method_name = get_effect_method_name(effect, "item", "")
  646.     end
  647.     send(method_name, user, item, effect) if respond_to?(method_name)
  648.   end
  649.   
  650.   #---------------------------------------------------------------------------
  651.   # Check if there are effects to apply other than the item used
  652.   #---------------------------------------------------------------------------
  653.   
  654.   # This method basically checks the effects for all effect objects
  655.   def check_effects(objects, trigger, user=nil, item=nil)
  656.     objects.each {|obj|
  657.       type = type || Effect_Manager::Effect_Types[obj.class]
  658.       obj.effects.each {|effect|
  659.         effect_apply(user, obj, effect, type, trigger)
  660.       }
  661.     }
  662.   end
  663.   
  664.   # Triggers for all effect objects
  665.   
  666.   # Triggered after basic damage calculation is done, but before damage
  667.   # is executed
  668.   def check_pre_attack_effects(user, item)
  669.     check_effects(user.effect_objects, "pre_attack", user, item)
  670.   end
  671.   
  672.   # Same as attack_damage, except on the guard side
  673.   def check_pre_guard_effects(user, item)
  674.     check_effects(effect_objects, "pre_guard", user, item)
  675.   end
  676.   
  677.   # Attack effects are applied whenever the battler successfully hits
  678.   def check_attack_effects(user, item)
  679.     check_effects(user.effect_objects, "attack", user, item)
  680.   end
  681.   
  682.   # Guard effects are applied whenever you are hit
  683.   def check_guard_effects(user, item)
  684.     check_effects(effect_objects, "guard", user, item)
  685.   end
  686.   
  687.   # Critical effects applied when critical hit is dealt
  688.   def check_critical_effects(user, item)
  689.     check_effects(user.effect_objects, "crit_attack", user, item)
  690.   end
  691.   
  692.   def check_crit_guard_effects(user, item)
  693.     check_effects(effect_objects, "crit_guard", user, item)
  694.   end
  695.   
  696.   def check_miss_attack_effects(user, item)
  697.     check_effects(user.effect_objects, "miss_attack", user, item)
  698.   end
  699.   
  700.   def check_miss_guard_effects(user, item)
  701.     check_effects(effect_objects, "miss_guard", user, item)
  702.   end
  703.   
  704.   def check_global_effects(user, item)
  705.     check_effects(user.effect_objects, "global")
  706.   end
  707.   
  708.   def check_troop_effects
  709.     check_effects(effect_objects, "troop")
  710.   end
  711.   
  712.   def check_level_up_effects
  713.     check_effects(effect_objects, "level_up")
  714.   end
  715.   
  716.   def check_level_down_effects
  717.     check_effects(effect_objects, "level_down")
  718.   end
  719.   
  720.   # Effects are applied at the start of the battle
  721.   def check_battle_start_effects
  722.     check_effects(effect_objects, "battle_start")
  723.   end
  724.   
  725.   # Effects triggered at the end of the battle
  726.   def check_battle_end_effects
  727.     check_effects(effect_objects, "battle_end")
  728.   end
  729.   
  730.   # Effects triggered at the start of each turn
  731.   def check_turn_start_effects
  732.     check_effects(effect_objects, "turn_start")
  733.   end
  734.   
  735.   # Effects triggered at the end of each turn
  736.   def check_turn_end_effects
  737.     check_effects(effect_objects, "turn_end")
  738.   end
  739.   
  740.   def check_die_effects
  741.     check_effects(effect_objects, "die")
  742.   end
  743.   
  744.   # Triggers for specific objects
  745.   
  746.   def check_equip_effects(equip)
  747.   end
  748.   
  749.   def check_unequip_effects(equip)
  750.   end
  751.   
  752.   def check_state_add_effects(state_id)
  753.     state = $data_states[state_id]
  754.     state.effects.each {|effect| effect_apply(nil, state, effect, "state", "add")}
  755.   end
  756.   
  757.   def check_state_remove_effects(state_id)
  758.     state = $data_states[state_id]
  759.     state.effects.each {|effect| effect_apply(nil, state, effect, "state", "remove")}
  760.   end
  761. end

  762. # Attack effects process the user's effects
  763. class Game_Enemy < Game_Battler
  764.   
  765.   def effect_objects
  766.     super + [enemy]
  767.   end
  768. end

  769. class Game_Actor < Game_Battler
  770.   
  771.   def effect_objects
  772.     super + [actor] + [self.class] + weapons + armors + skills
  773.   end
  774.   
  775.   alias :th_effect_manager_level_up :level_up
  776.   def level_up
  777.     th_effect_manager_level_up
  778.     check_level_up_effects
  779.   end
  780.   
  781.   alias :th_effect_manager_level_down :level_down
  782.   def level_down
  783.     th_effect_manager_level_down
  784.     check_level_down_effects
  785.   end
  786.   
  787.   # Trigger equip/unequip effects
  788.   alias :th_effect_manager_change_equip :change_equip
  789.   def change_equip(slot_id, item)
  790.    
  791.     # keep track of the old one...just in case we actually need it
  792.     old_item = @equips[slot_id].object
  793.     th_effect_manager_change_equip(slot_id, item)
  794.    
  795.     # Now to check effect triggers
  796.     if item
  797.       # We are equipping something different
  798.       if item != old_item
  799.         # There was something in the slot
  800.         if old_item
  801.           check_equip_effects(item)
  802.           check_unequip_effects(old_item)
  803.         else         
  804.           check_equip_effects(item)
  805.         end
  806.       end
  807.     else
  808.       # We are unequipping something
  809.       if old_item
  810.         check_unequip_effects(old_item)
  811.       end
  812.     end
  813.   end
  814.   
  815.   def check_equip_effects(equip)
  816.     super
  817.     check_effects([equip], "equip")
  818.   end
  819.   
  820.   def check_unequip_effects(equip)
  821.     super
  822.     check_effects([equip], "unequip")
  823.   end
  824. end


  825. class Game_Troop < Game_Unit

  826.   #-----------------------------------------------------------------------------
  827.   # Add "Troop" trigger, which is activated after a troop event is executed.
  828.   #-----------------------------------------------------------------------------
  829.   alias :th_effect_manager_setup_battle_event :setup_battle_event
  830.   def setup_battle_event
  831.     return if @interpreter.running? || @interpreter.setup_reserved_common_event
  832.     th_effect_manager_setup_battle_event
  833.    
  834.     # This assumes that the interpreter does not finish executing before
  835.     # we get here
  836.     if $game_troop.interpreter.running?
  837.       @interpreter.call_troop_effect
  838.     end
  839.   end
  840. end

  841. class Game_Interpreter
  842.   
  843.   # Trigger troop effects after execution completes
  844.   def call_troop_effect
  845.     @troop_effect = true
  846.   end
  847.   
  848.   alias :th_effect_manager_run :run
  849.   def run
  850.     th_effect_manager_run
  851.     if @troop_effect
  852.       ($game_party.members | $game_troop.members).each {|member| member.check_troop_effects}
  853.       @troop_effect = false
  854.     end
  855.   end
  856. end

  857. # Allow scenes to store an effect callback, which can be set when the scene
  858. # is called
  859. class Scene_Base
  860.   
  861.   def set_effect_callback(method, effect)
  862.     @effect_callback = method
  863.     @effect = effect
  864.   end
  865. end

  866. class Scene_Battle < Scene_Base
  867.   
  868.   alias :th_effect_manager_turn_start :turn_start
  869.   def turn_start
  870.     th_effect_manager_turn_start
  871.     all_battle_members.each do |battler|
  872.       battler.on_turn_start
  873.       refresh_status
  874.     end
  875.   end
  876. end
  877.    
  878. # Display all of the effect messages. Since I couldn't find a nice place to
  879. # put it I simply put it before the affected status, which is ok to come near
  880. # the end...
  881. class Window_BattleLog
  882.   
  883.   alias :th_effect_manager_display_status :display_affected_status
  884.   def display_affected_status(target, item)
  885.     target.result.effect_results.each {|msg|
  886.       add_text(msg)
  887.       wait
  888.     }
  889.     th_effect_manager_display_status(target, item)
  890.   end
  891. end
复制代码

  1. =begin
  2. #==============================================================================
  3. ** Effect: Vampiric Weapon
  4. Author: Hime
  5. Date: Nov 9, 2012
  6. ------------------------------------------------------------------------------
  7. ** Change log
  8. Nov 9, 2012
  9.    - converted amount drained to an int
  10. Oct 8, 2012
  11.    - initial release
  12. ------------------------------------------------------------------------------   
  13. ** Terms of Use
  14. * Free to use in non-commercial projects
  15. * Contact me for commercial use
  16. * No real support. The script is provided as-is
  17. * Will do bug fixes, but no compatibility patches
  18. * Features may be requested but no guarantees, especially if it is non-trivial
  19. * Preserve this header
  20. ------------------------------------------------------------------------------
  21. ** Required
  22. -Effect Manager ([url]http://www.rpgmakervxace.net/topic/7395-effect-manager/[/url])
  23. ------------------------------------------------------------------------------
  24. Adds a "vampiric weapon" effect to your equip.
  25. When a battler has this effect, all attacks will drain HP equal to the damage.
  26. 为武器添加"吸血武器" 的效果.
  27. 当装备了该武器的对象使用攻击或技能命中目标时,吸取目标一定的hp.

  28.   Tag your weapon with
  29.   使用备注
  30.     <eff: vampiric_weapon x>
  31.    
  32. Where x is a percentage of the damage inflicted, as a float
  33. eg: 0.5 means you will absorb 50% of damage dealt as HP.
  34. 其中 x 代表伤害的百分之多少会被吸收,是一个浮点数
  35. 例如: 0.5 代表你会吸收伤害的 50% ,回复自身该数值的hp.
  36. #==============================================================================
  37. =end
  38. $imported = {} if $imported.nil?
  39. $imported["Effect_VampiricWeapon"] = true
  40. #==============================================================================
  41. # ** Rest of the script
  42. #==============================================================================
  43. module Effect
  44.   module Vampiric_Weapon
  45.     Effect_Manager.register_effect(:vampiric_weapon)
  46.   end
  47. end

  48. class Game_Battler < Game_BattlerBase
  49.   
  50.   def effect_vampiric_weapon(user, obj, effect)
  51.     return if user == self
  52.     amount = [@result.hp_damage, @result.old_hp].min
  53.     amount = (amount * (eval(effect.value1[0]) rescue 1)).to_i
  54.     user.hp = [user.hp + amount, user.mhp].min
  55.     self.hp = [self.hp - amount, 0].max
  56.    
  57.     @result.effect_results.push("%s 吸取了 %d HP from %s" %[user.name, amount, self.name])
  58.     @result.success = true
  59.   end
  60.   
  61.   alias :actor_effect_vampiric_weapon_attack :effect_vampiric_weapon
  62.   alias :weapon_effect_vampiric_weapon_attack :effect_vampiric_weapon
  63.   alias :state_effect_vampiric_weapon_attack :effect_vampiric_weapon
  64. end
复制代码
回复 1 0

使用道具 举报

梦石
0
星屑
771
在线时间
83 小时
注册时间
2020-4-10
回帖
38
 楼主| 发表于 2021-2-28 09:29:48 | 显示全部楼层
alexncf125 发表于 2021-2-27 10:24
[fold=前置]=begin
#==============================================================================
* ...

哇!谢谢大佬!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部