设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2853|回复: 4
打印 上一主题 下一主题

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

[复制链接]

Lv5.捕梦者

梦石
0
星屑
24787
在线时间
5132 小时
注册时间
2016-3-8
帖子
1628
跳转到指定楼层
1
发表于 2020-8-13 14:44:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

RUBY 代码复制
  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.  
  43.  This script provides functionality for setting up "battle reactions", which are
  44.  actions that are automatically invoked in response to certain actions.
  45.  
  46.  This script introduces the concept of "reaction objects", which is basically
  47.  any object that supports reactions. Actors, Classes, Items, Skills, Weapons,
  48.  Armors, Enemies, and States all support reaction objects.
  49.  
  50.  You can have multiple reactions occur simultaneously and all of them
  51.  will be executed.
  52.  
  53. --------------------------------------------------------------------------------
  54.  ** Installation
  55.  
  56.  Place this script below Materials and above Main
  57.  
  58. --------------------------------------------------------------------------------
  59.  ** Usage
  60.  
  61.  -- Skill Triggers --
  62.  
  63.  To create a reaction that responds to skills, note-tag any reaction object with
  64.  
  65.    <skill reaction: skill_id react_id chance forced>
  66.    
  67.  Where
  68.    `skill_id` is the ID of the skill to react to
  69.    `react_id` is the ID of the skill to use in response
  70.    `chance` is the probability that it is used. 100 is always, while 0 is never
  71.    `forced` means it basically acts like a forced action (no MP/SP consumption)
  72.    
  73.  The chance can be specified as a formula, with the following variables
  74.  available to use
  75.  
  76.    a - react user (ie: the battler that will react)
  77.    b - react target
  78.    p - game party
  79.    t - game troop
  80.    v - game variables
  81.    s - game switches
  82.    
  83.  Note that you literally type in "forced" if you want the raction to be the\
  84.  same as a "forced action".
  85.  
  86.  -- Skill Type Triggers --
  87.  
  88.  To create a reaction that responds to skill types, note-tag reaction objects
  89.  with
  90.  
  91.    <stype reaction: stype_id react_id chance forced>
  92.    
  93.  Where the stype_id can be looked up in the terms database.
  94.  When a skill with the specified skill type ID is used, the reaction will
  95.  be triggered.
  96.  
  97.  -- Element Triggers --
  98.  
  99.  To create a reaction that responds to certain elements, note-tag any
  100.  reaction object with
  101.  
  102.    <element reaction: element_id react_id chance forced>
  103.    
  104.  Where the element_id can be looked up in the Terms database.
  105.  When a skill with the specified element is used, reaction will be triggered.
  106.  Note that this only considers the element of the skill, not features.
  107.  
  108.  -- Reaction Condition --
  109.  
  110.  You can add conditions to your reactions. A reaction will only occur if the
  111.  reaction condition has been met.
  112.  
  113.  Reaction conditions are specified as formulas. They can be any formula, and
  114.  use the same formula variables that are available to battle reactions.
  115.  
  116.  To create a reaction condition, use the following note-tag
  117.  
  118.    <reaction condition: id1,id2, ... >
  119.      FORMULA
  120.    </reaction condition>
  121.    
  122.  The ID's are important: they are the reactions that the condition applies to,
  123.  where each ID is separated by a comma.
  124.  
  125.  Each reaction has a unique ID, in the order that they are written in your note
  126.  box. The first reaction is 1,  the second reaction is 2, and so on. Refer to
  127.  the example to understand how reaction conditions can be used
  128.  
  129.  -- Reaction Timing --
  130.  
  131.  Reactions can occur before or after an action is executed. By default, a
  132.  reaction occurs after, but you can set a reaction to occur when an action
  133.  has been declared, but before it hits.
  134.  
  135.  So for example, if an enemy attacks you, you may react to this by putting up
  136.  a shield, effectively increasing your defense, before the attack lands.
  137.  
  138.  To set a reaction to occur before an action hits, use the note-tag
  139.  
  140.    <pre react: id1, id2, ... >
  141.    
  142.  Where the ID's are the reactions that you want to apply this setting to.
  143.  
  144. --------------------------------------------------------------------------------
  145.  ** Example
  146.  
  147.  Suppose we have two reactions. The first is a skill reaction that reacts to
  148.  the attack skill (skill 1), and responds with a triple attack (skill 23).
  149.  
  150.  The second is a skill type reaction that reacts to all "magic" skills
  151.  (stype 2) with a heal spell (skill 51).
  152.  
  153.  Both reactions will only occur if state 23 is applied.
  154.  
  155.  You can begin by writing the reactions, and then write the reaction condition
  156.  
  157.    <skill reaction: 1 23>
  158.    <stype reaction: 2 51>
  159.    
  160.    <reaction condition: 1,2>
  161.      a.state?(23)
  162.    </reaction condition>
  163.  
  164.  If you want the stype reaction to occur before the skill lands, you can simply
  165.  add the following to your note
  166.  
  167.    <pre react: 2>
  168.  
  169. #===============================================================================
  170. =end
  171. $imported = {} if $imported.nil?
  172. $imported["TH_BattleReactions"] = true
  173. #===============================================================================
  174. # ** Configuration
  175. #===============================================================================
  176. module TH
  177.   module Battle_Reactions
  178.  
  179.     # Message to display when a battler reacts to a skill.
  180.     Skill_React_Vocab = "%s counters!"
  181.  
  182.     Skill_Regex = /<skill[-_ ]reaction(\s*\d+\s*)?:\s*(\d+)\s*(\d+)\s*(.*?)?\s*(forced)?\s*>/i
  183.     Stype_Regex = /<stype[-_ ]reaction(\s*\d+\s*)?:\s*(\d+)\s*(\d+)\s*(.*?)?\s*(forced)?\s*>/i
  184.     Element_Regex = /<element[-_ ]reaction(\s*\d+\s*)?:\s*(\d+)\s*(\d+)\s*(.*?)?\s*(forced)?\s*>/i
  185.  
  186.     Cond_Regex = /<reaction[-_ ]condition:(.*)>(.*?)<\/reaction[-_ ]condition>/im
  187.  
  188.     Pre_Regex = /<pre[-_ ]react:\s*(.*)\s*>/i
  189.   end
  190. end
  191. #===============================================================================
  192. # ** Rest of Script
  193. #===============================================================================
  194. module RPG
  195.   class BaseItem
  196.  
  197.     def reactions(skill)
  198.       return [] unless skill.is_a?(RPG::Skill)
  199.       load_notetag_battle_reactions unless @reactions
  200.       @reactions.select {|data|
  201.         (data.trigger_type == :skill && data.trigger_id == skill.id) ||
  202.         (data.trigger_type == :stype && data.trigger_id == skill.stype_id) ||
  203.         (data.trigger_type == :element && data.trigger_id == skill.damage.element_id)
  204.       }
  205.     end
  206.  
  207.     def load_notetag_battle_reactions
  208.       @reactions = []
  209.  
  210.       reactions = load_data_battle_reaction(TH::Battle_Reactions::Skill_Regex, Data_SkillReaction)
  211.       @reactions.concat(reactions)
  212.  
  213.       reactions = load_data_battle_reaction(TH::Battle_Reactions::Stype_Regex, Data_StypeReaction)
  214.       @reactions.concat(reactions)
  215.  
  216.       reactions = load_data_battle_reaction(TH::Battle_Reactions::Element_Regex, Data_ElementReaction)
  217.       @reactions.concat(reactions)
  218.  
  219.       # Assign conditions to reactions
  220.       load_notetag_reaction_conditions
  221.       load_notetag_prereactions
  222.     end
  223.  
  224.     def load_data_battle_reaction(regex, dataClass)
  225.       reactions = []
  226.       res = self.note.scan(regex)
  227.       res.each do |data|
  228.         reaction_id = data[0].to_i
  229.         trigger_id = data[1].to_i
  230.         reaction = dataClass.new(trigger_id)
  231.         reaction.react_id = data[2].to_i
  232.         reaction.chance = data[3] if data[3] && !data[3].empty?
  233.         reaction.forced = data[4].downcase == "forced" if data[4]
  234.         reactions << reaction
  235.       end
  236.       return reactions
  237.     end
  238.  
  239.     def load_notetag_reaction_conditions
  240.       results = self.note.scan(TH::Battle_Reactions::Cond_Regex)
  241.       results.each do |res|
  242.         ids = res[0].split(",").map {|id| id.to_i - 1 }
  243.         condition = res[1].strip
  244.         ids.each do |id|
  245.           next unless @reactions[id]
  246.           @reactions[id].condition = condition
  247.         end
  248.       end
  249.     end
  250.  
  251.     def load_notetag_prereactions
  252.       results = self.note.scan(TH::Battle_Reactions::Pre_Regex)
  253.       results.each do |res|
  254.         ids = res[0].split(",").map {|id| id.to_i - 1 }
  255.         ids.each do |id|
  256.           next unless @reactions[id]
  257.           @reactions[id].pre_reaction = true
  258.         end
  259.       end
  260.     end
  261.   end
  262. end
  263.  
  264. module BattleManager
  265.  
  266.   class << self
  267.     attr_accessor :reaction_processing
  268.  
  269.     alias :th_battle_reactions_setup :setup
  270.     alias :th_battle_reactions_action_forced? :action_forced?
  271.   end
  272.   #-----------------------------------------------------------------------------
  273.   #
  274.   #-----------------------------------------------------------------------------
  275.   def self.setup(troop_id, can_escape = true, can_lose = false)
  276.     @reaction_processing = false
  277.     th_battle_reactions_setup(troop_id, can_escape, can_lose)
  278.   end
  279.  
  280.   def self.reaction_forced?
  281.     @reaction_processing
  282.   end
  283.  
  284.   def self.clear_reaction_processing
  285.     @reaction_forced = nil
  286.     @reaction_processing = false
  287.   end
  288.  
  289.   def self.force_reaction(battler)
  290.     @reaction_forced = battler
  291.   end
  292. end
  293.  
  294. module Vocab
  295.   Skill_Reaction = TH::Battle_Reactions::Skill_React_Vocab
  296. end
  297.  
  298. class Data_Reaction
  299.   attr_accessor :id
  300.   attr_accessor :trigger_type
  301.   attr_accessor :trigger_id
  302.   attr_accessor :react_type
  303.   attr_accessor :react_id
  304.   attr_accessor :chance       # probability that the reaction occurs
  305.   attr_accessor :forced
  306.   attr_accessor :condition
  307.   attr_accessor :pre_reaction
  308.  
  309.   def initialize
  310.     @id = 0
  311.     @condition = "true"
  312.     @forced = false
  313.     @chance = "100"
  314.     @pre_reaction = false
  315.   end
  316.  
  317.   def pre_react?
  318.     @pre_reaction
  319.   end
  320.  
  321.   def chance(react_user, react_target)
  322.     eval_chance(react_user, react_target)
  323.   end
  324.  
  325.   def eval_chance(a, b, p=$game_party, t=$game_troop, v=$game_variables, s=$game_switches)
  326.     eval(@chance) / 100.0
  327.   end
  328.  
  329.   def condition_met?(a, b, p=$game_party, t=$game_troop, v=$game_variables, s=$game_switches)
  330.     eval(@condition)
  331.   end
  332. end
  333.  
  334. #-------------------------------------------------------------------------------
  335. # Skill reaction object
  336. #-------------------------------------------------------------------------------
  337. class Data_SkillReaction < Data_Reaction
  338.  
  339.   def initialize(skill_id)
  340.     @trigger_type = :skill
  341.     @react_type = :skill
  342.     @trigger_id = skill_id
  343.     @react_id = 0
  344.     super()
  345.   end
  346. end
  347.  
  348. #-------------------------------------------------------------------------------
  349. # Skill Type reaction object.
  350. #-------------------------------------------------------------------------------
  351. class Data_StypeReaction < Data_Reaction
  352.   def initialize(stype_id)
  353.     @trigger_type = :stype
  354.     @react_type = :skill
  355.     @trigger_id = stype_id
  356.     @react_id = 0
  357.     super()
  358.   end
  359. end
  360.  
  361. #-------------------------------------------------------------------------------
  362. # Element reaction object
  363. #-------------------------------------------------------------------------------
  364. class Data_ElementReaction < Data_Reaction
  365.   def initialize(element_id)
  366.     @trigger_type = :element
  367.     @react_type = :skill
  368.     @trigger_id = element_id
  369.     @react_id = 0
  370.     super()
  371.   end
  372. end
  373.  
  374. class Game_BattlerBase
  375.  
  376.   #-----------------------------------------------------------------------------
  377.   #
  378.   #-----------------------------------------------------------------------------
  379.   def reaction_objects
  380.     states
  381.   end
  382. end
  383.  
  384. class Game_Battler < Game_BattlerBase
  385.  
  386.   #-----------------------------------------------------------------------------
  387.   #
  388.   #-----------------------------------------------------------------------------
  389.   def skill_reactions(item)
  390.     reaction_objects.inject([]) do |r, obj|
  391.       r.concat(obj.skill_reactions(item))
  392.     end
  393.   end
  394.  
  395.   def get_reactions(item)
  396.     res = []
  397.     reaction_objects.each do |obj|
  398.       res.concat(obj.reactions(item))
  399.     end
  400.     return res
  401.   end
  402.  
  403.   #-----------------------------------------------------------------------------
  404.   # adds a reaction object
  405.   #-----------------------------------------------------------------------------
  406.   def make_reaction(user, reaction)
  407.     return unless reaction.condition_met?(self, user)
  408.  
  409.     chance = reaction.chance(self, user)   
  410.     return if chance < rand
  411.     skill = $data_skills[reaction.react_id]
  412.     action = Game_Action.new(self, reaction.forced)
  413.  
  414.     if skill.for_opponent?
  415.       action.target_index = user.index
  416.     elsif skill.for_friend?
  417.       action.target_index = self.index
  418.     end
  419.     action.set_skill(reaction.react_id)
  420.     action.make_targets
  421.     @actions.push(action)
  422.     BattleManager.force_reaction(self)
  423.   end
  424.  
  425.   #-----------------------------------------------------------------------------
  426.   # adds a reaction object
  427.   #-----------------------------------------------------------------------------
  428.   def backup_actions
  429.     @reaction_backup = @actions.dup
  430.   end
  431.  
  432.   def restore_actions
  433.     @actions = @reaction_backup.dup
  434.   end
  435. end
  436.  
  437. class Game_Actor < Game_Battler
  438.  
  439.   #-----------------------------------------------------------------------------
  440.   #
  441.   #-----------------------------------------------------------------------------
  442.   def reaction_objects
  443.     super + [actor] + [self.class] + equips.compact
  444.   end
  445. end
  446.  
  447. class Game_Enemy < Game_Battler
  448.  
  449.   #-----------------------------------------------------------------------------
  450.   #
  451.   #-----------------------------------------------------------------------------
  452.   def reaction_objects
  453.     super + [enemy]
  454.   end
  455. end
  456.  
  457. class Scene_Battle < Scene_Base
  458.  
  459.   alias :th_skill_reactions_invoke_item :invoke_item
  460.   def invoke_item(target, item)
  461.     invoke_pre_reactions(target, item)
  462.     th_skill_reactions_invoke_item(target, item)
  463.     invoke_post_reactions(target, item)
  464.   end
  465.  
  466.   def invoke_pre_reactions(target, item)
  467.     return if BattleManager.reaction_processing
  468.     reactions = target.get_reactions(item).select{|react| react.pre_react? }
  469.     invoke_reactions(reactions, target, item)
  470.   end
  471.  
  472.   def invoke_post_reactions(target, item)
  473.     return if BattleManager.reaction_processing
  474.     reactions = target.get_reactions(item).select{|react| !react.pre_react? }
  475.     invoke_reactions(reactions, target, item)
  476.   end
  477.  
  478.   #-----------------------------------------------------------------------------
  479.   # Create reaction actions
  480.   #-----------------------------------------------------------------------------
  481.   def invoke_reactions(reactions, target, item)
  482.     return if reactions.empty?
  483.     # back up existing actions
  484.     target.backup_actions
  485.     target.clear_actions
  486.     reactions.each do |reaction|
  487.       target.make_reaction(@subject, reaction)
  488.     end
  489.     perform_reactions(target, item) if target.current_action
  490.     target.restore_actions
  491.   end
  492.  
  493.   #-----------------------------------------------------------------------------
  494.   # Perform all skill reactions
  495.   #-----------------------------------------------------------------------------
  496.   def perform_reactions(target, item)
  497.     @log_window.display_reaction(target, item)
  498.     BattleManager.reaction_processing = true
  499.     last_subject = @subject
  500.     @subject = target
  501.     while @subject.current_action
  502.       process_action
  503.     end
  504.     @subject = last_subject
  505.     BattleManager.clear_reaction_processing
  506.   end
  507. end
  508.  
  509. class Window_BattleLog < Window_Selectable
  510.  
  511.   #-----------------------------------------------------------------------------
  512.   # Informs the player that a reaction occurred
  513.   #-----------------------------------------------------------------------------
  514.   def display_reaction(target, item)
  515.     add_text(sprintf(Vocab::Skill_Reaction, target.name, item.name))
  516.     wait
  517.   end
  518. end

Lv6.析梦学徒

老鹰

梦石
40
星屑
33631
在线时间
6581 小时
注册时间
2012-5-26
帖子
3187

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

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

评分

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

查看全部评分

回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24787
在线时间
5132 小时
注册时间
2016-3-8
帖子
1628
3
 楼主| 发表于 2020-8-13 15:52:20 | 只看该作者
本帖最后由 alexncf125 于 2020-8-17 02:59 编辑

本篇已刪
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24787
在线时间
5132 小时
注册时间
2016-3-8
帖子
1628
4
 楼主| 发表于 2020-8-14 20:42:26 | 只看该作者
本帖最后由 alexncf125 于 2020-8-17 02:58 编辑

本篇已刪
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
24787
在线时间
5132 小时
注册时间
2016-3-8
帖子
1628
5
 楼主| 发表于 2020-8-16 13:18:36 | 只看该作者
本帖最后由 alexncf125 于 2020-8-17 02:58 编辑

本篇已刪
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-6-19 14:44

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表