#============================================================================== # ■ XP-RGSS-43 瞬刻防御 [Ver.1.1.0] by Claimh #------------------------------------------------------------------------------ # エネミー攻撃時にタイミングよくキーを入力すると、ある確率で防御 or 回避できる。 # ただし、回避を失敗すると通常以上のダメージを受けてしまう # 効果があるのはエネミーからの単体攻撃時のみ # 戦闘不能となるダメージを受けた場合は、防御/回避は出来ません # ステート攻撃も回避することが出来ます(防御時はステートが付与されることもある) #============================================================================== module MomentGuard #============================================================================== # □ カスタマイズSTART #============================================================================== #-----機能設定-----# # 防御機能有効化 M_GUARD = true # 回避機能有効化 M_AVOID = true #-----キー設定-----# # 防御 GUARD_KEY = Input::X # 回避 AVOID_KEY = Input::Y #-----動作成功SE設定(不要:nil)-----# # 防御 GUARD_SE = nil#"154-Support12" # 回避 AVOID_SE = nil#"064-Swing03" #-----動作アニメ設定(不要:0)-----# # 防御 GUARD_ANIME_ID = 64 # 回避 AVOID_ANIME_ID = 24 #-----無効属性設定-----# # 防御無効属性 N_GUARD_EL = 1 # 回避無効属性 N_AVOID_EL = 2 #-----その他-----# # 回避失敗時のダメージ増加率 AVOID_MISS = 0.5 #-----ダブルアニメーション導入-----# # 防御/回避のアニメーションをダブルアニメーションで表示させる # ※必須「ダブルアニメーション」 DOUBLE_ANI = false #============================================================================== # □ カスタマイズEND #============================================================================== end #============================================================================== # ■ Scene_Battle #============================================================================== class Scene_Battle #-------------------------------------------------------------------------- # ● 変数初期化 #-------------------------------------------------------------------------- def mga_refresh @mga_key_check = false @mga_key_defence = false @mga_key_avoid = false end #-------------------------------------------------------------------------- # ● ステート変数初期化 #-------------------------------------------------------------------------- def mga_refresh_states # アクターのステート付与状態を保持 @actor_states = [] for actor in $game_party.actors @actor_states[actor.id] = actor.states.dup end end #-------------------------------------------------------------------------- # ● animation setting #-------------------------------------------------------------------------- def set_anime(actor, anime_id) return if anime_id == 0 if MomentGuard::DOUBLE_ANI actor.double_animation_id = anime_id # ダブルアニメーション表示 else actor.animation_id = anime_id end end #-------------------------------------------------------------------------- # ● ステートの後戻し処理 #-------------------------------------------------------------------------- def refresh_states(actor, enemy) # アクションの種別で分岐 case enemy.current_action.kind when 0 # 基本 add_states = enemy.plus_state_set del_states = enemy.minus_state_set when 1 # スキル add_states = $data_skills[enemy.current_action.skill_id].plus_state_set del_states = $data_skills[enemy.current_action.skill_id].minus_state_set when 2 # アイテム add_states = $data_items[enemy.current_action.item_id].plus_state_set del_states = $data_items[enemy.current_action.item_id].minus_state_set else return end # 付与されたステートは解除 for state in add_states # 攻撃によって付与された場合 unless @actor_states.include?(state) actor.remove_state(state, true) # 強制解除 end end # 解除されたステートは付与 for state in del_states # 攻撃によって解除された場合 unless @actor_states.include?(state) actor.add_state(state, true) # 強制付与 end end end #-------------------------------------------------------------------------- # ● 発動条件判定 #-------------------------------------------------------------------------- def mga_jegdement(attaker, target, skill, item) # エネミー以外の攻撃では発動しない return false unless attaker.is_a?(Game_Enemy) # アクションの種別で分岐 case attaker.current_action.kind when 0 # 基本 # 攻撃時のみ有効 if attaker.current_action.basic == 0 # 味方攻撃時は無効 return false if attaker.restriction == 3 # ターゲット:単体アクター if !target.empty? and target.size == 1 and target[0].is_a?(Game_Actor) return true end end when 1 # スキル if !skill.nil? and skill.scope == 1 # ターゲット:単体アクター if !target.empty? and target.size == 1 and target[0].is_a?(Game_Actor) return true end end when 2 # アイテム if !item.nil? and item.scope == 1 # ターゲット:単体アクター if !target.empty? and target.size == 1 and target[0].is_a?(Game_Actor) return true end end end return false end #-------------------------------------------------------------------------- # ● 防御可能判定 #-------------------------------------------------------------------------- def mga_defencable?(enemy, actor) # 機能無効 return false unless MomentGuard::M_GUARD # 防御無効属性攻撃 return false if enemy.element_set.include?(MomentGuard::N_GUARD_EL) # 行動不可 return false unless actor.movable? # 攻撃が当たっていない return false if actor.damage == "Miss" # すでに防御 return false if actor.guarding? # すでに死亡 return false if actor.dead? # 防御可能 return true end #-------------------------------------------------------------------------- # ● 回避可能判定 #-------------------------------------------------------------------------- def mga_avoidable?(enemy, actor) # 機能無効 return false unless MomentGuard::M_AVOID # 回避無効属性攻撃 return false if enemy.element_set.include?(MomentGuard::N_AVOID_EL) # 行動不可 return false unless actor.movable? # 攻撃が当たっていない return false if actor.damage == "Miss" # すでに死亡 return false if actor.dead? # 回避可能 return true end #-------------------------------------------------------------------------- # ● 防御計算 #-------------------------------------------------------------------------- def mga_defence_ex(actor, enemy) sp_ev = actor.agi + actor.dex defence = (actor.pdef + actor.mdef) / 2 if sp_ev > 0 a_eval = (((sp_ev + (defence/enemy.atk).round) * ((rand(101) * 100)/100 )) / sp_ev).round else a_eval = -1 # 必ず失敗する[例外] end srand() if enemy.hit > 0 e_hit = ((enemy.hit * ((rand(101) * 100)/100 )) / enemy.hit).round else e_hit = 0 # 例外を除いて、必ず成功する end # 防御判定 if a_eval > e_hit unless actor.damage.is_a?(String) damage = actor.damage actor.damage = (damage / 2).round actor.hp += damage - actor.damage actor.damage = "Guard " + actor.damage.to_s end # SE再生 unless MomentGuard::GUARD_SE.nil? Audio.se_play("Audio/SE/" + MomentGuard::GUARD_SE) end # アニメーションのセット set_anime(actor, MomentGuard::GUARD_ANIME_ID) end end #-------------------------------------------------------------------------- # ● 回避成功計算 #-------------------------------------------------------------------------- def mga_avoid_ex(actor, enemy) sp_ev = actor.agi + actor.dex if sp_ev > 0 a_eval = (((sp_ev + actor.eva) * ((rand(101) * 100)/100 )) / sp_ev).round else a_eval = -1 # 必ず失敗する[例外] end srand() if enemy.hit > 0 e_hit = ((enemy.hit * ((rand(101) * 100)/100 )) / enemy.hit).round else e_hit = 0 # 例外を除いて、必ず成功する end # 回避判定 if a_eval > e_hit if actor.damage.is_a?(Numeric) actor.hp += actor.damage end actor.damage = "Avoid!" # SE再生 unless MomentGuard::AVOID_SE.nil? Audio.se_play("Audio/SE/" + MomentGuard::AVOID_SE) end # アニメーションのセット set_anime(actor, MomentGuard::AVOID_ANIME_ID) # ステート解除処理 refresh_states(actor, enemy) else if actor.damage.is_a?(Numeric) # 失敗時はダメージ増加 add_damage = (actor.damage * MomentGuard::AVOID_MISS).round actor.damage += add_damage actor.hp -= add_damage end end end #↓↓↓↓↓alias↓↓↓↓↓# #-------------------------------------------------------------------------- # ● フレーム更新 (メインフェーズ ステップ 1 : アクション準備) #-------------------------------------------------------------------------- alias update_phase4_step1_mga update_phase4_step1 def update_phase4_step1 mga_refresh mga_refresh_states update_phase4_step1_mga # 原型 end #-------------------------------------------------------------------------- # ● フレーム更新 (メインフェーズ ステップ 4 : 対象側アニメーション) #-------------------------------------------------------------------------- alias update_phase4_step4_mga update_phase4_step4 def update_phase4_step4 update_phase4_step4_mga # 原型 # 条件判定 if mga_jegdement(@active_battler, @target_battlers, @skill, @item) # 防御判定 if mga_defencable?(@active_battler, @target_battlers[0]) @mga_key_defence = true end # 回避判定 if mga_avoidable?(@active_battler, @target_battlers[0]) @mga_key_avoid = true end # キー入力開始判定 if @mga_key_defence or @mga_key_avoid @mga_key_check = true end end end #-------------------------------------------------------------------------- # ● フレーム更新 (メインフェーズ ステップ 5 : ダメージ表示) #-------------------------------------------------------------------------- alias update_phase4_step5_mga update_phase4_step5 def update_phase4_step5 mga_refresh # 保険 update_phase4_step5_mga # 原型 end #-------------------------------------------------------------------------- # ● フレーム更新 (メインフェーズ ステップ 6 : リフレッシュ) #-------------------------------------------------------------------------- alias update_phase4_step6_mga update_phase4_step6 def update_phase4_step6 mga_refresh # 保険 mga_refresh_states # 保険 update_phase4_step6_mga # 原型 end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- alias update_mga update def update if @mga_key_check # 防御 if @mga_key_defence if Input.trigger?(MomentGuard::GUARD_KEY) mga_defence_ex(@target_battlers[0], @active_battler) mga_refresh end end # 回避 if @mga_key_avoid if Input.trigger?(MomentGuard::AVOID_KEY) mga_avoid_ex(@target_battlers[0], @active_battler) mga_refresh end end end update_mga # 原型 end end