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
end
return super
end
end
=end
class Game_Party
#----------------------------------------------------------------------
# ● 获得角色目标
#----------------------------------------------------------------------
def get_index_by(actor)
for i in 0...@actors.size()
if @actors.equal?(actor)
return i
end
end
return nil
end
end
class Game_Troop
#----------------------------------------------------------------------
# ● 获得敌人目标
#----------------------------------------------------------------------
def get_index_by(enemy)
for i in 0...@enemies.size()
if @enemies.equal?(enemy)
return i
end
end
return nil
end
end
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
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
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
[/pre]
这个反击脚本中 如果用技能反击的话 需要已经习得那个特技 那么问题来了 如何去掉这个设定 让角色即使没有习得那个技能 也能用那个技能反击?