| 赞 | 0 |
| VIP | |
| 好人卡 | |
| 积分 | 1 |
| 经验 | |
| 最后登录 | 2016-12-17 |
| 在线时间 | 97 小时 |
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 97 小时
- 注册时间
- 2015-3-27
- 回帖
- 187
|
发表于 2016-5-9 22:23:35
|
显示全部楼层
本帖最后由 578783944 于 2016-5-9 22:29 编辑
送你一个脚本,这个脚本原作者应该是日本人,我将注释翻译成了汉语,并做了比较详细的注释。
同时,我对脚本做了一些修改,修复了原先的BUG,并且实现按概率反击,和复制攻击模式进行反击。
我做的修改都是针对回合制的,看脚本作者写的应该是也支持CP半即时制战斗。
注意:这个脚本是通过状态来实现反击的,当然也可以改进。
有什么问题你可以问我,最好给我博客留言或者发邮箱,在这里的话我可能不能及时看到。
我的博客
- #==========================================================================
- # 本脚本来自[url]www.66RPG.com[/url],由ikki转载。使用请保留此信息
- #=========================================================================
- # ▼▲▼ XRXS27. 特殊効果 SuperEX「反击」 ver.1.05 ▼▲▼
- # by シムナフ, ピニョン
- #========================================================================
- # □ 自定义设定
- #========================================================================
- class Game_Battler
- # 反击的状态名
- STATE_COUNTER_NAME = '反击'
- end
- #========================================================================
- # ◇ 说明文档
- #=======================================================================
- #****Warning! 重新定义了 Game_Actor#skill_can_use? ****
- #使用方法
- #对于身中“反击”状态的角色,当收到单独的攻击的时候会自动反击
- #反击的模式可以在下面设定
- #-cr (counter react)下面设定可以反击的挨打设定:
- # 比如设定一个状态名为“反击 -crm”,则受到魔法攻击的时候会自动反击
- #-cra50(attack) =>遭到物理攻击(普攻)的时候50%概率反击。
- #-crp (physical) =>遭到物理伤害(物攻+物理技能)的时候反击。
- #-crm (magic) =>遭到法术伤害(法术技能)的时候反击。
- #-crs (skill) =>遭到技能伤害(物理技能+法术技能)的时候反击。
- #-cre7 (element) =>遭到属性ID为7的攻击的时候反击。
- #-ca (counter act)下面设定反击行为:
- #比如设置一个状态名叫做“反击 -cas19”,那么受到攻击的时候就会用19号特技反击。
- #-caa (attack) =>使用物理攻击反击。
- #-cas1 (skill) =>使用ID为1的技能反击。
- #-cac (copy) =>复制敌人攻击方式(普攻+技能)进行反击。
- #-cai1 (item) =>使用ID为1的物品。
- #-cae (escape) =>逃跑,敌人使用。
- #注意和即时战斗的共同使用问题……
- #举例:设置一个状态,使得遭遇物理攻击的时候使用物品4,“反击 -crp -cai4”
- #========================================================================
- # ■ Game_Battler (分割定义 1)
- #========================================================================
- class Game_Battler
- #-----------------------------------------------------------------------
- # ● 状态初始化
- #-----------------------------------------------------------------------
- def states=(states)
- @states = states
- end
- #-----------------------------------------------------------------------
- # ● 对象初始化
- #-----------------------------------------------------------------------
- alias original_initialize_before_counter_action initialize
- def initialize
- original_initialize_before_counter_action()
- @counter_action = Game_BattleAction.new
- end
- #-----------------------------------------------------------------------
- # ● 获取当前的动作
- #-----------------------------------------------------------------------
- alias original_current_action_before_counter_action current_action
- def current_action
- if @counter_action.cleared?
- return original_current_action_before_counter_action()
- else
- return @counter_action
- end
- end
- #-----------------------------------------------------------------------
- # ● 获取当前的动作
- #-----------------------------------------------------------------------
- def counter_action
- return @counter_action
- end
- #-----------------------------------------------------------------------
- # ● 是否待机
- #-----------------------------------------------------------------------
- def counter_acting?
- if !@counter_action.cleared?
- return true
- else
- return false
- end
- end
- #-----------------------------------------------------------------------
- # ● 战斗不能判定
- #-----------------------------------------------------------------------
- #alias original_dead_before_counter_action dead?
- #def dead?
- # if self.counter_acting?
- # return false
- # else
- # return original_dead_before_counter_action()
- # end
- #end
- #----------------------------------------------------------------------
- # ●
- #----------------------------------------------------------------------
- def counter_action_for(attacker, skill = nil)
- # 行动存在时
- if attacker.counter_acting?
- return
- end
- # 无法行动和不存在的情况
- #if !self.movable? || !self.exist?
- # return
- #end
- if attacker.is_a?(Game_Actor)
- if self.is_a?(Game_Actor) # 攻击目标是伙伴的情况下
- return
- end
- ind = $game_party.get_index_by(attacker)
- s_ind = $game_troop.get_index_by(self)
- elsif attacker.is_a?(Game_Enemy)
- if self.is_a?(Game_Enemy) # 攻击目标是伙伴的情况下
- return
- end
- ind = $game_troop.get_index_by(attacker)
- s_ind = $game_party.get_index_by(self)
- end
- if ind.nil? || s_ind.nil?
- return
- end
- # 初始化反击类型为普攻
- act_kind = 'a'
- act_id = 0
- # 检测状态
- for id in @states
- # 如果状态名包含“反击”
- if $data_states[id].name =~ /^#{STATE_COUNTER_NAME}/
- # 初始化反击行动
- react_cond = false
- react_succ = false
- # 检测
- for opt in $data_states[id].options
- # 检测伤害类型
- if opt =~ /^cr([apmsend])([0-9]*)/
- kind = $1
- id = $2.to_i
- react_cond = true
- # 判断伤害类型
- case kind
- when 'a' # 物理攻击(普攻)
- if skill.nil? && (rand(100) < id)
- react_succ = true
- end
- when 'p' # 物理伤害(物理技能 + 普攻)
- if skill.nil? || skill.atk_f != 0
- react_succ = true
- end
- when 'm' # 法术伤害(法术技能)
- if !skill.nil? && skill.power > 0
- react_succ = true
- end
- when 's' # 技能伤害(法术技能+物理技能)
- if !skill.nil? && (skill.power > 0 || skill.atk_f != 0)
- react_succ = true
- end
- when 'e' # 属性攻击
- if id.nil? || id.zero?
- next
- elsif skill.nil? # 武器攻击属性
- if attacker.is_a?(Game_Actor) && !$data_weapons[@weapon_id].nil?
- if $data_weapons[@weapon_id].element_set.include?(id)
- react_succ = true
- end
- end
- elsif skill.element_set.include?(id)# 敌人攻击属性
- react_succ = true
- end
- when 'n' # 令目标攻击无效
- no_attack = true
- #when 'ss' # 目标闪避攻击时反击
- # miss_attack = true
- when 'd' # 目标死亡时反击
- if self.dead? && self.movable?
- react_succ = true
- end
- end
- # 检测反击类型
- elsif opt =~ /^ca([ascie])([0-9]*)/
- act_kind = $1
- act_id = $2.to_i
- #react_cond = true
- end
- end
- # 反击条件成立的情况下
- if (!react_cond || react_succ)
- counter = true
- break
- else
- next
- end
- end
- end
- # 不反击的情况下直接返回
- if !counter
- return
- end
- # 目标攻击无效的话恢复损失气血
- if no_attack == true
- if self.damage != "Miss"
- self.hp += self.damage
- self.damage = "Miss"
- self.critical = false
- @state_changed = false
- self.states = @old_states
- end
- end
- # 目标没有闪避伤害时直接返回
- #if miss_attack == true and self.damage != "Miss"
- # return
- #end
- # 如果是复制攻击方行动效果
- if act_kind == 'c'
- if skill.nil?
- act_kind = 'a'
- else
- act_kind = 's'
- act_id = skill.id
- end
- end
- # 判断反击类型
- case act_kind
- when 'a' # 攻击 kind:0 basic:0
- self.counter_action.kind = 0
- self.counter_action.target_index = ind
- self.counter_action.basic = 0
- when 's' # 技能 kind:1 basic:0
- s = $data_skills[act_id]
- # 判断技能是否不存在,是否战斗可用,是否角色可用
- if s.nil? || ![0,1].include?(s.occasion) || !self.skill_can_use?(act_id)
- return
- end
- self.counter_action.skill_id = act_id
- self.counter_action.kind = 1
- # 1敌单体,2敌全体
- if [1,2].include?(s.scope)
- self.counter_action.target_index = ind
- else
- self.counter_action.target_index = s_ind
- end
- when 'i' # 物品 kind:2 basic:0
- i = $data_items[act_id]
- # 判断是否是角色,物品是否不存在,是否战斗可用,是否角色可用
- if !self.is_a?(Game_Actor) || i.nil? || ![0,1].include?(i.occasion) || !$game_party.item_can_use?(act_id)
- return
- end
- self.counter_action.item_id = act_id
- self.counter_action.kind = 2
- # 1敌单体,2敌全体
- if [1,2].include?(i.scope)
- self.counter_action.target_index = ind
- else
- self.counter_action.target_index = s_ind
- end
- when 'e' # 逃跑 kind:0 basic:2
- # 判断是否是敌人
- if !self.is_a?(Game_Enemy)
- return
- end
- self.counter_action.kind = 0
- self.counter_action.target_index = ind
- self.counter_action.basic = 2
- end
- return
- end
- #----------------------------------------------------------------------
- # ● 普通攻击效果
- # attacker : 攻击者
- #----------------------------------------------------------------------
- alias original_attack_effect_before_counter_action attack_effect
- def attack_effect(attacker)
- @old_states = self.states.clone
- val = original_attack_effect_before_counter_action(attacker)
- # 检测反击
- self.counter_action_for(attacker)
- return val
- end
- #----------------------------------------------------------------------
- # ● 技能攻击效果
- # user : 技能使用者
- # skill : 技能ID
- #----------------------------------------------------------------------
- alias original_skill_effect_before_counter_action skill_effect
- def skill_effect(attacker, skill)
- @old_states = self.states.clone
- val = original_skill_effect_before_counter_action(attacker, skill)
- # 检测反击
- self.counter_action_for(attacker, skill)
- return val
- end
- end
- #===============================================================================
- # ■ Game_Actor
- #-------------------------------------------------------------------------------
- =begin
- class Game_Actor < Game_Battler
- #----------------------------------------------------------------------
- # ● 技能使用判定
- # skill_id : 技能 ID
- #----------------------------------------------------------------------
- def skill_can_use?(skill_id)
- #if not skill_learn?(skill_id)
- # return false
- #end
- return super
- end
- end
- =end
- #===============================================================================
- # ■ Game_BattleAction
- #-------------------------------------------------------------------------------
- class Game_BattleAction
- #-----------------------------------------------------------------------
- # ● 初始化
- #-----------------------------------------------------------------------
- alias :xp_original_initialize :initialize
- def initialize
- xp_original_initialize()
- @turn_move_times = 0
- end
- #-----------------------------------------------------------------------
- # ● 清除判定
- #-----------------------------------------------------------------------
- def cleared?
- if @speed == 0 && @kind == 0 && @basic == 3 && @skill_id == 0 && @item_id == 0 && @target_index == -1 && @forcing == false
- return true
- else
- return false
- end
- end
- end
- #===============================================================================
- # ■ Game_Party
- #-------------------------------------------------------------------------------
- class Game_Party
- #----------------------------------------------------------------------
- # ● 获得角色目标
- #----------------------------------------------------------------------
- def get_index_by(actor)
- for i in [email]0...@actors.size[/email]()
- if @actors[i].equal?(actor)
- return i
- end
- end
- return nil
- end
- end
- #==========================================================================
- # ■ Game_Troop
- #--------------------------------------------------------------------------
- class Game_Troop
- #----------------------------------------------------------------------
- # ● 获得敌人目标
- #----------------------------------------------------------------------
- def get_index_by(enemy)
- for i in [email]0...@enemies.size[/email]()
- if @enemies[i].equal?(enemy)
- return i
- end
- end
- return nil
- end
- end
- #==========================================================================
- # ■ Scene_Battle (分割定义 4)
- #--------------------------------------------------------------------------
- class Scene_Battle
- #----------------------------------------------------------------------
- # ● 刷新画面 (主回合步骤 6 : 刷新)
- #----------------------------------------------------------------------
- alias original_update_phase4_step6_before_counter_action update_phase4_step6
- def update_phase4_step6
- original_update_phase4_step6_before_counter_action()
- clear_counter_action(@active_battler)
- activate_counter_action(@action_battlers)
- end
- #----------------------------------------------------------------------
- # ● 清除行动
- #----------------------------------------------------------------------
- def clear_counter_action(active_battler)
- #既にカウンターを行ったバトラーのカウンターアクションをクリア
- if active_battler.nil?
- return
- end
- if !active_battler.counter_acting?
- return
- end
- active_battler.counter_action.clear
- return
- end
- #----------------------------------------------------------------------
- # ● 行动
- #----------------------------------------------------------------------
- def activate_counter_action(action_battlers)
- #カウンター状態になったバトラーを一回だけアクションバトラーズにアンシフト
- if !action_battlers[0].nil?
- if action_battlers[0].counter_acting?#既にカウンター行動待機バトラーが居た場合
- return
- end
- end
- counter_battlers = []
- $game_party.actors.each{|a|
- if a.counter_acting?
- counter_battlers.push(a)
- end
- }
- $game_troop.enemies.each{|e|
- if e.counter_acting?
- counter_battlers.push(e)
- end
- }
- counter_battlers = counter_battlers.sort_by{|b| b.agi}
- counter_battlers.each{ |b|
- action_battlers.unshift(b)
- }
- #p action_battlers.collect{|b| b.name}
- return
- end
- end
- #===============================================================================
- # ■ CP战斗对应。回合战斗不必要。
- #-------------------------------------------------------------------------------
- =begin
- class Game_Battler
- if method_defined?(:cp)
- alias original_cp_before_counter_action cp
- def cp
- if self.counter_acting?
- return 65535
- else
- return original_cp_before_counter_action()
- end
- end
- end
- if method_defined?(:cp=)
- alias original_cp_before_counter_action= cp=
- def cp=(n)
- if self.counter_acting?
- return
- else
- self.original_cp_before_counter_action = n
- end
- end
- end
- end
- =end
- #===============================================================================
- # ■ 状态重定义
- #-------------------------------------------------------------------------------
- module RPG
- class State
- #---------------------------------------------------------
- # ● 定义状态名称
- #---------------------------------------------------------
- def name
- if @new_name.nil?
- name_setting()
- end
- return @new_name
- end
- #---------------------------------------------------------
- # ● 定义状态伤害与反击类型
- #---------------------------------------------------------
- def options
- if @options.nil?
- name_setting()
- end
- return @options
- end
- #---------------------------------------------------------
- # ● 获取状态名称、伤害与反击类型
- #---------------------------------------------------------
- def name_setting
- names = @name.split(/ +-/)
- # 获取名称
- @new_name = names.shift
- if @new_name.nil?
- @new_name = ''
- end
- # 获取伤害与反击类型
- @options = names
- if @options.nil?
- @options = []
- end
- end
- end
- end
复制代码 |
评分
-
查看全部评分
|