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([pmedns])([0-9]*)/
kind = $1
id = $2.to_i
react_cond = true
case kind
when 'p'
if skill.nil? || skill.atk_f >= 100
react_succ = true
end
when 'm'
if !skill.nil? && skill.int_f >= 100
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 's'#回避時カウンター
miss_attack = true
when 'd'#死亡カウンター
if self.dead? && self.movable?
react_succ = true
end
end
elsif opt =~ /^ca([asime])([0-9]*)/
act_kind = $1
act_id = $2.to_i
act_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 != "被对手闪开了!"
self.hp += self.damage
self.damage = "反击!!"
self.critical = false
@state_changed = false
self.states = @old_states
end
end
# 回避時カウンターありでミスじゃないときはさよなら
if miss_attack == true and self.damage != "被对手闪开了!"
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 's'#skill kind:1 basic0
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
if [1,2].include?(s.scope)#1,2で敵単体、敵全体。
self.counter_action.target_index = ind
else
self.counter_action.target_index = s_ind
end
when 'i'#item 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
if [1,2].include?(i.scope)#1,2で敵単体、敵全体。
self.counter_action.target_index = ind
else
self.counter_action.target_index = s_ind
end
when 'a'#通常攻撃 kind:0 basic:0
self.counter_action.kind = 0
self.counter_action.target_index = ind
self.counter_action.basic = 0
when 'e'#escape 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 : スキル
#----------------------------------------------------------------------
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
class Game_Party
#----------------------------------------------------------------------
# ●
#----------------------------------------------------------------------
def get_index_by(actor)
for i in [email protected]()
if @actors.equal?(actor)
return i
end
end
return nil
end
end
class Game_Troop
#----------------------------------------------------------------------
# ●
#----------------------------------------------------------------------
def get_index_by(enemy)
for i in [email protected]()
if @enemies.equal?(enemy)
return i
end
end
return nil
end
end
#----------------------------------------------------------------------
# ● フレーム更新 (メインフェーズ ステップ 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バトル対応。
#ターンバトルの人は必要なし。
#=============================
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