=begin RGSS3 ★ バトルリトライ ★ 戦闘敗北時に、リトライするかの選択を可能にします。 ver1.00 Last Update : 2012/02/06 02/06 : 新規 ろかん   http://kaisou-ryouiki.sakura.ne.jp/ =end #=========================================== # 設定箇所 #=========================================== module Rokan module Retry_Battle # リトライを許可するスイッチ番号 RETRY_ENABLE_SWITCH = 10 # コマンドに表示する文字列 RETRY_COMMAND = "再戦" GIVEUP_COMMAND = "ギブアップ" end end #=========================================== # ここまで #=========================================== $rsi ||= {} $rsi["バトルリトライ"] = true class << BattleManager #-------------------------------------------------------------------------- # ● インクルード Rokan::Retry_Battle #-------------------------------------------------------------------------- include Rokan::Retry_Battle #-------------------------------------------------------------------------- # ● セットアップ #-------------------------------------------------------------------------- alias _retry_battle_setup setup def setup(troop_id, can_escape = true, can_lose = false) _retry_battle_setup(troop_id, can_escape, can_lose) setup_retry_data end #-------------------------------------------------------------------------- # ● オブジェクトをディープコピーして返す #-------------------------------------------------------------------------- def deep_cp(obj) Marshal.load(Marshal.dump(obj)) end #-------------------------------------------------------------------------- # ● リトライ用にデータを保持する #-------------------------------------------------------------------------- def backup_retry_data @retry_data = [] @retry_data << deep_cp($game_switches) @retry_data << deep_cp($game_variables) @retry_data << deep_cp($game_actors) @retry_data << deep_cp($game_party) @retry_data << deep_cp($game_troop) end #-------------------------------------------------------------------------- # ● リトライ用データを読み込む #-------------------------------------------------------------------------- def restore_retry_data $game_switches = deep_cp(@retry_data[0]) $game_variables = deep_cp(@retry_data[1]) $game_actors = deep_cp(@retry_data[2]) $game_party = deep_cp(@retry_data[3]) $game_troop = deep_cp(@retry_data[4]) end #-------------------------------------------------------------------------- # ● リトライの為の準備を行う #-------------------------------------------------------------------------- def setup_retry_data backup_retry_data end #-------------------------------------------------------------------------- # ● リトライの是非の選択開始 #-------------------------------------------------------------------------- def start_retry_selection SceneManager.scene.start_retry_selection end #-------------------------------------------------------------------------- # ● リトライの処理 #-------------------------------------------------------------------------- def process_retry Graphics.update Graphics.freeze restore_retry_data SceneManager.goto(Scene_Battle) BattleManager.play_battle_bgm Sound.play_battle_start end #-------------------------------------------------------------------------- # ● 敗北の処理 #-------------------------------------------------------------------------- alias _retry_battle_process_defeat process_defeat def process_defeat if $game_switches[RETRY_ENABLE_SWITCH] start_retry_selection else _retry_battle_process_defeat end end end class Game_Screen #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_writer :brightness # 明るさ end class Retry_Window < Window_Command #-------------------------------------------------------------------------- # ● インクルード Rokan::Retry_Battle #-------------------------------------------------------------------------- include Rokan::Retry_Battle #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super(0, 0) update_placement select_symbol(:reset_battle) self.openness = 0 self.active = false end #-------------------------------------------------------------------------- # ● ウィンドウ幅の取得 #-------------------------------------------------------------------------- def window_width return 160 end #-------------------------------------------------------------------------- # ● ウィンドウ位置の更新 #-------------------------------------------------------------------------- def update_placement self.x = (Graphics.width - width) / 2 self.y = (Graphics.height - height) / 2 end #-------------------------------------------------------------------------- # ● コマンドリストの作成 #-------------------------------------------------------------------------- def make_command_list add_command(RETRY_COMMAND, :retry) add_command(GIVEUP_COMMAND, :giveup) end #-------------------------------------------------------------------------- # ● ウィンドウのアクティブ化 #-------------------------------------------------------------------------- def activate open super end #-------------------------------------------------------------------------- # ● ウィンドウの非アクティブ化 #-------------------------------------------------------------------------- def deactivate close super end end class Scene_Battle < Scene_Base #-------------------------------------------------------------------------- # ● 開始処理 #-------------------------------------------------------------------------- alias _retry_battle_start start def start _retry_battle_start create_command_window end #-------------------------------------------------------------------------- # ● 終了処理 #-------------------------------------------------------------------------- alias _retry_battle_terminate terminate def terminate _retry_battle_terminate @command_window.dispose perform_battle_transition if SceneManager.scene_is?(Scene_Battle) end #-------------------------------------------------------------------------- # ● 確認コマンドウィンドウの作成 #-------------------------------------------------------------------------- def create_command_window @command_window = Retry_Window.new @command_window.set_handler(:retry, method(:reset_battle)) @command_window.set_handler(:giveup, method(:giveup_battle)) end #-------------------------------------------------------------------------- # ● リトライの是非の選択開始 #-------------------------------------------------------------------------- def start_retry_selection @command_window.activate bgm = RPG::BGM.last bgm.volume -= 20 bgm.play update_basic until @command_window.open? end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- alias _retry_battle_update update def update if @command_window.active super else _retry_battle_update end end #-------------------------------------------------------------------------- # ● フレーム更新(基本) #-------------------------------------------------------------------------- alias _retry_battle_update_basic update_basic def update_basic if @command_window && @command_window.active $game_troop.screen.brightness = [$game_troop.screen.brightness - 8, 160].max end _retry_battle_update_basic end #-------------------------------------------------------------------------- # ● 戦闘をあきらめる #-------------------------------------------------------------------------- def giveup_battle @command_window.deactivate BattleManager._retry_battle_process_defeat end #-------------------------------------------------------------------------- # ● 戦闘のリセット #-------------------------------------------------------------------------- def reset_battle @command_window.deactivate update_basic until @command_window.close? BattleManager.process_retry end #-------------------------------------------------------------------------- # ● 戦闘前トランジション実行 #-------------------------------------------------------------------------- def perform_battle_transition Graphics.transition(60, "Graphics/System/BattleStart", 100) Graphics.freeze end end