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

Project1

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

[已经解决] 求帮忙改反击脚本

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
49
在线时间
46 小时
注册时间
2011-10-7
帖子
95
跳转到指定楼层
1
发表于 2011-10-21 12:14:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 我不是字母君 于 2011-10-24 12:32 编辑
  1. #==========================================================================
  2. # 本脚本来自www.66RPG.com,由ikki转载。使用请保留此信息http://rpg.blue/forum.php?mod=post&action=edit&fid=18&tid=212215&pid=1783006&page=1
  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. #-crp  (physical)=>遭到通常攻击,物理攻击的时候反击
  23. #-crm  (masic)=>遭到魔法攻击的时候反击
  24. #-cre7 (element)=>遭到属性ID编号为7的攻击的时候反击。

  25. #-ca (counter act)下面设定反击行为
  26. #比如设置一个状态名叫做“反击 -cas19”,那么受到攻击的时候就会用19号特技反击。
  27. #-cas1 (skill)=>使用编号为1的技能
  28. #-cai1 (item)=>使用编号为1的物品。
  29. #-caa  (attack)=>使用物理攻击反击。
  30. #-cae  (escape)=>逃跑,敌人使用

  31. #-cac  (copy)=>受けたスキルをそのまま反击。未テスト(笑
  32. #何もつけない場合は通常攻撃反击になります。(不懂……?@_@?)

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

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

  35. #========================================================================
  36. # ■ Game_Battler (分割定義 1)
  37. #========================================================================

  38. class Game_Battler
  39.   #-----------------------------------------------------------------------
  40.   # ● オブジェクト初期化
  41.   #-----------------------------------------------------------------------
  42.   def states=(states)
  43.     @states = states
  44.   end
  45.   
  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.   #-----------------------------------------------------------------------
  58.   alias original_current_action_before_counter_action current_action
  59.   def current_action
  60.       if @counter_action.cleared?
  61.         return original_current_action_before_counter_action()
  62.       else
  63.         return @counter_action
  64.       end
  65.   end

  66.   #-----------------------------------------------------------------------
  67.   # ●
  68.   #-----------------------------------------------------------------------
  69.   def counter_action
  70.     return @counter_action
  71.   end
  72.   #-----------------------------------------------------------------------
  73.   # ●
  74.   #-----------------------------------------------------------------------
  75.   def counter_acting?
  76.     if !@counter_action.cleared?
  77.       return true
  78.     else
  79.       return false
  80.     end
  81.   end
  82.   #-----------------------------------------------------------------------
  83.   # ● 戦闘不能判定
  84.   #-----------------------------------------------------------------------
  85.   #alias original_dead_before_counter_action dead?
  86.   #def dead?
  87.   #  if self.counter_acting?
  88.   #    return false
  89.   #  else
  90.   #    return original_dead_before_counter_action()
  91.   #  end
  92.   #end
  93.   
  94.   #----------------------------------------------------------------------
  95.   # ●
  96.   #----------------------------------------------------------------------
  97.   def counter_action_for(attacker, skill = nil)
  98.     #カウンターからのカウンターは発生しない
  99.     if attacker.counter_acting?
  100.       return
  101.     end
  102.     #動けない場合存在しない場合は発生しない
  103.     #if !self.movable? || !self.exist?
  104.     #  return
  105.     #end
  106.     if attacker.is_a?(Game_Actor)
  107.       if self.is_a?(Game_Actor)#味方からの攻撃はカウンター不可
  108.         return
  109.       end
  110.       ind = $game_party.get_index_by(attacker)
  111.       s_ind = $game_troop.get_index_by(self)
  112.     elsif attacker.is_a?(Game_Enemy)
  113.       if self.is_a?(Game_Enemy)#味方からの攻撃はカウンター不可
  114.         return
  115.       end
  116.       ind = $game_troop.get_index_by(attacker)
  117.       s_ind = $game_party.get_index_by(self)
  118.     end
  119.     if ind.nil? || s_ind.nil?
  120.       return
  121.     end
  122.    
  123.     act_kind = 'a'
  124.     act_id = 0
  125.    
  126.     for id in @states
  127.       if $data_states[id].name =~ /^#{STATE_COUNTER_NAME}/
  128.         react_cond = false
  129.         react_succ = false
  130.         for opt in $data_states[id].options
  131.           if opt =~ /^cr([pmedns])([0-9]*)/
  132.             kind = $1
  133.             id = $2.to_i
  134.             react_cond = true
  135.             case kind
  136.             when 'p'
  137.               if skill.nil? || skill.atk_f >= 100
  138.                 react_succ = true
  139.               end
  140.             when 'm'
  141.               if !skill.nil? && skill.int_f >= 100
  142.                 react_succ = true
  143.               end
  144.             when 'e'
  145.               if id.nil? || id.zero?
  146.                 next
  147.               elsif skill.nil? #武器の攻撃属性
  148.                 if attacker.is_a?(Game_Actor) && !$data_weapons[@weapon_id].nil?
  149.                   if $data_weapons[@weapon_id].element_set.include?(id)
  150.                     react_succ = true
  151.                   end
  152.                 end
  153.               elsif skill.element_set.include?(id)#スキルの攻撃属性
  154.                 react_succ = true
  155.               end

  156.             when 'n'#相手攻撃無効カウンター
  157.               no_attack = true
  158.             when 's'#回避時カウンター
  159.               miss_attack = true
  160.             when 'd'#死亡カウンター
  161.               if self.dead? && self.movable?
  162.                 react_succ = true
  163.               end
  164.             end
  165.             
  166.           elsif opt =~ /^ca([asime])([0-9]*)/
  167.             act_kind = $1
  168.             act_id = $2.to_i
  169.             act_cond = true
  170.           end
  171.         end
  172.         
  173.         if (!react_cond || react_succ)#反击条件が無い・もしくは条件に一致
  174.           counter = true#カウンター成功
  175.           break
  176.         else
  177.           next
  178.         end
  179.         
  180.       end
  181.     end
  182.    
  183.     if !counter#カウンター成功していなかった場合
  184.       return
  185.     end


  186.     # 相手攻撃無効カウンターありならダメージ戻し
  187.     if no_attack == true
  188.       if self.damage != "被对手闪开了!"
  189.         self.hp += self.damage
  190.         self.damage = "抵抗"
  191.         self.critical = false
  192.         @state_changed = false
  193.         self.states = @old_states
  194.       end
  195.     end

  196.     # 回避時カウンターありでミスじゃないときはさよなら
  197.     if miss_attack == true and self.damage != "被对手闪开了!"
  198.       return
  199.     end


  200.     if act_kind == 'c'
  201.       if skill.nil?
  202.         act_kind = 'a'
  203.       else
  204.         act_kind = 's'
  205.         act_id = skill.id
  206.       end
  207.     end
  208.    
  209.     case act_kind
  210.     when 's'#skill kind:1 basic0
  211.       s = $data_skills[act_id]
  212.       if s.nil? || ![0,1].include?(s.occasion) || !self.skill_can_use?(act_id)
  213.         return
  214.       end
  215.       self.counter_action.skill_id = act_id
  216.       self.counter_action.kind = 1
  217.       if [1,2].include?(s.scope)#1,2で敵単体、敵全体。
  218.         self.counter_action.target_index = ind
  219.       else
  220.         self.counter_action.target_index = s_ind
  221.       end
  222.     when 'i'#item kind:2 basic:0
  223.       i = $data_items[act_id]
  224.       if !self.is_a?(Game_Actor) || i.nil? || ![0,1].include?(i.occasion) || !$game_party.item_can_use?(act_id)
  225.         return
  226.       end
  227.       self.counter_action.item_id = act_id
  228.       self.counter_action.kind = 2
  229.       if [1,2].include?(i.scope)#1,2で敵単体、敵全体。
  230.         self.counter_action.target_index = ind
  231.       else
  232.         self.counter_action.target_index = s_ind
  233.       end
  234.     when 'a'#通常攻撃 kind:0 basic:0
  235.       self.counter_action.kind = 0
  236.       self.counter_action.target_index = ind
  237.       self.counter_action.basic = 0
  238.     when 'e'#escape kind:0 basic:2
  239.       if !self.is_a?(Game_Enemy)
  240.         return
  241.       end
  242.       self.counter_action.kind = 0
  243.       self.counter_action.target_index = ind
  244.       self.counter_action.basic = 2      
  245.     end
  246.     return
  247.    
  248.   end
  249.   
  250.   #----------------------------------------------------------------------
  251.   # ● 通常攻撃の効果適用
  252.   #     attacker : 攻撃者 (バトラー)
  253.   #----------------------------------------------------------------------
  254.   alias original_attack_effect_before_counter_action attack_effect
  255.   def attack_effect(attacker)
  256.     @old_states = self.states.clone
  257.     val = original_attack_effect_before_counter_action(attacker)
  258.     self.counter_action_for(attacker)
  259.     return val
  260.   end  
  261.   
  262.   #----------------------------------------------------------------------
  263.   # ● スキルの効果適用
  264.   #     user  : スキルの使用者 (バトラー)
  265.   #     skill : スキル
  266.   #----------------------------------------------------------------------
  267.   alias original_skill_effect_before_counter_action skill_effect
  268.   def skill_effect(attacker, skill)
  269.     @old_states = self.states.clone
  270.     val = original_skill_effect_before_counter_action(attacker, skill)
  271.     self.counter_action_for(attacker, skill)
  272.     return val
  273.   end
  274.   
  275. end

  276. #=======================================================================
  277. # ■ Game_Actor
  278. #--------------------------------------------------------------------------
  279. #  アクターを扱うクラスです。このクラスは Game_Actors クラス ($game_actors)
  280. # の内部で使用され、Game_Party クラス ($game_party) からも参照されます。
  281. #=======================================================================

  282. class Game_Actor < Game_Battler
  283.   #----------------------------------------------------------------------
  284.   # ● スキルの使用可能判定
  285.   #     skill_id : スキル ID
  286.   #----------------------------------------------------------------------
  287.   def skill_can_use?(skill_id)
  288.     #if not skill_learn?(skill_id)
  289.     #  return false
  290.     #end
  291.     return super
  292.   end
  293. end

  294. #========================================================================
  295. # ■ Game_BattleAction
  296. #-------------------------------------------------------------------------
  297. #  アクション (戦闘中の行動) を扱うクラスです。このクラスは Game_Battler クラ
  298. # スの内部で使用されます。
  299. #========================================================================

  300. class Game_BattleAction
  301.   
  302.   alias :xp_original_initialize :initialize
  303.   def initialize
  304.     xp_original_initialize()
  305.     @turn_move_times = 0
  306.   end
  307.   #-----------------------------------------------------------------------
  308.   # ● クリア判定
  309.   #-----------------------------------------------------------------------
  310.   def cleared?
  311.     if @speed == 0 && @kind == 0 && @basic == 3 && @skill_id == 0 && @item_id == 0 && @target_index == -1 && @forcing == false
  312.       return true
  313.     else
  314.       return false
  315.     end
  316.   end
  317.   
  318. end


  319. #=========================================================================
  320. # ■ Game_Party
  321. #--------------------------------------------------------------------------
  322. #  パーティを扱うクラスです。ゴールドやアイテムなどの情報が含まれます。このク
  323. # ラスのインスタンスは $game_party で参照されます。
  324. #=========================================================================

  325. class Game_Party
  326.   #----------------------------------------------------------------------
  327.   # ●
  328.   #----------------------------------------------------------------------
  329.   def get_index_by(actor)
  330.     for i in [email protected]()
  331.       if @actors[i].equal?(actor)
  332.         return i
  333.       end
  334.     end
  335.     return nil
  336.   end
  337. end


  338. #==========================================================================
  339. # ■ Game_Troop
  340. #--------------------------------------------------------------------------
  341. #  トループを扱うクラスです。このクラスのインスタンスは $game_troop で参照さ
  342. # れます。
  343. #==========================================================================

  344. class Game_Troop
  345.   #----------------------------------------------------------------------
  346.   # ●
  347.   #----------------------------------------------------------------------
  348.   def get_index_by(enemy)
  349.     for i in [email protected]()
  350.       if @enemies[i].equal?(enemy)
  351.         return i
  352.       end
  353.     end
  354.     return nil
  355.   end
  356. end

  357. #==========================================================================
  358. # ■ Scene_Battle (分割定義 4)
  359. #--------------------------------------------------------------------------
  360. #  バトル画面の処理を行うクラスです。
  361. #==========================================================================

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


  416. #=============================
  417. #CPバトル対応。
  418. #ターンバトルの人は必要なし。
  419. #=============================
  420. class Game_Battler
  421.   if method_defined?(:cp)
  422.     alias original_cp_before_counter_action cp
  423.     def cp
  424.       if self.counter_acting?
  425.         return 65535
  426.       else
  427.         return original_cp_before_counter_action()
  428.       end
  429.     end
  430.   end
  431.   if method_defined?(:cp=)
  432.     alias original_cp_before_counter_action= cp=
  433.     def cp=(n)
  434.       if self.counter_acting?
  435.         return
  436.       else
  437.         self.original_cp_before_counter_action = n
  438.       end
  439.     end
  440.   end
  441. end
  442. #=============================
  443. #ここまで。
  444. #=============================


  445.   #---------------------------------------------------------------------
  446.   #
  447.   #---------------------------------------------------------------------

  448. module RPG
  449.   class State
  450.     def name
  451.       if @new_name.nil?
  452.         name_setting()
  453.       end
  454.       return @new_name
  455.     end
  456.    
  457.     def options
  458.       if @options.nil?
  459.         name_setting()
  460.       end
  461.       return @options
  462.     end
  463.    
  464.     def name_setting
  465.       names = @name.split(/ +-/)
  466.       @new_name = names.shift
  467.       if @new_name.nil?
  468.         @new_name = ''
  469.       end
  470.       @options = names
  471.       if @options.nil?
  472.         @options = []
  473.       end
  474.     end
  475.     def description
  476.       return @description.split(/P/)[0]
  477.     end
  478.     def priority
  479.       return @description.split(/P/)[1]
  480.     end
  481.   end
  482. end

复制代码
希望能改成概率反击而不是必定反击。
为了防止6R想度娘一样吞分,解答问题者领分请后台
我是傻逼

Lv1.梦旅人

梦石
0
星屑
50
在线时间
22 小时
注册时间
2011-10-11
帖子
72
2
发表于 2011-10-24 12:35:09 | 只看该作者
小号自顶一次(超过3小时了)
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
113 小时
注册时间
2011-10-6
帖子
45
3
发表于 2011-10-24 13:34:16 | 只看该作者
在所有self.counter_action_for这条语句上面插入概率不就行了吗,或者在def counter_action_for(attacker, skill = nil)主体的开头插入也行

点评

结贴之前,声明一下:在讨论区,兰州永远是烧饼  发表于 2011-10-24 14:02
突然发现只有两个counter。。。给分,请查收。  发表于 2011-10-24 14:00
注意每一个随机变量(即便连续,没有randomize分割)都会不一样。 如果真的没人做,就做坟贴处理了  发表于 2011-10-24 13:57
这样是不行的,由于各种counter如果每个都概率,那么将会有的执行有的不执行,产生乱套。 注意每一个随机变量(即便连续,没有randomize分割)都会不  发表于 2011-10-24 13:57
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-20 10:14

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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