#============================================================================== # ■ VXAce-RGSS3-47 フィールドマップ [database] by Claimh #============================================================================== module FieldMap #-------------------------------------------------------------------------- # ● 配列チェック #-------------------------------------------------------------------------- def self.ary_include?(ary, id) return false unless ary.is_a?(Array) return ary.include?(id) end #-------------------------------------------------------------------------- # ● Hash keyチェック #-------------------------------------------------------------------------- def self.key_include?(hash, id) return false unless hash.is_a?(Hash) return hash.keys.include?(id) end #-------------------------------------------------------------------------- # ● 移動地点イベントチェック #-------------------------------------------------------------------------- def self.ev_include?(map_id, ev_id) return true if EV[map_id].nil? ary_include?(EV[map_id], ev_id) end #-------------------------------------------------------------------------- # ● 中継地点イベントチェック #-------------------------------------------------------------------------- def self.tr_include?(map_id, ev_id) ary_include?(TR[map_id], ev_id) end #-------------------------------------------------------------------------- # ● ルートIDチェック #-------------------------------------------------------------------------- def self.rt_include?(map_id, r_id) key_include?(RT[map_id], r_id) end #-------------------------------------------------------------------------- # ● イベントIDチェック #-------------------------------------------------------------------------- def self.check_ev(map_id, ev_id) return false if RT[map_id].nil? or RT[map_id].keys.empty? return false if !ev_include?(map_id, ev_id) and !tr_include?(map_id, ev_id) return RT[map_id].values.any? {|v| v[:from] == ev_id or v[:to] == ev_id} end #-------------------------------------------------------------------------- # ● 移動ルート情報参照 #-------------------------------------------------------------------------- def self.route(map_id, r_id) return nil if RT[map_id].nil? RT[map_id][r_id] end #-------------------------------------------------------------------------- # ● 移動ルート条件有効化 #-------------------------------------------------------------------------- def self.enable_ev_condition(map_id, ev_id, page) ev = load_data(sprintf("Data/Map%03d.rvdata2", map_id)).events[ev_id] cond = ev.pages[page].condition $game_switches[cond.switch1_id] = true if cond.switch1_valid $game_switches[cond.switch2_id] = true if cond.switch2_valid $game_variables[cond.variable_id] = variable_value if cond.variable_valid $game_self_switches[[map_id, ev_id, cond.self_switch_ch]] = true if cond.self_switch_valid msgbox_p "条件:アイテムあり ev:#{ev_id} page#{page} item:#{cond.item_id}" if cond.item_valid msgbox_p "条件:アクターあり ev:#{ev_id} page#{page} item:#{cond.actor_id}" if cond.actor_valid end #-------------------------------------------------------------------------- # ● 移動ルート条件無効化 #-------------------------------------------------------------------------- def self.disable_ev_condition(map_id, ev_id, page) ev = load_data(sprintf("Data/Map%03d.rvdata2", map_id)).events[ev_id] cond = ev.pages[page].condition $game_switches[cond.switch1_id] = false if cond.switch1_valid $game_switches[cond.switch2_id] = false if cond.switch2_valid $game_variables[cond.variable_id] = 0 if cond.variable_valid $game_self_switches[[map_id, ev_id, cond.self_switch_ch]] = false if cond.self_switch_valid msgbox_p "条件:アイテムあり ev:#{ev_id} page#{page} item:#{cond.item_id}" if cond.item_valid msgbox_p "条件:アクターあり ev:#{ev_id} page#{page} item:#{cond.actor_id}" if cond.actor_valid end #-------------------------------------------------------------------------- # ● イベントリスト(現map限定) #-------------------------------------------------------------------------- def self.ev_list(ev_id, page) $game_map.events[ev_id].pages[page].list end #-------------------------------------------------------------------------- # ● イベント実行 #-------------------------------------------------------------------------- def self.exec_list(list) $game_map.interpreter.clear $game_map.interpreter.setup(list) end #-------------------------------------------------------------------------- # ● イベント実行 #-------------------------------------------------------------------------- def self.exec_ev(ev_id, page) exec_list(ev_list(ev_id, page)) end end #============================================================================== # ■ FieldMap::FieldPos : 座標情報クラス #============================================================================== class FieldMap::FieldPos attr_reader :x attr_reader :y attr_reader :dir attr_reader :fade #-------------------------------------------------------------------------- # ● オブジェクト初期化 # x .. X座標 # y .. Y座標 # dir .. 向き(2:下 4:左 6:右 8:上 0:そのまま) #-------------------------------------------------------------------------- def initialize(x, y, dir=0, fade=0) @x = x; @y = y; @dir = dir;@fade = fade end end #============================================================================== # ■ FieldMap::FieldPos2 : 座標情報クラス #============================================================================== class FieldMap::FieldPos2 attr_reader :x attr_reader :y #-------------------------------------------------------------------------- # ● オブジェクト初期化 # x .. X座標 # y .. Y座標 #-------------------------------------------------------------------------- def initialize(x, y) @x = x; @y = y end def r; @x+=1; self; end # 右 def l; @x-=1; self; end # 左 def u; @y-=1; self; end # 上 def d; @y+=1; self; end # 下 def move(dir) case dir when 2; d when 4; l when 6; r when 8; u when 1; l.d when 3; r.d when 7; l.u when 9; r.u end self end def renew; FieldMap::FieldPos2.new(@x, @y); end end #============================================================================== # ■ Game_Temp #============================================================================== class Game_Temp #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :from_fieldmap # フィールドマップ遷移 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias init_fieldmap initialize def initialize init_fieldmap @from_fieldmap = false end end #============================================================================== # ■ Game_Player #============================================================================== class Game_Player < Game_Character #-------------------------------------------------------------------------- # ● 方向ボタン入力による移動処理 #-------------------------------------------------------------------------- alias move_by_input_fieldmap move_by_input def move_by_input # フィールドマップ上では移動禁止 move_by_input_fieldmap unless SceneManager.scene_is?(Scene_FieldMap) end end #============================================================================== # ■ Game_Event #============================================================================== class Game_Event < Game_Character #-------------------------------------------------------------------------- # ● ページ情報 #-------------------------------------------------------------------------- def pages @event.pages end #-------------------------------------------------------------------------- # ● RPG::Event情報 #-------------------------------------------------------------------------- def data @event end #-------------------------------------------------------------------------- # ● イベントページの設定をセットアップ #-------------------------------------------------------------------------- alias setup_page_settings_fieldmap setup_page_settings def setup_page_settings setup_page_settings_fieldmap @interpreter = nil if SceneManager.scene_is?(Scene_FieldMap) end #-------------------------------------------------------------------------- # ● 条件に合うイベントページを見つける #-------------------------------------------------------------------------- alias find_proper_page_fieldmap find_proper_page def find_proper_page if SceneManager.scene_is?(Scene_FieldMap) # フィールドマップ上の移動地点/中継地点は移動ページのみで評価 if FieldMap.tr_include?(@map_id, @id) return conditions_met?(@event.pages[0]) ? @event.pages[0] : nil elsif FieldMap.ev_include?(@map_id, @id) page = $game_system.field[@map_id].place[@id].page return conditions_met?(@event.pages[page]) ? @event.pages[page] : nil end end find_proper_page_fieldmap end #-------------------------------------------------------------------------- # ● 自動イベントの起動判定 #-------------------------------------------------------------------------- alias check_event_trigger_auto_fieldmap check_event_trigger_auto def check_event_trigger_auto # 自動実行は許可しない check_event_trigger_auto_fieldmap unless SceneManager.scene_is?(Scene_FieldMap) end end #============================================================================== # ■ Game_Player #============================================================================== class Game_Player < Game_Character #-------------------------------------------------------------------------- # ● 移動中でない場合の処理 # last_moving : 直前に移動中だったか #-------------------------------------------------------------------------- alias update_nonmoving_fieldmap update_nonmoving def update_nonmoving(last_moving) update_nonmoving_fieldmap(last_moving) unless SceneManager.scene_is?(Scene_FieldMap) end end #============================================================================== # ■ Game_System #============================================================================== class Game_System #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias initialize_fieldmap initialize def initialize initialize_fieldmap init_fieldmap end #-------------------------------------------------------------------------- # ● フィールドマップ情報初期化 #-------------------------------------------------------------------------- def init_fieldmap @field = FieldMap::FieldInfo.new end #-------------------------------------------------------------------------- # ● フィールドマップ情報 #-------------------------------------------------------------------------- def field @field || init_fieldmap end end #============================================================================== # ■ Game_Map #============================================================================== class Game_Map #-------------------------------------------------------------------------- # ● 並列処理コモンイベントの配列を取得 #-------------------------------------------------------------------------- alias parallel_common_events_fieldmap parallel_common_events def parallel_common_events return [] if SceneManager.scene_is?(Scene_FieldMap) parallel_common_events_fieldmap end end #============================================================================== # ■ FieldMap::FieldInfo : フィールド情報クラス #============================================================================== class FieldMap::FieldInfo #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize @data = {} end #-------------------------------------------------------------------------- # ● フィールドマップ情報参照 #-------------------------------------------------------------------------- def [](map_id) @data[map_id] ||= FieldMap::FieldMapInfo.new(map_id) end end #============================================================================== # ■ FieldMap::FieldMapInfo : フィールドマップ情報クラス #============================================================================== class FieldMap::FieldMapInfo attr_reader :route # ルート情報 attr_reader :place # 移動移転情報 attr_accessor :text # 表示テキスト #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(map_id) @map_id = map_id @text = FieldMap::TXT[map_id] @route = FieldMap::RouteInfo.new(@map_id) @place = FieldMap::PlaceInfo.new(@map_id) end end #============================================================================== # ■ FieldMap::PlaceInfo : Map上移動地点情報クラス #============================================================================== class FieldMap::PlaceInfo attr_reader :data #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(map_id) @map_id = map_id @data = {} end #-------------------------------------------------------------------------- # ● 移動地点情報参照 #-------------------------------------------------------------------------- def [](ev_id) return err_print(ev_id) unless include?(ev_id) @data[ev_id] ||= FieldMap::Place.new(@map_id, ev_id) end def err_print(ev_id) msgbox_p "不正なイベントを参照しています(EV未登録) : MAP[#{@map_id}] EV[#{ev_id}]", FieldMap::EV[@map_id], FieldMap::TR[@map_id], FieldMap::RT[@map_id] nil end #-------------------------------------------------------------------------- # ● 移動地点IDチェック #-------------------------------------------------------------------------- def include?(ev_id) FieldMap::check_ev(@map_id, ev_id) end end #============================================================================== # ■ FieldMap::Place : 移動地点情報クラス #============================================================================== class FieldMap::Place attr_reader :page # 移動ページ attr_accessor :force # 強制移動 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(map_id, ev_id) @map_id = map_id @ev_id = ev_id @page = 0 @enable = true @force = false end #-------------------------------------------------------------------------- # ● マップ移動イベント有効チェック #-------------------------------------------------------------------------- def check_ev_enable map = Game_Map.new map.setup(@map_id) map.setup_events ev = Game_Event.new(@map_id, map.events[@ev_id]) ev.conditions_met?(map.events[@ev_id].pages[@page]) end #-------------------------------------------------------------------------- # ● マップ移動イベント実行 #-------------------------------------------------------------------------- def into return unless @enable list = [] pos = nil page_list = FieldMap.ev_list(@ev_id, @page) page_list.each do |cmd| if cmd.code == 201 if cmd.parameters[0] == 0 x = cmd.parameters[2] y = cmd.parameters[3] else x = $game_variables[cmd.parameters[2]] y = $game_variables[cmd.parameters[3]] end pos = FieldMap::FieldPos.new(x, y, cmd.parameters[4], cmd.parameters[5]) else list.push(cmd) end end FieldMap.exec_list(list) pos end #-------------------------------------------------------------------------- # ● 移動イベントページ変更 #-------------------------------------------------------------------------- def page=(pg) disable @page = pg - 1 enable end #-------------------------------------------------------------------------- # ● 現在位置のマップID取得 #-------------------------------------------------------------------------- def target_map_id return nil if FieldMap.tr_include?(@map_id, @ev_id) ev = load_data(sprintf("Data/Map%03d.rvdata2", @map_id)).events[@ev_id] list = ev.pages[@page].list # 場所移動コマンド[command_201] list.select {|l| l.code == 201}.each do |c| if c.parameters[0] == 0 # 直接指定 return c.parameters[1] else # 変数で指定 return $game_variables[c.parameters[1]] end end msgbox_p "場所移動イベント設定ミス! : MAP[#{@map_id}] EV[#{@ev_id}]", list nil # 見つからない end #-------------------------------------------------------------------------- # ● 移動禁止? #-------------------------------------------------------------------------- def enable? @enable end #-------------------------------------------------------------------------- # ● 移動禁止 #-------------------------------------------------------------------------- def restrict @enable = false @force = false end #-------------------------------------------------------------------------- # ● 移動禁止解除 #-------------------------------------------------------------------------- def lift @enable = true end #-------------------------------------------------------------------------- # ● 移動先条件有効化 #-------------------------------------------------------------------------- def enable FieldMap.enable_ev_condition(@map_id, @ev_id, @page) if @page >= 0 self end #-------------------------------------------------------------------------- # ● 移動先条件無効化 #-------------------------------------------------------------------------- def disable FieldMap.disable_ev_condition(@map_id, @ev_id, @page) if @page >= 0 self end end #============================================================================== # ■ FieldMap::RouteInfo : Map上移動ルート情報クラス #============================================================================== class FieldMap::RouteInfo attr_reader :data #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(map_id) @map_id = map_id @data = {} end #-------------------------------------------------------------------------- # ● 移動地点情報参照 #-------------------------------------------------------------------------- def [](r_id) return err_print(r_id) unless include?(r_id) @data[r_id] ||= FieldMap::Route.new(@map_id, r_id) end def err_print(r_id) msgbox_p "不正なルートIDを参照しています(RT未登録) : MAP[#{@map_id}] RT[#{r_id}]", FieldMap::RT[@map_id] nil end #-------------------------------------------------------------------------- # ● ルートIDチェック #-------------------------------------------------------------------------- def include?(r_id) FieldMap.rt_include?(@map_id, r_id) end #-------------------------------------------------------------------------- # ● 新規移動ルート情報抽出 #-------------------------------------------------------------------------- def new_route_rids rt = [] @data.each_pair {|k, v| rt.push(k) if v.new_route and v.enable?} rt end end #============================================================================== # ■ FieldMap::Route : 移動ルート情報クラス #============================================================================== class FieldMap::Route attr_reader :from_ev_id # 移動元イベントID attr_reader :to_ev_id # 移動先イベントID attr_reader :page # 移動ルートイベントページ番号 attr_reader :routes # 移動ルート attr_reader :new_route # 新規移動ルート? attr_reader :acting # 仮想ルート #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(map_id, r_id) @map_id = map_id @route_id = r_id reset end def enable?; @enable; end #-------------------------------------------------------------------------- # ● 移動ルート情報再構築 #-------------------------------------------------------------------------- def reset r = FieldMap.route(@map_id, @route_id) msgbox_p "未設定のルートを参照しています: MAP[#{@map_id}] ID[#{@route_id}]" if r.nil? @enable = r[:enable].nil? ? false : r[:enable] @new_route = r[:enable].nil? ? true : (r[:enable] ? false : true) remake disable_route_condition unless @enable end #-------------------------------------------------------------------------- # ● 移動ルート再構築 #-------------------------------------------------------------------------- def remake r = FieldMap.route(@map_id, @route_id) @from_ev_id = r[:from] @to_ev_id = r[:to] @auto = r[:page].nil? ? true : (r[:page] == 0) @page = r[:page].nil? ? -1 : r[:page] - 1 @acting = r[:acting].nil? ? false : r[:acting] @routes = [] create_route(r[:straight].nil? ? false : r[:straight]) unless @acting end #-------------------------------------------------------------------------- # ● 移動ルートイベントコマンドリスト(原本) #-------------------------------------------------------------------------- def list FieldMap.ev_list(@from_ev_id, @page) end #-------------------------------------------------------------------------- # ● 移動ルート実行 #-------------------------------------------------------------------------- def move_to(target) FieldMap.exec_list([make_command_list(target)]) end #-------------------------------------------------------------------------- # ● 移動ルート生成 #-------------------------------------------------------------------------- def create_route(straight=false) @routes = [] @page < 0 ? auto_route(straight) : calc_route end #-------------------------------------------------------------------------- # ● イベントとの衝突判定 #-------------------------------------------------------------------------- def collide_with_events?(map, x, y) map.events_xy_nt(x, y).any? do |event| event.normal_priority? || self.is_a?(Game_Event) end end #-------------------------------------------------------------------------- # ● 通行可能判定 # d : 方向(2,4,6,8) #-------------------------------------------------------------------------- def passable?(map, x, y, d) x2 = map.round_x_with_direction(x, d) y2 = map.round_y_with_direction(y, d) return false unless map.valid?(x2, y2) # return true if @through || debug_through? return false unless map.passable?(x, y, d) return false unless map.passable?(x2, y2, 10 - d) return false if collide_with_events?(map, x2, y2) return true end #-------------------------------------------------------------------------- # ● 移動可能な方向 #-------------------------------------------------------------------------- def auto_route_start_dir(map, pos, dx, dy, nd=0) # 差が大きい方から詰める dirx = dx > 0 ? 6 : 4 diry = dy > 0 ? 2 : 8 list = dx.abs > dy.abs ? [dirx, diry] : [diry, dirx] list.delete(nd) list.each do |d| return d if passable?(map, pos.x, pos.y, d) end return 0 end #-------------------------------------------------------------------------- # ● 自動ルート計算(直線) #-------------------------------------------------------------------------- def calc_auto_route_straight(map, pos, to) dir = auto_route_start_dir(map, pos, to.x - pos.x, to.y - pos.y) return if dir == 0 until (pos.x == to.x and pos.y == to.y) or dir == 0 @routes.push(pos.move(dir).renew) if ([4, 6].include?(dir) and pos.x == to.x and pos.y != to.y) or ([2, 8].include?(dir) and pos.y == to.y and pos.x != to.x) or !passable?(map, pos.x, pos.y, dir) dir = auto_route_start_dir(map, pos, to.x - pos.x, to.y - pos.y, dir) end end end #-------------------------------------------------------------------------- # ● 自動ルート計算(斜め) #-------------------------------------------------------------------------- def calc_auto_route_slanting(map, pos, to) until (pos.x == to.x and pos.y == to.y) dx = to.x - pos.x dy = to.y - pos.y break if dx == 0 and dy == 0 # 差が大きい方から詰める dirx = dx > 0 ? 6 : 4 diry = dy > 0 ? 2 : 8 list = dx.abs > dy.abs ? [dirx, diry] : [diry, dirx] tmp = pos.dup list.each do |d| if passable?(map, pos.x, pos.y, d) @routes.push(pos.move(d).renew) break end end break if tmp.x == pos.x and tmp.y == pos.y end end #-------------------------------------------------------------------------- # ● 自動ルート計算 #-------------------------------------------------------------------------- def auto_route(straight=false) map = Game_Map.new map.setup(@map_id) map.setup_events from = map.events[@from_ev_id].data to = map.events[@to_ev_id].data pos = FieldMap::FieldPos2.new(from.x, from.y) if FieldMap::ART_STRAIGHT or straight calc_auto_route_straight(map, pos, to) else calc_auto_route_slanting(map, pos, to) end if pos.x != to.x or pos.y != to.y msgbox "自動ルートが確立できません!", "MAP[#{@map_id}] R[#{@route_id}] From[#{@from_ev_id}] To[#{@to_ev_id}]", "from(x:#{from.x}/y:#{from.y}) => x:#{pos.x}/y:#{pos.y}" end @routes.pop # 最後は移動地点or中継地点のため除外 end #-------------------------------------------------------------------------- # ● 移動ルート生成(手動) #-------------------------------------------------------------------------- ROUTE_END = 0 # 移動ルートの終端 ROUTE_MOVE_DOWN = 1 # 下に移動 ROUTE_MOVE_LEFT = 2 # 左に移動 ROUTE_MOVE_RIGHT = 3 # 右に移動 ROUTE_MOVE_UP = 4 # 上に移動 ROUTE_MOVE_LOWER_L = 5 # 左下に移動 ROUTE_MOVE_LOWER_R = 6 # 右下に移動 ROUTE_MOVE_UPPER_L = 7 # 左上に移動 ROUTE_MOVE_UPPER_R = 8 # 右上に移動 ROUTE_TURN_DOWN = 16 # 下を向く ROUTE_CHANGE_SPEED = 29 # 移動速度の変更 def calc_route map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id)) ev = map.events[@from_ev_id] pos = FieldMap::FieldPos2.new(ev.x, ev.y) # 移動ルート設定(プレイヤー)からルートの確定 ev.pages[@page].list.select {|l| l.code == 205 and l.parameters[0] == -1}.each do |c| move_route = c.parameters[1] move_route.list.each do |mv| case mv.code when ROUTE_MOVE_DOWN; @routes.push(pos.d.renew) when ROUTE_MOVE_LEFT; @routes.push(pos.l.renew) when ROUTE_MOVE_RIGHT; @routes.push(pos.r.renew) when ROUTE_MOVE_UP; @routes.push(pos.u.renew) when ROUTE_MOVE_LOWER_L; @routes.push(pos.l.d.renew) when ROUTE_MOVE_LOWER_R; @routes.push(pos.r.d.renew) when ROUTE_MOVE_UPPER_L; @routes.push(pos.l.u.renew) when ROUTE_MOVE_UPPER_R; @routes.push(pos.r.u.renew) end end end @routes.pop # 最後は移動地点or中継地点のため除外 if $TEST to = map.events[@to_ev_id] if to.x != pos.x or to.y != pos.y msgbox_p "error: not arrived(ルート設定ミス!) route:#{@route_id}", "from .. ev[#{@from_ev_id}] x:#{ev.x}/y:#{ev.y}", "to .. ev[#{@to_ev_id}] x:#{to.x}/y:#{to.y}", "calc result .. x:#{pos.x}/y:#{pos.y}" end end end #-------------------------------------------------------------------------- # ● 移動ルートイベント生成 #-------------------------------------------------------------------------- def make_command_list(target) route = target == @to_ev_id ? @routes.dup : @routes.reverse.dup map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id)) from_ev = map.events[(target == @to_ev_id ? @from_ev_id : @to_ev_id )] to_ev = map.events[(target == @to_ev_id ? @to_ev_id : @from_ev_id)] ev = FieldMap::FieldPos2.new(from_ev.x, from_ev.y) route.push(FieldMap::FieldPos2.new(to_ev.x, to_ev.y)) # 移動ルート生成 rt = RPG::MoveRoute.new rt.repeat = false rt.skippable = true rt.wait = true rt.list = [] # 移動速度変更 move_speed = $game_player.move_speed rt.list.push( RPG::MoveCommand.new(ROUTE_CHANGE_SPEED, [FieldMap::SPEED]) ) # 移動コマンド生成 route.each do |r| if ev.x == r.x and ev.y == r.y code = ROUTE_END # 終端 elsif ev.x == r.x and ev.y < r.y code = ROUTE_MOVE_DOWN ev.d elsif ev.x > r.x and ev.y == r.y code = ROUTE_MOVE_LEFT ev.l elsif ev.x < r.x and ev.y == r.y code = ROUTE_MOVE_RIGHT ev.r elsif ev.x == r.x and ev.y > r.y code = ROUTE_MOVE_UP ev.u elsif ev.x > r.x and ev.y < r.y code = ROUTE_MOVE_LOWER_L ev.l.d elsif ev.x < r.x and ev.y < r.y code = ROUTE_MOVE_LOWER_R ev.r.d elsif ev.x > r.x and ev.y > r.y code = ROUTE_MOVE_UPPER_L ev.l.u elsif ev.x < r.x and ev.y > r.y code = ROUTE_MOVE_UPPER_R ev.r.u else code = ROUTE_END # ここには来ない end rt.list.push( RPG::MoveCommand.new(code) ) end if $TEST if ev.x != to_ev.x and ev.y != to_ev.y msgbox_p "移動ルート未到達!" end end rt.list.push( RPG::MoveCommand.new(ROUTE_CHANGE_SPEED, [move_speed]) ) rt.list.push( RPG::MoveCommand.new(ROUTE_TURN_DOWN) ) rt.list.push( RPG::MoveCommand.new(ROUTE_END) ) # list = RPG::EventCommand.new list.code = 205 # 移動ルート list.parameters[0] = -1 # Player list.parameters[1] = rt return list end #-------------------------------------------------------------------------- # ● 移動ルート許可 #-------------------------------------------------------------------------- def enable @enable = true enable_route_condition self end #-------------------------------------------------------------------------- # ● 移動ルート禁止 #-------------------------------------------------------------------------- def disable @enable = false self end #-------------------------------------------------------------------------- # ● 移動ルート条件有効化 #-------------------------------------------------------------------------- def enable_route_condition FieldMap.enable_ev_condition(@map_id, @from_ev_id, @page) if @page >= 0 end #-------------------------------------------------------------------------- # ● 移動ルート条件無効化 #-------------------------------------------------------------------------- def disable_route_condition FieldMap.disable_ev_condition(@map_id, @from_ev_id, @page) if @page >= 0 end #-------------------------------------------------------------------------- # ● 移動地点条件有効化 #-------------------------------------------------------------------------- def enable_place_condition $game_system.field[@map_id].place[@from_ev_id].enable $game_system.field[@map_id].place[@to_ev_id].enable end #-------------------------------------------------------------------------- # ● 移動地点条件有効化 #-------------------------------------------------------------------------- def disable_place_condition $game_system.field[@map_id].place[@from_ev_id].disable $game_system.field[@map_id].place[@to_ev_id].disable end #-------------------------------------------------------------------------- # ● 新規移動ルート開拓 #-------------------------------------------------------------------------- def enable_new_route enable_route_condition enable_place_condition @new_route = false self end end #============================================================================== # ■ FieldMap::FieldRoute : 移動ルート #============================================================================== class FieldMap::FieldRoute attr_reader :map_id attr_reader :current_ev_id attr_reader :start_ev_id attr_reader :target #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(start_map_id, map_id, ev_id, back, dir, fade) @start_map_id = start_map_id @map_id = map_id @current_ev_id = @start_ev_id = ev_id @follower = $game_player.followers.visible backpoint(back, dir, fade) end #-------------------------------------------------------------------------- # ● 復帰ポイント記録 #-------------------------------------------------------------------------- def backpoint(back, dir, fade) x = $game_player.x y = $game_player.y case back # 戻る方向に応じてプレイヤー位置を決める when -1 case d when 2; y -= 1 when 4; x += 1 when 6; y -= 1 when 8; y += 1 end when 1; x -= 1; y += 1 when 2; y += 1; when 3; x += 1; y += 1 when 4; x -= 1 when 6; x += 1 when 7; x -= 1; y -= 1 when 8; y -= 1 when 9; x += 1 end @back = FieldMap::FieldPos.new(x, y, dir, fade) end #-------------------------------------------------------------------------- # ● ルート情報 #-------------------------------------------------------------------------- def route(rid) $game_system.field[@map_id].route[rid] end #-------------------------------------------------------------------------- # ● 移動地点情報 #-------------------------------------------------------------------------- def place(ev_id) $game_system.field[@map_id].place[ev_id] end #-------------------------------------------------------------------------- # ● 初期位置イベント位置へ移動 #-------------------------------------------------------------------------- def move_to_start ev = $game_map.events[@start_ev_id] msgbox_p "移動地点指定ミス! err:ev = #{@start_ev_id} is not found" if ev.nil? $game_player.moveto(ev.x, ev.y) $game_player.set_direction(2) $game_player.followers.visible = false $game_player.refresh end #-------------------------------------------------------------------------- # ● 呼び出し元のマップ? #-------------------------------------------------------------------------- def start_map? @start_ev_id != @current_ev_id end #-------------------------------------------------------------------------- # ● 呼び出し元のマップへ戻る #-------------------------------------------------------------------------- def cancel_map goto_map(@start_map_id, @back) end def goto_map(map_id, info) $game_temp.fade_type = info.fade SceneManager.scene.pre_transfer SceneManager.goto(Scene_Map) $game_map.setup(map_id) SceneManager.scene.from_fieldmap(info, @follower) end #-------------------------------------------------------------------------- # ● 移動先へ移動 #-------------------------------------------------------------------------- def move_to_target(target) r_id = target[:rid] ev_id = target[:target] next_target = target_route_info(ev_id).dup next_target.delete(r_id) # 一本道の中継地点はskipする if FieldMap.tr_include?(@map_id, ev_id) and next_target.size == 1 # 現地点->中継 イベントコマンド ev_cmd = route(r_id).make_command_list(ev_id) cmd = ev_cmd.parameters[1] list = cmd.list 3.times {|t| list.pop} # 速度変更、下向き、endは削除 # 最終移動先EV next_ev = target_ev(ev_id).compact next_ev.delete(@current_ev_id) next_ev_id = next_ev.shift next_r_id = next_target.shift # 中継->移動先 イベントコマンド next_ev_cmd = route(next_r_id).make_command_list(next_ev_id) next_cmd = next_ev_cmd.parameters[1] next_list = next_cmd.list next_list.shift # 速度変更は削除 # 結合 list.concat(next_list) # イベントセットアップ FieldMap.exec_list([ev_cmd]) return next_ev_id else route(target[:rid]).move_to(target[:target]) end return target[:target] end #-------------------------------------------------------------------------- # ● 現在位置が中継地点? #-------------------------------------------------------------------------- def current_is_tr? FieldMap.tr_include?(@map_id, @current_ev_id) end #-------------------------------------------------------------------------- # ● 現位置のマップへ移動可能? #-------------------------------------------------------------------------- def into_map? return false if current_is_tr? place(@current_ev_id).enable? end #-------------------------------------------------------------------------- # ● 現位置のマップへ移動イベント実行 & 位置情報取得 #-------------------------------------------------------------------------- def into_map place(@current_ev_id).into end #-------------------------------------------------------------------------- # ● 移動先へスクロール #-------------------------------------------------------------------------- def scroll_target(target) $game_map.start_event_scroll(target, FieldMap::SCROLL) end #-------------------------------------------------------------------------- # ● スクロールのリセット #-------------------------------------------------------------------------- def reset_scroll $game_map.start_player_scroll(FieldMap::SCROLL) end #-------------------------------------------------------------------------- # ● 移動ルート情報 #-------------------------------------------------------------------------- def route_info $game_system.field[@map_id].route.data end #-------------------------------------------------------------------------- # ● 中継地点情報 #-------------------------------------------------------------------------- def place_info l = {:ev=>[], :route=>@route} tr = FieldMap::TR[@map_id] return {} if tr.nil? tr.each do |id| l[:ev].push(id) if place(id).enable? end l end #-------------------------------------------------------------------------- # ● 移動ルート情報追加 #-------------------------------------------------------------------------- def add_route(ev_id, r_id) @route[ev_id] ||= [] @route[ev_id].push(r_id) unless @route[ev_id].include?(r_id) return route(r_id).reset if FieldMap::RESET_ROUTE return route(r_id).remake if FieldMap::REMAKE_ROUTE end #-------------------------------------------------------------------------- # ● 移動ルート情報生成(新規ルート以外) #-------------------------------------------------------------------------- def create_route @route = {} $game_map.events.each_pair do |id, ev| next unless FieldMap.check_ev(@map_id, id) rt = FieldMap::RT[@map_id] next if rt.nil? rt.each_pair do |rid, v| if v[:from] == id or v[:to] == id add_route(id, rid) if route(rid).enable? and !route(rid).new_route end end end end #-------------------------------------------------------------------------- # ● 指定位置からの移動ルート情報 #-------------------------------------------------------------------------- def ev_route_info(ev_id) @route[ev_id] end #-------------------------------------------------------------------------- # ● 現在位置からの移動ルート情報 #-------------------------------------------------------------------------- def current_route_info ev_route_info(current_ev_id) end #-------------------------------------------------------------------------- # ● 移動先からの移動ルート情報 #-------------------------------------------------------------------------- def target_route_info(target) ev_route_info(target) end #-------------------------------------------------------------------------- # ● 近隣ルート抽出 #-------------------------------------------------------------------------- def sort_new_route(rt, ev_id) rt[:org].each do |r| d = route(r) if d.from_ev_id == ev_id or d.to_ev_id == ev_id or d.acting rt[:res].push(r) rt[:org].delete(r) add_route(d.from_ev_id, r) add_route(d.to_ev_id, r) end end rt end #-------------------------------------------------------------------------- # ● 新規移動ルート生成(現在位置からのルート抽出まで実施) #-------------------------------------------------------------------------- RETRY = 10 def new_route_rids rt = {:org=>$game_system.field[@map_id].route.new_route_rids, :res=>[]} try = 0 while !rt[:org].empty? try += 1 targets = [@current_ev_id] searched = [] while !targets.empty? and !rt[:org].empty? targets.each {|t| rt = sort_new_route(rt, t)} unless rt[:org].empty? searched.concat(targets) targets = [] searched.each {|t| targets.concat(target_ev(t))} targets.uniq! searched.each {|t| targets.delete(t)} end end end rt[:res] end #-------------------------------------------------------------------------- # ● 新規移動ルート情報有効化 #-------------------------------------------------------------------------- def create_new_route(r) route(r).enable_new_route end #-------------------------------------------------------------------------- # ● 指定位置からの行き先EVリスト #-------------------------------------------------------------------------- def target_ev(ev_id) return [] if @route[ev_id].nil? list = [] @route[ev_id].each do |rid| rt = route(rid) list.push(rt.to_ev_id) if rt.from_ev_id == ev_id list.push(rt.from_ev_id) if rt.to_ev_id == ev_id end list end #-------------------------------------------------------------------------- # ● 現在位置からの行き先EVリスト #-------------------------------------------------------------------------- def target_ev_from_current target_ev(@current_ev_id) end #-------------------------------------------------------------------------- # ● 現在位置のマップID取得 #-------------------------------------------------------------------------- def target_map(ev_id) place(ev_id).target_map_id end #-------------------------------------------------------------------------- # ● 現在位置のマップID取得 #-------------------------------------------------------------------------- def current_map_id target_map(@current_ev_id) end #-------------------------------------------------------------------------- # ● 現在位置からの移動先マップリスト #-------------------------------------------------------------------------- def target_dir_maps(dir) return [] if @target[dir].nil? ev_id = @target[dir][:target] maps = [] if FieldMap.tr_include?(@map_id, ev_id) # 移動先が中継地点の場合、現位置を除く移動ルート取得 targets = target_ev(ev_id).compact targets.delete(@current_ev_id) # 中継地点先のマップID集計 targets.each {|t_id| maps.push(target_map(t_id))} elsif ev_id != nil # 移動先マップID集計 maps.push(target_map(ev_id)) end return maps end #-------------------------------------------------------------------------- # ● 現在位置設定 #-------------------------------------------------------------------------- def set_current_ev_id(ev_id) @current_ev_id = ev_id create_current_route end #-------------------------------------------------------------------------- # ● 現在位置からの移動ルート情報 #-------------------------------------------------------------------------- def create_current_route @target = create_target_route(@current_ev_id) end #-------------------------------------------------------------------------- # ● 移動ルート情報生成 #-------------------------------------------------------------------------- def create_target_route(ev_id) ev = $game_map.events[ev_id] return [] if ev.nil? pos = FieldMap::FieldPos2.new(ev.x, ev.y) return [] if FieldMap::RT[@map_id].nil? target = [] FieldMap::RT[@map_id].each_key do |rid| rt = route(rid) next unless rt.enable? next if rt.new_route if rt.from_ev_id == ev_id next_pos = rt.routes[0] target_ev = rt.to_ev_id elsif rt.to_ev_id == ev_id next_pos = rt.routes[rt.routes.size - 1] target_ev = rt.from_ev_id else next end tgt = {:rid => rid, :target => target_ev} if pos.x == next_pos.x and (pos.y + 1) == next_pos.y target[2] = tgt # 下 elsif pos.x == next_pos.x and (pos.y - 1) == next_pos.y target[8] = tgt # 上 elsif (pos.x - 1) == next_pos.x and pos.y == next_pos.y target[4] = tgt # 左 elsif (pos.x + 1) == next_pos.x and pos.y == next_pos.y target[6] = tgt # 右 elsif (pos.x - 1) == next_pos.x and (pos.y - 1) == next_pos.y target[1] = tgt # 左下 elsif (pos.x + 1) == next_pos.x and (pos.y - 1) == next_pos.y target[3] = tgt # 右下 elsif (pos.x - 1) == next_pos.x and (pos.y + 1) == next_pos.y target[7] = tgt # 左上 elsif (pos.x + 1) == next_pos.x and (pos.y + 1) == next_pos.y target[9] = tgt # 右上 end end return target end end