查看: 3379|回复: 4

[已经过期] Hime的战斗反应脚本含有冗余內容

[复制链接]
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2020-8-13 14:44:37 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 alexncf125 于 2024-1-25 01:48 编辑

这个战斗反应脚本是不是有兩句写错了??
270行alias了action_forced?但接下来却看不见有改动的地方
280行定义了reaction_forced?但又看不见有调用它的地方

  1. =begin
  2. #===============================================================================
  3. Title: Battle Reactions
  4. Author: Tsukihime
  5. Date: May 13, 2014
  6. URL: [url]http://himeworks.wordpress.com/2013/09/17/battle-reactions/[/url]
  7. --------------------------------------------------------------------------------
  8. ** Change log
  9. May 13, 2014
  10.    - implemented "pre-reactions"
  11. Mar 5, 2014
  12.    - corrected element and skill type triggers
  13. Feb 7, 2014
  14.    - added reaction conditions
  15.    - reactions are handled uniformly now
  16.    - "chance" is considered deprecated and should not be used
  17. Jan 22, 2014
  18.    - updated to remove all dependencies on forced action
  19. Dec 6, 2013
  20.    - fixed bug where using an item crashed on stype check
  21. Nov 23, 2013
  22.    - react message is only shown if an actual reaction took place
  23.    - fixed bug where the chance was not divided by 100
  24. Nov 15, 2013
  25.    - refactored reaction note-tag loading
  26.    - chance can now be specified as a formula
  27. Sep 22, 2013
  28.    - fixed bug where battlers no longer performed any actions after reacting
  29. Sep 21, 2013
  30.    - Initial release
  31. --------------------------------------------------------------------------------   
  32. ** Terms of Use
  33. * Free to use in non-commercial projects
  34. * Contact me for commercial use
  35. * No real support. The script is provided as-is
  36. * Will do bug fixes, but no compatibility patches
  37. * Features may be requested but no guarantees, especially if it is non-trivial
  38. * Credits to Tsukihime in your project
  39. * Preserve this header
  40. --------------------------------------------------------------------------------
  41. ** Description

  42. This script provides functionality for setting up "battle reactions", which are
  43. actions that are automatically invoked in response to certain actions.

  44. This script introduces the concept of "reaction objects", which is basically
  45. any object that supports reactions. Actors, Classes, Items, Skills, Weapons,
  46. Armors, Enemies, and States all support reaction objects.

  47. You can have multiple reactions occur simultaneously and all of them
  48. will be executed.

  49. --------------------------------------------------------------------------------
  50. ** Installation

  51. Place this script below Materials and above Main

  52. --------------------------------------------------------------------------------
  53. ** Usage

  54. -- Skill Triggers --

  55. To create a reaction that responds to skills, note-tag any reaction object with

  56.    <skill reaction: skill_id react_id chance forced>
  57.    
  58. Where
  59.    `skill_id` is the ID of the skill to react to
  60.    `react_id` is the ID of the skill to use in response
  61.    `chance` is the probability that it is used. 100 is always, while 0 is never
  62.    `forced` means it basically acts like a forced action (no MP/SP consumption)
  63.    
  64. The chance can be specified as a formula, with the following variables
  65. available to use

  66.    a - react user (ie: the battler that will react)
  67.    b - react target
  68.    p - game party
  69.    t - game troop
  70.    v - game variables
  71.    s - game switches
  72.    
  73. Note that you literally type in "forced" if you want the raction to be the\
  74. same as a "forced action".

  75. -- Skill Type Triggers --

  76. To create a reaction that responds to skill types, note-tag reaction objects
  77. with

  78.    <stype reaction: stype_id react_id chance forced>
  79.    
  80. Where the stype_id can be looked up in the terms database.
  81. When a skill with the specified skill type ID is used, the reaction will
  82. be triggered.

  83. -- Element Triggers --

  84. To create a reaction that responds to certain elements, note-tag any
  85. reaction object with

  86.    <element reaction: element_id react_id chance forced>
  87.    
  88. Where the element_id can be looked up in the Terms database.
  89. When a skill with the specified element is used, reaction will be triggered.
  90. Note that this only considers the element of the skill, not features.

  91. -- Reaction Condition --

  92. You can add conditions to your reactions. A reaction will only occur if the
  93. reaction condition has been met.

  94. Reaction conditions are specified as formulas. They can be any formula, and
  95. use the same formula variables that are available to battle reactions.

  96. To create a reaction condition, use the following note-tag

  97.    <reaction condition: id1,id2, ... >
  98.      FORMULA
  99.    </reaction condition>
  100.    
  101. The ID's are important: they are the reactions that the condition applies to,
  102. where each ID is separated by a comma.

  103. Each reaction has a unique ID, in the order that they are written in your note
  104. box. The first reaction is 1,  the second reaction is 2, and so on. Refer to
  105. the example to understand how reaction conditions can be used

  106. -- Reaction Timing --

  107. Reactions can occur before or after an action is executed. By default, a
  108. reaction occurs after, but you can set a reaction to occur when an action
  109. has been declared, but before it hits.

  110. So for example, if an enemy attacks you, you may react to this by putting up
  111. a shield, effectively increasing your defense, before the attack lands.

  112. To set a reaction to occur before an action hits, use the note-tag

  113.    <pre react: id1, id2, ... >
  114.    
  115. Where the ID's are the reactions that you want to apply this setting to.

  116. --------------------------------------------------------------------------------
  117. ** Example

  118. Suppose we have two reactions. The first is a skill reaction that reacts to
  119. the attack skill (skill 1), and responds with a triple attack (skill 23).

  120. The second is a skill type reaction that reacts to all "magic" skills
  121. (stype 2) with a heal spell (skill 51).

  122. Both reactions will only occur if state 23 is applied.

  123. You can begin by writing the reactions, and then write the reaction condition

  124.    <skill reaction: 1 23>
  125.    <stype reaction: 2 51>
  126.    
  127.    <reaction condition: 1,2>
  128.      a.state?(23)
  129.    </reaction condition>

  130. If you want the stype reaction to occur before the skill lands, you can simply
  131. add the following to your note

  132.    <pre react: 2>
  133.   
  134. #===============================================================================
  135. =end
  136. $imported = {} if $imported.nil?
  137. $imported["TH_BattleReactions"] = true
  138. #===============================================================================
  139. # ** Configuration
  140. #===============================================================================
  141. module TH
  142.   module Battle_Reactions
  143.    
  144.     # Message to display when a battler reacts to a skill.
  145.     Skill_React_Vocab = "%s counters!"
  146.    
  147.     Skill_Regex = /<skill[-_ ]reaction(\s*\d+\s*)?:\s*(\d+)\s*(\d+)\s*(.*?)?\s*(forced)?\s*>/i
  148.     Stype_Regex = /<stype[-_ ]reaction(\s*\d+\s*)?:\s*(\d+)\s*(\d+)\s*(.*?)?\s*(forced)?\s*>/i
  149.     Element_Regex = /<element[-_ ]reaction(\s*\d+\s*)?:\s*(\d+)\s*(\d+)\s*(.*?)?\s*(forced)?\s*>/i
  150.    
  151.     Cond_Regex = /<reaction[-_ ]condition:(.*)>(.*?)<\/reaction[-_ ]condition>/im
  152.    
  153.     Pre_Regex = /<pre[-_ ]react:\s*(.*)\s*>/i
  154.   end
  155. end
  156. #===============================================================================
  157. # ** Rest of Script
  158. #===============================================================================
  159. module RPG
  160.   class BaseItem
  161.    
  162.     def reactions(skill)
  163.       return [] unless skill.is_a?(RPG::Skill)
  164.       load_notetag_battle_reactions unless @reactions
  165.       @reactions.select {|data|
  166.         (data.trigger_type == :skill && data.trigger_id == skill.id) ||
  167.         (data.trigger_type == :stype && data.trigger_id == skill.stype_id) ||
  168.         (data.trigger_type == :element && data.trigger_id == skill.damage.element_id)
  169.       }
  170.     end
  171.    
  172.     def load_notetag_battle_reactions
  173.       @reactions = []
  174.       
  175.       reactions = load_data_battle_reaction(TH::Battle_Reactions::Skill_Regex, Data_SkillReaction)
  176.       @reactions.concat(reactions)
  177.       
  178.       reactions = load_data_battle_reaction(TH::Battle_Reactions::Stype_Regex, Data_StypeReaction)
  179.       @reactions.concat(reactions)
  180.       
  181.       reactions = load_data_battle_reaction(TH::Battle_Reactions::Element_Regex, Data_ElementReaction)
  182.       @reactions.concat(reactions)
  183.       
  184.       # Assign conditions to reactions
  185.       load_notetag_reaction_conditions
  186.       load_notetag_prereactions
  187.     end
  188.    
  189.     def load_data_battle_reaction(regex, dataClass)
  190.       reactions = []
  191.       res = self.note.scan(regex)
  192.       res.each do |data|
  193.         reaction_id = data[0].to_i
  194.         trigger_id = data[1].to_i
  195.         reaction = dataClass.new(trigger_id)
  196.         reaction.react_id = data[2].to_i
  197.         reaction.chance = data[3] if data[3] && !data[3].empty?
  198.         reaction.forced = data[4].downcase == "forced" if data[4]
  199.         reactions << reaction
  200.       end
  201.       return reactions
  202.     end
  203.    
  204.     def load_notetag_reaction_conditions
  205.       results = self.note.scan(TH::Battle_Reactions::Cond_Regex)
  206.       results.each do |res|
  207.         ids = res[0].split(",").map {|id| id.to_i - 1 }
  208.         condition = res[1].strip
  209.         ids.each do |id|
  210.           next unless @reactions[id]
  211.           @reactions[id].condition = condition
  212.         end
  213.       end
  214.     end
  215.    
  216.     def load_notetag_prereactions
  217.       results = self.note.scan(TH::Battle_Reactions::Pre_Regex)
  218.       results.each do |res|
  219.         ids = res[0].split(",").map {|id| id.to_i - 1 }
  220.         ids.each do |id|
  221.           next unless @reactions[id]
  222.           @reactions[id].pre_reaction = true
  223.         end
  224.       end
  225.     end
  226.   end
  227. end

  228. module BattleManager
  229.   
  230.   class << self
  231.     attr_accessor :reaction_processing
  232.    
  233.     alias :th_battle_reactions_setup :setup
  234.     alias :th_battle_reactions_action_forced? :action_forced?
  235.   end
  236.   #-----------------------------------------------------------------------------
  237.   #
  238.   #-----------------------------------------------------------------------------
  239.   def self.setup(troop_id, can_escape = true, can_lose = false)
  240.     @reaction_processing = false
  241.     th_battle_reactions_setup(troop_id, can_escape, can_lose)
  242.   end
  243.   
  244.   def self.reaction_forced?
  245.     @reaction_processing
  246.   end
  247.   
  248.   def self.clear_reaction_processing
  249.     @reaction_forced = nil
  250.     @reaction_processing = false
  251.   end
  252.   
  253.   def self.force_reaction(battler)
  254.     @reaction_forced = battler
  255.   end
  256. end

  257. module Vocab
  258.   Skill_Reaction = TH::Battle_Reactions::Skill_React_Vocab
  259. end

  260. class Data_Reaction
  261.   attr_accessor :id
  262.   attr_accessor :trigger_type
  263.   attr_accessor :trigger_id
  264.   attr_accessor :react_type
  265.   attr_accessor :react_id
  266.   attr_accessor :chance       # probability that the reaction occurs
  267.   attr_accessor :forced
  268.   attr_accessor :condition
  269.   attr_accessor :pre_reaction
  270.   
  271.   def initialize
  272.     @id = 0
  273.     @condition = "true"
  274.     @forced = false
  275.     @chance = "100"
  276.     @pre_reaction = false
  277.   end
  278.   
  279.   def pre_react?
  280.     @pre_reaction
  281.   end
  282.   
  283.   def chance(react_user, react_target)
  284.     eval_chance(react_user, react_target)
  285.   end
  286.   
  287.   def eval_chance(a, b, p=$game_party, t=$game_troop, v=$game_variables, s=$game_switches)
  288.     eval(@chance) / 100.0
  289.   end
  290.   
  291.   def condition_met?(a, b, p=$game_party, t=$game_troop, v=$game_variables, s=$game_switches)
  292.     eval(@condition)
  293.   end
  294. end

  295. #-------------------------------------------------------------------------------
  296. # Skill reaction object
  297. #-------------------------------------------------------------------------------
  298. class Data_SkillReaction < Data_Reaction
  299.   
  300.   def initialize(skill_id)
  301.     @trigger_type = :skill
  302.     @react_type = :skill
  303.     @trigger_id = skill_id
  304.     @react_id = 0
  305.     super()
  306.   end
  307. end

  308. #-------------------------------------------------------------------------------
  309. # Skill Type reaction object.
  310. #-------------------------------------------------------------------------------
  311. class Data_StypeReaction < Data_Reaction
  312.   def initialize(stype_id)
  313.     @trigger_type = :stype
  314.     @react_type = :skill
  315.     @trigger_id = stype_id
  316.     @react_id = 0
  317.     super()
  318.   end
  319. end

  320. #-------------------------------------------------------------------------------
  321. # Element reaction object
  322. #-------------------------------------------------------------------------------
  323. class Data_ElementReaction < Data_Reaction
  324.   def initialize(element_id)
  325.     @trigger_type = :element
  326.     @react_type = :skill
  327.     @trigger_id = element_id
  328.     @react_id = 0
  329.     super()
  330.   end
  331. end

  332. class Game_BattlerBase
  333.   
  334.   #-----------------------------------------------------------------------------
  335.   #
  336.   #-----------------------------------------------------------------------------
  337.   def reaction_objects
  338.     states
  339.   end
  340. end

  341. class Game_Battler < Game_BattlerBase
  342.   
  343.   #-----------------------------------------------------------------------------
  344.   #
  345.   #-----------------------------------------------------------------------------
  346.   def skill_reactions(item)
  347.     reaction_objects.inject([]) do |r, obj|
  348.       r.concat(obj.skill_reactions(item))
  349.     end
  350.   end
  351.   
  352.   def get_reactions(item)
  353.     res = []
  354.     reaction_objects.each do |obj|
  355.       res.concat(obj.reactions(item))
  356.     end
  357.     return res
  358.   end
  359.   
  360.   #-----------------------------------------------------------------------------
  361.   # adds a reaction object
  362.   #-----------------------------------------------------------------------------
  363.   def make_reaction(user, reaction)
  364.     return unless reaction.condition_met?(self, user)
  365.    
  366.     chance = reaction.chance(self, user)   
  367.     return if chance < rand
  368.     skill = $data_skills[reaction.react_id]
  369.     action = Game_Action.new(self, reaction.forced)
  370.   
  371.     if skill.for_opponent?
  372.       action.target_index = user.index
  373.     elsif skill.for_friend?
  374.       action.target_index = self.index
  375.     end
  376.     action.set_skill(reaction.react_id)
  377.     action.make_targets
  378.     @actions.push(action)
  379.     BattleManager.force_reaction(self)
  380.   end
  381.   
  382.   #-----------------------------------------------------------------------------
  383.   # adds a reaction object
  384.   #-----------------------------------------------------------------------------
  385.   def backup_actions
  386.     @reaction_backup = @actions.dup
  387.   end
  388.   
  389.   def restore_actions
  390.     @actions = @reaction_backup.dup
  391.   end
  392. end

  393. class Game_Actor < Game_Battler
  394.   
  395.   #-----------------------------------------------------------------------------
  396.   #
  397.   #-----------------------------------------------------------------------------
  398.   def reaction_objects
  399.     super + [actor] + [self.class] + equips.compact
  400.   end
  401. end

  402. class Game_Enemy < Game_Battler
  403.   
  404.   #-----------------------------------------------------------------------------
  405.   #
  406.   #-----------------------------------------------------------------------------
  407.   def reaction_objects
  408.     super + [enemy]
  409.   end
  410. end

  411. class Scene_Battle < Scene_Base
  412.   
  413.   alias :th_skill_reactions_invoke_item :invoke_item
  414.   def invoke_item(target, item)
  415.     invoke_pre_reactions(target, item)
  416.     th_skill_reactions_invoke_item(target, item)
  417.     invoke_post_reactions(target, item)
  418.   end
  419.   
  420.   def invoke_pre_reactions(target, item)
  421.     return if BattleManager.reaction_processing
  422.     reactions = target.get_reactions(item).select{|react| react.pre_react? }
  423.     invoke_reactions(reactions, target, item)
  424.   end
  425.   
  426.   def invoke_post_reactions(target, item)
  427.     return if BattleManager.reaction_processing
  428.     reactions = target.get_reactions(item).select{|react| !react.pre_react? }
  429.     invoke_reactions(reactions, target, item)
  430.   end
  431.   
  432.   #-----------------------------------------------------------------------------
  433.   # Create reaction actions
  434.   #-----------------------------------------------------------------------------
  435.   def invoke_reactions(reactions, target, item)
  436.     return if reactions.empty?
  437.     # back up existing actions
  438.     target.backup_actions
  439.     target.clear_actions
  440.     reactions.each do |reaction|
  441.       target.make_reaction(@subject, reaction)
  442.     end
  443.     perform_reactions(target, item) if target.current_action
  444.     target.restore_actions
  445.   end
  446.   
  447.   #-----------------------------------------------------------------------------
  448.   # Perform all skill reactions
  449.   #-----------------------------------------------------------------------------
  450.   def perform_reactions(target, item)
  451.     @log_window.display_reaction(target, item)
  452.     BattleManager.reaction_processing = true
  453.     last_subject = @subject
  454.     @subject = target
  455.     while @subject.current_action
  456.       process_action
  457.     end
  458.     @subject = last_subject
  459.     BattleManager.clear_reaction_processing
  460.   end
  461. end

  462. class Window_BattleLog < Window_Selectable
  463.   
  464.   #-----------------------------------------------------------------------------
  465.   # Informs the player that a reaction occurred
  466.   #-----------------------------------------------------------------------------
  467.   def display_reaction(target, item)
  468.     add_text(sprintf(Vocab::Skill_Reaction, target.name, item.name))
  469.     wait
  470.   end
  471. end
复制代码

老鹰

梦石
40
星屑
38044
在线时间
7127 小时
注册时间
2012-5-26
回帖
3306

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2020-8-13 15:31:43 | 显示全部楼层
没报错,管它写了什么多余的东西
也有可能是旧版本流传着,然后里面有的东西没删干净or还没扩展完成

评分

参与人数 1赞 +1 收起 理由
alexncf125 + 1 认可答案

查看全部评分

回复

使用道具 举报

梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
 楼主| 发表于 2020-8-13 15:52:20 | 显示全部楼层
本帖最后由 alexncf125 于 2020-8-17 02:59 编辑

本篇已刪
回复

使用道具 举报

梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
 楼主| 发表于 2020-8-14 20:42:26 | 显示全部楼层
本帖最后由 alexncf125 于 2020-8-17 02:58 编辑

本篇已刪
回复

使用道具 举报

梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
 楼主| 发表于 2020-8-16 13:18:36 | 显示全部楼层
本帖最后由 alexncf125 于 2020-8-17 02:58 编辑

本篇已刪
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部