查看: 1916|回复: 0

[已经过期] 想在反击脚本中添加窗口文字提示“反击”

[复制链接]
梦石
0
星屑
1442
在线时间
171 小时
注册时间
2019-10-4
回帖
162
发表于 2022-10-11 16:45:13 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 guoxiaomi 于 2022-10-12 22:41 编辑
  1. #==========================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],由ikki转载。使用请保留此信息
  3. #=========================================================================

  4. # ▼▲▼ XRXS27. 特殊効果 SuperEX「反击」 ver.1.05 ▼▲▼
  5. # by シムナフ, ピニョン

  6. #========================================================================
  7. # □ 自定义设定
  8. #========================================================================
  9. class Game_Battler
  10.   # 反击的状态名
  11.   STATE_COUNTER_NAME = '反击'
  12. end
  13. #========================================================================
  14. # ◇ 说明文档
  15. #=======================================================================
  16. #****Warning! 重新定义了 Game_Actor#skill_can_use? ****

  17. #使用方法
  18. #对于身中“反击”状态的角色,当收到单独的攻击的时候会自动反击
  19. #反击的模式可以在下面设定

  20. #-cr (counter react)下面设定可以反击的挨打设定:

  21. # 比如设定一个状态名为“反击 -crm”,则受到魔法攻击的时候会自动反击
  22. #-cra50(attack)   =>遭到物理攻击(普攻)的时候50%概率反击。
  23. #-crp  (physical) =>遭到物理伤害(物攻+物理技能)的时候反击。
  24. #-crm  (magic)    =>遭到法术伤害(法术技能)的时候反击。
  25. #-crs  (skill)    =>遭到技能伤害(物理技能+法术技能)的时候反击。
  26. #-cre7 (element)  =>遭到属性ID为7的攻击的时候反击。

  27. #-ca (counter act)下面设定反击行为:

  28. #比如设置一个状态名叫做“反击 -cas19”,那么受到攻击的时候就会用19号特技反击。
  29. #-caa  (attack)   =>使用物理攻击反击。
  30. #-cas1 (skill)    =>使用ID为1的技能反击。
  31. #-cac  (copy)     =>复制敌人攻击方式(普攻+技能)进行反击。
  32. #-cai1 (item)     =>使用ID为1的物品。
  33. #-cae  (escape)   =>逃跑,敌人使用。

  34. #注意和即时战斗的共同使用问题……

  35. #举例:设置一个状态,使得遭遇物理攻击的时候使用物品4,“反击 -crp -cai4”

  36. #========================================================================
  37. # ■ Game_Battler (分割定义 1)
  38. #========================================================================

  39. class Game_Battler
  40.   #-----------------------------------------------------------------------
  41.   # ● 状态初始化
  42.   #-----------------------------------------------------------------------
  43.   def states=(states)
  44.     @states = states
  45.   end  
  46.   #-----------------------------------------------------------------------
  47.   # ● 对象初始化
  48.   #-----------------------------------------------------------------------
  49.   alias original_initialize_before_counter_action initialize
  50.   def initialize
  51.     original_initialize_before_counter_action()
  52.     @counter_action = Game_BattleAction.new
  53.   end   

  54.   #-----------------------------------------------------------------------
  55.   # ● 获取当前的动作
  56.   #-----------------------------------------------------------------------
  57.   alias original_current_action_before_counter_action current_action
  58.   def current_action
  59.     if @counter_action.cleared?
  60.       return original_current_action_before_counter_action()
  61.     else
  62.       return @counter_action
  63.     end
  64.   end
  65.   #-----------------------------------------------------------------------
  66.   # ● 获取当前的动作
  67.   #-----------------------------------------------------------------------
  68.   def counter_action
  69.     return @counter_action
  70.   end
  71.   #-----------------------------------------------------------------------
  72.   # ● 是否待机
  73.   #-----------------------------------------------------------------------
  74.   def counter_acting?
  75.     if !@counter_action.cleared?
  76.       return true
  77.     else
  78.       return false
  79.     end
  80.   end
  81.   #-----------------------------------------------------------------------
  82.   # ● 战斗不能判定
  83.   #-----------------------------------------------------------------------
  84.   #alias original_dead_before_counter_action dead?
  85.   #def dead?
  86.   #  if self.counter_acting?
  87.   #    return false
  88.   #  else
  89.   #    return original_dead_before_counter_action()
  90.   #  end
  91.   #end  
  92.   #----------------------------------------------------------------------
  93.   # ●
  94.   #----------------------------------------------------------------------
  95.   def counter_action_for(attacker, skill = nil)
  96.     # 行动存在时
  97.     if attacker.counter_acting?
  98.       return
  99.     end
  100.     # 无法行动和不存在的情况
  101.     #if !self.movable? || !self.exist?
  102.     #  return
  103.     #end
  104.     if attacker.is_a?(Game_Actor)
  105.       if self.is_a?(Game_Actor) # 攻击目标是伙伴的情况下
  106.         return
  107.       end
  108.       ind = $game_party.get_index_by(attacker)
  109.       s_ind = $game_troop.get_index_by(self)
  110.     elsif attacker.is_a?(Game_Enemy)
  111.       if self.is_a?(Game_Enemy) # 攻击目标是伙伴的情况下
  112.         return
  113.       end
  114.       ind = $game_troop.get_index_by(attacker)
  115.       s_ind = $game_party.get_index_by(self)
  116.     end
  117.     if ind.nil? || s_ind.nil?
  118.       return
  119.     end
  120.     # 初始化反击类型为普攻
  121.     act_kind = 'a'
  122.     act_id = 0
  123.     # 检测状态
  124.     for id in @states
  125.       # 如果状态名包含“反击”
  126.       if $data_states[id].name =~ /^#{STATE_COUNTER_NAME}/
  127.         # 初始化反击行动
  128.         react_cond = false
  129.         react_succ = false
  130.         # 检测
  131.         for opt in $data_states[id].options
  132.           # 检测伤害类型
  133.           if opt =~ /^cr([apmsend])([0-9]*)/
  134.             kind = $1
  135.             id = $2.to_i
  136.             react_cond = true
  137.             # 判断伤害类型
  138.             case kind
  139.             when 'a' # 物理攻击(普攻)
  140.               if skill.nil? && (rand(100) < id)
  141.                 react_succ = true
  142.               end              
  143.             when 'p' # 物理伤害(物理技能 + 普攻)
  144.               if skill.nil? || skill.atk_f != 0
  145.                 react_succ = true
  146.               end
  147.             when 'm' # 法术伤害(法术技能)
  148.               if !skill.nil? && skill.power > 0
  149.                 react_succ = true
  150.               end
  151.             when 's' # 技能伤害(法术技能+物理技能)
  152.               if !skill.nil? && (skill.power > 0 || skill.atk_f != 0)
  153.                 react_succ = true
  154.               end              
  155.             when 'e' # 属性攻击
  156.               if id.nil? || id.zero?
  157.                 next
  158.               elsif skill.nil? # 武器攻击属性
  159.                 if attacker.is_a?(Game_Actor) && !$data_weapons[@weapon_id].nil?
  160.                   if $data_weapons[@weapon_id].element_set.include?(id)
  161.                     react_succ = true
  162.                   end
  163.                 end
  164.               elsif skill.element_set.include?(id)# 敌人攻击属性
  165.                 react_succ = true
  166.               end
  167.             when 'n' # 令目标攻击无效
  168.               no_attack = true
  169.             #when 'ss' # 目标闪避攻击时反击
  170.             #  miss_attack = true
  171.             when 'd' # 目标死亡时反击
  172.               if self.dead? && self.movable?
  173.                 react_succ = true
  174.               end
  175.             end
  176.           # 检测反击类型
  177.           elsif opt =~ /^ca([ascie])([0-9]*)/
  178.             act_kind = $1
  179.             act_id = $2.to_i
  180.             #react_cond = true
  181.           end
  182.         end
  183.         # 反击条件成立的情况下
  184.         if (!react_cond || react_succ)
  185.           counter = true
  186.           break
  187.         else
  188.           next
  189.         end
  190.       end
  191.     end
  192.     # 不反击的情况下直接返回
  193.     if !counter
  194.       return
  195.     end
  196.     # 目标攻击无效的话恢复损失气血
  197.     if no_attack == true
  198.       if self.damage != "Miss"
  199.         self.hp += self.damage
  200.         self.damage = "Miss"
  201.         self.critical = false
  202.         @state_changed = false
  203.         self.states = @old_states
  204.       end
  205.     end
  206.     # 目标没有闪避伤害时直接返回
  207.     #if miss_attack == true and self.damage != "Miss"
  208.     #  return
  209.     #end
  210.     # 如果是复制攻击方行动效果
  211.     if act_kind == 'c'
  212.       if skill.nil?
  213.         act_kind = 'a'
  214.       else
  215.         act_kind = 's'
  216.         act_id = skill.id
  217.       end
  218.     end
  219.     # 判断反击类型
  220.     case act_kind
  221.     when 'a' # 攻击 kind:0 basic:0
  222.       self.counter_action.kind = 0
  223.       self.counter_action.target_index = ind
  224.       self.counter_action.basic = 0
  225.     when 's' # 技能 kind:1 basic:0
  226.       s = $data_skills[act_id]
  227.       # 判断技能是否不存在,是否战斗可用,是否角色可用
  228.       if s.nil? || ![0,1].include?(s.occasion) || !self.skill_can_use?(act_id)
  229.         return
  230.       end
  231.       self.counter_action.skill_id = act_id
  232.       self.counter_action.kind = 1
  233.       # 1敌单体,2敌全体
  234.       if [1,2].include?(s.scope)
  235.         self.counter_action.target_index = ind
  236.       else
  237.         self.counter_action.target_index = s_ind
  238.       end
  239.     when 'i' # 物品 kind:2 basic:0
  240.       i = $data_items[act_id]
  241.       # 判断是否是角色,物品是否不存在,是否战斗可用,是否角色可用
  242.       if !self.is_a?(Game_Actor) || i.nil? || ![0,1].include?(i.occasion) || !$game_party.item_can_use?(act_id)
  243.         return
  244.       end
  245.       self.counter_action.item_id = act_id
  246.       self.counter_action.kind = 2
  247.       # 1敌单体,2敌全体
  248.       if [1,2].include?(i.scope)
  249.         self.counter_action.target_index = ind
  250.       else
  251.         self.counter_action.target_index = s_ind
  252.       end
  253.     when 'e' # 逃跑 kind:0 basic:2
  254.       # 判断是否是敌人
  255.       if !self.is_a?(Game_Enemy)
  256.         return
  257.       end
  258.       self.counter_action.kind = 0
  259.       self.counter_action.target_index = ind
  260.       self.counter_action.basic = 2      
  261.     end
  262.     return   
  263.   end  
  264.   #----------------------------------------------------------------------
  265.   # ● 普通攻击效果
  266.   #     attacker : 攻击者
  267.   #----------------------------------------------------------------------
  268.   alias original_attack_effect_before_counter_action attack_effect
  269.   def attack_effect(attacker)
  270.     @old_states = self.states.clone
  271.     val = original_attack_effect_before_counter_action(attacker)
  272.     # 检测反击
  273.     self.counter_action_for(attacker)
  274.     return val
  275.   end   
  276.   #----------------------------------------------------------------------
  277.   # ● 技能攻击效果
  278.   #     user  : 技能使用者
  279.   #     skill : 技能ID
  280.   #----------------------------------------------------------------------
  281.   alias original_skill_effect_before_counter_action skill_effect
  282.   def skill_effect(attacker, skill)
  283.     @old_states = self.states.clone
  284.     val = original_skill_effect_before_counter_action(attacker, skill)
  285.     # 检测反击
  286.     self.counter_action_for(attacker, skill)
  287.     return val
  288.   end  
  289. end

  290. #===============================================================================
  291. # ■ Game_Actor
  292. #-------------------------------------------------------------------------------
  293. =begin
  294. class Game_Actor < Game_Battler
  295.   #----------------------------------------------------------------------
  296.   # ● 技能使用判定
  297.   #     skill_id : 技能 ID
  298.   #----------------------------------------------------------------------
  299.   def skill_can_use?(skill_id)
  300.     #if not skill_learn?(skill_id)
  301.     #  return false
  302.     #end
  303.     return super
  304.   end
  305. end
  306. =end

  307. #===============================================================================
  308. # ■ Game_BattleAction
  309. #-------------------------------------------------------------------------------

  310. class Game_BattleAction
  311.   #-----------------------------------------------------------------------
  312.   # ● 初始化
  313.   #-----------------------------------------------------------------------  
  314.   alias :xp_original_initialize :initialize
  315.   def initialize
  316.     xp_original_initialize()
  317.     @turn_move_times = 0
  318.   end
  319.   #-----------------------------------------------------------------------
  320.   # ● 清除判定
  321.   #-----------------------------------------------------------------------
  322.   def cleared?
  323.     if @speed == 0 && @kind == 0 && @basic == 3 && @skill_id == 0 && @item_id == 0 && @target_index == -1 && @forcing == false
  324.       return true
  325.     else
  326.       return false
  327.     end
  328.   end  
  329. end

  330. #===============================================================================
  331. # ■ Game_Party
  332. #-------------------------------------------------------------------------------

  333. class Game_Party
  334.   #----------------------------------------------------------------------
  335.   # ● 获得角色目标
  336.   #----------------------------------------------------------------------
  337.   def get_index_by(actor)
  338.      for i in 0...@actors.size()
  339.       if @actors[i].equal?(actor)
  340.         return i
  341.       end
  342.     end
  343.     return nil
  344.   end
  345. end

  346. #==========================================================================
  347. # ■ Game_Troop
  348. #--------------------------------------------------------------------------

  349. class Game_Troop
  350.   #----------------------------------------------------------------------
  351.   # ● 获得敌人目标
  352.   #----------------------------------------------------------------------
  353.   def get_index_by(enemy)
  354.     for i in 0...@enemies.size()
  355.       if @enemies[i].equal?(enemy)
  356.         return i
  357.       end
  358.     end
  359.     return nil
  360.   end
  361. end

  362. #==========================================================================
  363. # ■ Scene_Battle (分割定义 4)
  364. #--------------------------------------------------------------------------

  365. class Scene_Battle  
  366.   #----------------------------------------------------------------------
  367.   # ● 刷新画面 (主回合步骤 6 : 刷新)
  368.   #----------------------------------------------------------------------
  369.   alias original_update_phase4_step6_before_counter_action update_phase4_step6
  370.   def update_phase4_step6
  371.     original_update_phase4_step6_before_counter_action()
  372.     clear_counter_action(@active_battler)
  373.     activate_counter_action(@action_battlers)
  374.   end
  375.   #----------------------------------------------------------------------
  376.   # ● 清除行动
  377.   #----------------------------------------------------------------------
  378.   def clear_counter_action(active_battler)
  379.     #既にカウンターを行ったバトラーのカウンターアクションをクリア
  380.     if active_battler.nil?
  381.       return
  382.     end
  383.     if !active_battler.counter_acting?
  384.       return
  385.     end
  386.     active_battler.counter_action.clear
  387.     return
  388.   end
  389.   #----------------------------------------------------------------------
  390.   # ● 行动
  391.   #----------------------------------------------------------------------
  392.   def activate_counter_action(action_battlers)
  393.     #カウンター状態になったバトラーを一回だけアクションバトラーズにアンシフト
  394.     if !action_battlers[0].nil?
  395.       if action_battlers[0].counter_acting?#既にカウンター行動待機バトラーが居た場合
  396.         return
  397.       end
  398.     end
  399.     counter_battlers = []
  400.     $game_party.actors.each{|a|
  401.       if a.counter_acting?
  402.         counter_battlers.push(a)
  403.       end
  404.     }
  405.     $game_troop.enemies.each{|e|
  406.       if e.counter_acting?
  407.         counter_battlers.push(e)
  408.       end
  409.     }
  410.     counter_battlers = counter_battlers.sort_by{|b| b.agi}
  411.     counter_battlers.each{ |b|
  412.       action_battlers.unshift(b)
  413.     }
  414.     #p action_battlers.collect{|b| b.name}
  415.     return
  416.   end
  417. end

  418. #===============================================================================
  419. # ■ CP战斗对应。回合战斗不必要。
  420. #-------------------------------------------------------------------------------
  421. =begin
  422. class Game_Battler
  423.   if method_defined?(:cp)
  424.     alias original_cp_before_counter_action cp
  425.     def cp
  426.       if self.counter_acting?
  427.         return 65535
  428.       else
  429.         return original_cp_before_counter_action()
  430.       end
  431.     end
  432.   end
  433.   if method_defined?(:cp=)
  434.     alias original_cp_before_counter_action= cp=
  435.     def cp=(n)
  436.       if self.counter_acting?
  437.         return
  438.       else
  439.         self.original_cp_before_counter_action = n
  440.       end
  441.     end
  442.   end
  443. end
  444. =end
  445. #===============================================================================
  446. # ■ 状态重定义
  447. #-------------------------------------------------------------------------------

  448. module RPG
  449.   class State
  450.     #---------------------------------------------------------
  451.     # ● 定义状态名称
  452.     #---------------------------------------------------------
  453.     def name
  454.       if @new_name.nil?
  455.         name_setting()
  456.       end
  457.       return @new_name
  458.     end
  459.     #---------------------------------------------------------
  460.     # ● 定义状态伤害与反击类型
  461.     #---------------------------------------------------------   
  462.     def options
  463.       if @options.nil?
  464.         name_setting()
  465.       end
  466.       return @options
  467.     end
  468.     #---------------------------------------------------------
  469.     # ● 获取状态名称、伤害与反击类型
  470.     #---------------------------------------------------------
  471.     def name_setting
  472.       names = @name.split(/ +-/)
  473.       # 获取名称
  474.       @new_name = names.shift
  475.       if @new_name.nil?
  476.         @new_name = ''
  477.       end
  478.       # 获取伤害与反击类型
  479.       @options = names
  480.       if @options.nil?
  481.         @options = []
  482.       end
  483.     end   
  484.   end
  485. end
复制代码

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

本版积分规则

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

在本版发帖返回顶部