diff --git a/Data/HCGframes/event/EndingShip_begin.rb b/Data/HCGframes/event/EndingShip_begin.rb index 0cdb88a..89aeb3f 100644 --- a/Data/HCGframes/event/EndingShip_begin.rb +++ b/Data/HCGframes/event/EndingShip_begin.rb @@ -1,4 +1,11 @@ +if defined?(MPIslandVoyage) && MPIslandVoyage.transit? + $game_player.opacity = 255 + chcg_background_color(0,0,0,0,0) + map_background_color(0,0,0,0,0) + return +end + $game_switches.data_common_event[:default] = false #turn off all GMI and HOM update $game_switches.data_common_event[:AutoCommon] = false map_background_color(0,0,0,255,0) diff --git a/Data/HCGframes/event/NoerDockBroker.rb b/Data/HCGframes/event/NoerDockBroker.rb index 874a2b5..4b3e776 100644 --- a/Data/HCGframes/event/NoerDockBroker.rb +++ b/Data/HCGframes/event/NoerDockBroker.rb @@ -5,6 +5,11 @@ if $game_map.threat return end +# Online passage uses the ship map without the single-player ending. +if defined?(MPIslandVoyage) && MPIslandVoyage.online? + return MPIslandVoyage.edward_menu(self) +end + diff --git a/Data/Scripts/Editables/33_Functions_OverMapEvents.rb b/Data/Scripts/Editables/33_Functions_OverMapEvents.rb index 312d7ee..fc81291 100644 --- a/Data/Scripts/Editables/33_Functions_OverMapEvents.rb +++ b/Data/Scripts/Editables/33_Functions_OverMapEvents.rb @@ -25,6 +25,9 @@ def overmap_gen_WildDangerous end def overmap_event_EnterMap(customData=nil) + if defined?(MPIslandVoyage) && MPIslandVoyage.exit_tile? + return MPIslandVoyage.exit_menu(self) + end #overmap_roll_capturedXY #TODO 環境危險係數 RAND一個基本變數 當環境危險係數高於基本變數時 且玩家處於 REGION MAP 則NAP後出現敵人 #TODO 基本變數為玩家的3*SURVIVAL+RAND(100)基本變數 diff --git a/ModScripts/9999999999999999999999_IBRUIsland.rb b/ModScripts/9999999999999999999999_IBRUIsland.rb new file mode 100644 index 0000000..7d72fa2 --- /dev/null +++ b/ModScripts/9999999999999999999999_IBRUIsland.rb @@ -0,0 +1,453 @@ +# encoding: UTF-8 +# The IBRU_VIZ island is an online, server-authorized temporary mode. +module MPIslandVoyage + SHEET = '-char-M-REGULAR04' + INDEX = 2 + @active = false + @noclip = false + @targets = {} + + def self.online? + defined?(WebSocket) && WebSocket.connected? + rescue + false + end + + def self.active? + online? && !!@active + end + + def self.transit? + !!@transit_runtime || ($story_stats && $story_stats['IBRU_Transit'].to_i == 1) + rescue + false + end + + def self.mark_transit + @transit_runtime = true + $story_stats['IBRU_Transit'] = 1 if $story_stats + end + + def self.exit_tile? + online? && $game_map && $game_map.map_id == 2 && $game_player && + $game_player.x == 101 && $game_player.y == 106 + rescue + false + end + + def self.edward_menu(interpreter) + interpreter.call_msg('\\CBid[-1,2]\\SETpl[Mfat_DockCaptain]\\c[4]Эдвард:\\C[0] Куда направимся? \\optB[Отмена,Остров IBRU_VIZ]') + choice = $game_temp.choice + $game_temp.choice = -1 + board('out') if choice == 1 + end + + def self.exit_menu(interpreter) + interpreter.call_msg('\\CBid[-1,2]\\SETpl[Mfat_DockCaptain]\\c[4]Эдвард:\\C[0] Отплываем? \\optB[Отмена,Уплыть]') + choice = $game_temp.choice + $game_temp.choice = -1 + board('back') if choice == 1 + end + + def self.board(direction) + return unless online? + @ship_ready_at = nil + if $story_stats + if direction == 'out' + $story_stats['IBRU_ReturnOverX'] = $story_stats['LastOverMapX'] + $story_stats['IBRU_ReturnOverY'] = $story_stats['LastOverMapY'] + end + end + mark_transit + WebSocket.send_line("ibru_board:#{direction}") + end + + def self.arrived(direction) + @arrival = [direction, direction == 'out' ? 2 : 14] + end + + def self.tick + unless online? + set_active(false) if @active + return + end + if WebSocket.respond_to?(:bootstrap_sync_unlocked?) && WebSocket.bootstrap_sync_unlocked? && + (!@hello_at || Time.now.to_f - @hello_at > 5) + @hello_at = Time.now.to_f + WebSocket.send_line('ibru_hello') + end + if transit? && $game_map && $game_map.map_id == 156 && + (!@ship_ready_at || Time.now.to_f - @ship_ready_at > 10) + @ship_ready_at = Time.now.to_f + WebSocket.send_line('ibru_ship_ready') + end + if @arrival && $game_map && $game_map.map_id == @arrival[1] && $game_message && !$game_message.busy? + if $story_stats + if @arrival[0] == 'out' + $story_stats['LastOverMapX'] = 101 + $story_stats['LastOverMapY'] = 106 + $story_stats['OverMapID'] = 2 + else + x = $story_stats['IBRU_ReturnOverX'].to_i + y = $story_stats['IBRU_ReturnOverY'].to_i + $story_stats['LastOverMapX'] = x if x > 0 + $story_stats['LastOverMapY'] = y if y > 0 + $story_stats.delete('IBRU_ReturnOverX') if $story_stats.respond_to?(:delete) + $story_stats.delete('IBRU_ReturnOverY') if $story_stats.respond_to?(:delete) + end + $story_stats['IBRU_Transit'] = 0 + end + @transit_runtime = false + @ship_ready_at = nil + $game_message.background = 0 + $game_message.position = 2 + $game_message.add('\\CBid[-1,2]\\SETpl[Mfat_DockCaptain]\\c[4]Эдвард:\\C[0] Приплыли.') + @arrival = nil + end + if active? && (!@skin_applied || ($game_player && + ($game_player.instance_variable_get(:@chs_type).to_s != SHEET || + $game_player.charset_index.to_i != INDEX))) + apply_skin + end + rescue => e + puts("[IBRU] tick: #{e.class}: #{e.message}") rescue nil + end + + def self.set_active(value) + value = !!value + return if @active == value + @active = value + unless value + @noclip = false + @targets = {} + MPGodMode.reset if defined?(MPGodMode) + restore_skin + if defined?(WebSocket) + WebSocket.instance_variable_set(:@admin_ghost_enabled, false) + WebSocket.instance_variable_set(:@admin_see_hidden_enabled, false) + WebSocket.instance_variable_set(:@ninja_local_last_active, nil) + end + end + end + + def self.noclip? + active? && !!@noclip + end + + def self.set_noclip(value) + @noclip = !!value + end + + def self.targets + @targets || {} + end + + def self.set_targets(value) + @targets = value + end + + def self.apply_skin + return unless active? && $game_player && defined?(WebSocket) + return unless WebSocket.respond_to?(:mp_male_apply_specific_skin) + @previous_male ||= [WebSocket.mp_male_skin_active?, + ($story_stats[WebSocket::MP_MALE_CHS_KEY].to_s rescue ''), + ($story_stats[WebSocket::MP_MALE_CHS_IDX_KEY].to_i rescue 0)] + WebSocket.mp_male_set_flag(1) + @skin_applied = WebSocket.mp_male_apply_specific_skin(SHEET, INDEX) + rescue => e + puts("[IBRU] skin: #{e.class}: #{e.message}") rescue nil + end + + def self.restore_skin + return unless @skin_applied && defined?(WebSocket) + previous = @previous_male + if previous && previous[0] && previous[1] != '' + WebSocket.mp_male_apply_specific_skin(previous[1], previous[2]) + else + WebSocket.mp_male_set_flag(0) + WebSocket.mp_male_restore_lona_skin + end + ensure + @skin_applied = false + @previous_male = nil + end +end + +if defined?(Game_Player) + class Game_Player + alias ibru_movable_without movable? + def movable?(*args, &block) + return false if MPIslandVoyage.transit? && $game_map && $game_map.map_id == 156 + ibru_movable_without(*args, &block) + end + end +end + +if defined?(WebSocket) + module WebSocket + class << self + alias ibru_parse_without parse + def parse(message) + # The server uses a distinct room ID for island interiors. Only the + # transport layer sees it; the game loads the original map data. + if message =~ /\Abootstrap_map:(10\d{3})\z/ + MPIslandVoyage.mark_transit if $1.to_i == 10_156 + message = "bootstrap_map:#{$1.to_i - 10_000}" + elsif message =~ /\Abootstrap_state:(10\d{3}):(.*)\z/m + message = "bootstrap_state:#{$1.to_i - 10_000}:#{$2}" + elsif message =~ /\Apvp_force_spawn:(10\d{3}):(.*)\z/m + message = "pvp_force_spawn:#{$1.to_i - 10_000}:#{$2}" + end + case message + when /\Aibru_state:([01])\z/ + MPIslandVoyage.set_active($1 == '1') + return + when /\Aibru_noclip_state:([01])\z/ + MPIslandVoyage.set_noclip($1 == '1') + return + when /\Aibru_arrived:(out|back)\z/ + MPIslandVoyage.arrived($1) + return + when /\Aibru_board_reject\z/ + $story_stats['IBRU_Transit'] = 0 if $story_stats + MPIslandVoyage.instance_variable_set(:@transit_runtime, false) + MPIslandVoyage.instance_variable_set(:@ship_ready_at, nil) + chat_local_system('Эдвард: переправа сейчас недоступна.') if respond_to?(:chat_local_system) + return + when /\Aibru_targets:(.*)\z/ + list = {} + $1.split('|').each do |entry| + id, name = entry.split(':', 2) + list[id.to_i] = unesc(name) if id.to_i > 0 && name + end + MPIslandVoyage.set_targets(list) + return + end + ibru_parse_without(message) + end + + alias ibru_noclip_without admin_noclip_enabled? + def admin_noclip_enabled? + MPIslandVoyage.noclip? || ibru_noclip_without + end + + alias ibru_hidden_without admin_see_hidden_enabled? + def admin_see_hidden_enabled? + (MPIslandVoyage.active? && !!@admin_see_hidden_enabled) || ibru_hidden_without + end + + alias ibru_ghost_without admin_can_ghost? + def admin_can_ghost? + MPIslandVoyage.active? || ibru_ghost_without + end + end + end +end + +if defined?(MPGodMode) + module MPGodMode + class << self + alias ibru_active_without active? + def active? + return !!@enabled && MPIslandVoyage.active? && Time.now.to_f < @expires.to_f if MPIslandVoyage.active? + ibru_active_without + end + alias ibru_toggle_without request_toggle + def request_toggle + return ibru_toggle_without unless MPIslandVoyage.active? + return if pending? || !WebSocket.connected? + @pending_at = Time.now.to_f + WebSocket.send_line("god_toggle:#{active? ? 0 : 1}") + refresh_menu + end + alias ibru_tick_without tick + def tick + ibru_tick_without + if MPIslandVoyage.active? && WebSocket.bootstrap_sync_unlocked? && (!@ibru_hello_at || Time.now.to_f - @ibru_hello_at > 10) + @ibru_hello_at = Time.now.to_f + WebSocket.send_line('god_hello:1') + end + end + end + end +end + +if defined?(Scene_Map) + class Scene_Map + alias ibru_update_without update + def update(*args, &block) + result = ibru_update_without(*args, &block) + MPIslandVoyage.tick + result + end + end +end + +# Keep the island tools in the existing VIP overlay, without granting OWNER. +if defined?(Scene_Map) && Scene_Map.method_defined?(:mp_admin_open_root) + class Scene_Map + alias ibru_hotkey_without mp_admin_update_hotkey + def mp_admin_update_hotkey + return ibru_hotkey_without unless MPIslandVoyage.active? && WebSocket.admin_role_rank <= 0 + return if MPAdminMenu.blocked_by_other_ui? || !MPAdminMenu.open_triggered? + mp_admin_menu_active? ? mp_admin_dispose_menu : mp_admin_open_root + end + + alias ibru_validate_role_without mp_admin_validate_menu_role + def mp_admin_validate_menu_role + return if MPIslandVoyage.active? && WebSocket.connected? + ibru_validate_role_without + end + + alias ibru_admin_root_without mp_admin_open_root + def mp_admin_open_root + return ibru_admin_root_without unless MPIslandVoyage.active? + rows = [] + rows << [MPAdminMenu::ROOT_STYLE_TEXT, :style_root, true, nil] if WebSocket.admin_can_style? + rows << [MPAdminMenu::ROOT_EMOJI_TEXT, :emoji_root, true, nil] if WebSocket.admin_can_style? + rows << ["Noclip: #{MPIslandVoyage.noclip? ? 'ВКЛ' : 'ВЫКЛ'}", :ibru_noclip, true, nil] + rows << [MPAdminMenu.see_hidden_label, :ibru_hidden, true, nil] + rows << [MPAdminMenu.ghost_label, :ibru_ghost, true, nil] + rows << ['Телепортироваться к игроку на острове', :ibru_teleport, true, nil] + rows << [MPGodMode.label, :ibru_god, !MPGodMode.pending?, nil] if defined?(MPGodMode) + mp_admin_show_commands(rows, :root, 360) + @mp_admin_window.set_handler(:style_root, method(:mp_admin_open_style_menu)) + @mp_admin_window.set_handler(:emoji_root, method(:mp_admin_open_emoji_side_menu)) + @mp_admin_window.set_handler(:ibru_noclip, method(:ibru_toggle_noclip)) + @mp_admin_window.set_handler(:ibru_hidden, method(:ibru_toggle_hidden)) + @mp_admin_window.set_handler(:ibru_ghost, method(:ibru_toggle_ghost)) + @mp_admin_window.set_handler(:ibru_teleport, method(:ibru_open_targets)) + @mp_admin_window.set_handler(:ibru_god, method(:ibru_toggle_god)) if defined?(MPGodMode) + @mp_admin_window.set_handler(:cancel, method(:mp_admin_dispose_menu)) + end + + alias ibru_admin_back_without mp_admin_back + def mp_admin_back + return mp_admin_open_root if @mp_admin_state == :ibru_targets + ibru_admin_back_without + end + + def ibru_toggle_noclip + WebSocket.send_line('ibru_noclip_toggle') if MPIslandVoyage.active? + mp_admin_open_root + end + + def ibru_toggle_hidden + if MPIslandVoyage.active? + current = WebSocket.instance_variable_get(:@admin_see_hidden_enabled) + WebSocket.instance_variable_set(:@admin_see_hidden_enabled, !current) + end + mp_admin_open_root + end + + def ibru_toggle_ghost + WebSocket.admin_toggle_ghost if MPIslandVoyage.active? + mp_admin_open_root + end + + def ibru_toggle_god + MPGodMode.request_toggle if MPIslandVoyage.active? + mp_admin_open_root + end + + def ibru_open_targets + return mp_admin_open_root unless MPIslandVoyage.active? + WebSocket.send_line('ibru_targets_req') + rows = MPIslandVoyage.targets.map { |id, nick| [nick, :ibru_target, true, id] } + rows = [['На острове нет других игроков', :noop, false, nil]] if rows.empty? + mp_admin_show_commands(rows, :ibru_targets, 360) + @mp_admin_window.set_handler(:ibru_target, method(:ibru_teleport_target)) + @mp_admin_window.set_handler(:cancel, method(:mp_admin_open_root)) + end + + def ibru_teleport_target + if MPIslandVoyage.active? && @mp_admin_window + WebSocket.send_line("ibru_tp_to:#{@mp_admin_window.current_ext.to_i}") + end + mp_admin_dispose_menu + end + end +end + +if defined?(MPAdminMenu) + module MPAdminMenu + class << self + alias ibru_grid_title_without grid_title + def grid_title(state) + return 'Остров IBRU_VIZ' if state == :root && MPIslandVoyage.active? + ibru_grid_title_without(state) + end + end + end +end + +# Gray the item entry and block both keyboard and mouse access to its page. +if defined?(Menu_Command) + class Menu_Command + alias ibru_menu_initialize_without initialize + def initialize(command_names) + @ibru_item_index = command_names.index($game_text['menu:core/items']) rescue nil + ibru_menu_initialize_without(command_names) + end + alias ibru_menu_refresh_without refresh + def refresh + ibru_menu_refresh_without + if MPIslandVoyage.active? && @ibru_item_index && @menu_sprites[@ibru_item_index] + @menu_sprites[@ibru_item_index].opacity = 65 + end + end + end +end + +if defined?(Scene_Menu) + class Scene_Menu + alias ibru_menu_start_without start + def start(*args, &block) + result = ibru_menu_start_without(*args, &block) + if MPIslandVoyage.active? && @contents && @contents.contents[@menu_index].is_a?(Menu_Items) + ibru_menu_switch_without(0) + end + result + end + alias ibru_menu_switch_without process_switchMenuIndex + def process_switchMenuIndex(index) + if MPIslandVoyage.active? && @contents && @contents.contents[index].is_a?(Menu_Items) + direction = index.to_i >= @menu_index.to_i ? 1 : -1 + skip = index.to_i + direction + return if skip < 0 || skip >= @contents.contents.size + index = skip + end + ibru_menu_switch_without(index) + end + alias ibru_menu_ok_without process_ok + def process_ok + return SndLib.sys_buzzer if MPIslandVoyage.active? && @contents && @contents.contents[@menu_index].is_a?(Menu_Items) + ibru_menu_ok_without + end + end +end + +# Local NPC combat is client simulated; suppress its damage before the server +# relay as well, so an island owner cannot hurt either NPCs or players. +if defined?(Battle_System) + module IbruIslandNoDamage + def take_damage(user, *args, &block) + return [] if MPIslandVoyage.active? && $game_player && user.equal?($game_player.actor) + super + end + def apply_skill_state_effect(skill, user, *args, &block) + return if MPIslandVoyage.active? && $game_player && user.equal?($game_player.actor) + super + end + end + Battle_System.prepend(IbruIslandNoDamage) +end +if defined?(Game_SandboxObject) + class Game_SandboxObject + alias ibru_sandbox_damage_without take_damage + def take_damage(user, *args, &block) + return [] if MPIslandVoyage.active? && $game_player && user.equal?($game_player.actor) + ibru_sandbox_damage_without(user, *args, &block) + end + end +end