1802 lines
58 KiB
Ruby
1802 lines
58 KiB
Ruby
# encoding: UTF-8
|
|||
|
|
#==============================================================================
|
||
|
|
# 100008_CorpseRecovery.rb
|
||
|
|
# CorpseRecovery 1.1.3 client bridge for LonaRPG Online.
|
||
|
|
#
|
||
|
|
# - Sends a protected pre-respawn corpse snapshot on Scene_Gameover.
|
||
|
|
# - Shows corpse marker with the same VIP emoji renderer (☠) + real-time timer.
|
||
|
|
# - Owner can press C near the corpse to restore the saved character state.
|
||
|
|
# - After 15 protected minutes other players can loot only additive equipment,
|
||
|
|
# items and physical coins; their character/quest state is never replaced.
|
||
|
|
# - Map002 shows the same skull at the entrance of the corpse's interior map.
|
||
|
|
# - Death respawn goes to NoerSewer. New accounts are directed to TutorialOP
|
||
|
|
# by the server plugin through bootstrap_map/bootstrap_pos.
|
||
|
|
#==============================================================================
|
||
|
|
|
||
|
|
begin
|
||
|
|
require 'base64'
|
||
|
|
rescue LoadError
|
||
|
|
end
|
||
|
|
|
||
|
|
module MPCorpseRecovery
|
||
|
|
SKULL = "💀"
|
||
|
|
MARKER_WIDTH = 118
|
||
|
|
MARKER_HEIGHT = 30
|
||
|
|
TOP_HUD_WIDTH = 58
|
||
|
|
TOP_HUD_HEIGHT = 24
|
||
|
|
TOP_HUD_Y = 6
|
||
|
|
DEATH_ACK_WAIT_FRAMES = 240
|
||
|
|
MAX_WIRE_CHARS = 240_000
|
||
|
|
MAX_BODY_CHARS = 90_000
|
||
|
|
OVERMAP_MAP_ID = 2
|
||
|
|
TUTORIAL_MAP_ID = 139
|
||
|
|
TUTORIAL_X = 0
|
||
|
|
TUTORIAL_Y = 0
|
||
|
|
TUTORIAL_DIRECTION = 2
|
||
|
|
|
||
|
|
@corpses = {}
|
||
|
|
@death_pending = false
|
||
|
|
@death_deadline_frame = 0
|
||
|
|
@death_corpse_id = nil
|
||
|
|
@restore_pending_id = nil
|
||
|
|
@restore_save_pending_id = nil
|
||
|
|
@restore_save_next_retry_frame = 0
|
||
|
|
@restore_save_attempts = 0
|
||
|
|
@public_loot_pending_id = nil
|
||
|
|
@public_loot_save_pending_id = nil
|
||
|
|
@public_loot_save_next_retry_frame = 0
|
||
|
|
@public_loot_save_attempts = 0
|
||
|
|
@public_loot_applied = {}
|
||
|
|
@restore_loot_applied = {}
|
||
|
|
@last_claim_at = 0.0
|
||
|
|
@new_registration_tutorial = false
|
||
|
|
@new_registration_tutorial_consumed = false
|
||
|
|
@post_death_reset_save = false
|
||
|
|
@tutorial_initial_save = false
|
||
|
|
@server_clock_server_ms = 0
|
||
|
|
@server_clock_local_ms = 0
|
||
|
|
|
||
|
|
module_function
|
||
|
|
|
||
|
|
def now_ms
|
||
|
|
(Time.now.to_f * 1000.0).to_i
|
||
|
|
rescue
|
||
|
|
0
|
||
|
|
end
|
||
|
|
|
||
|
|
# Monotonic clock is used only to animate the visible countdown. The server
|
||
|
|
# remains authoritative for expiration. A server timestamp received with each
|
||
|
|
# corpse packet calibrates this clock, so different PC wall clocks do not
|
||
|
|
# skew the HUD timer.
|
||
|
|
def monotonic_ms
|
||
|
|
begin
|
||
|
|
if defined?(Process) && Process.respond_to?(:clock_gettime) && defined?(Process::CLOCK_MONOTONIC)
|
||
|
|
return (Process.clock_gettime(Process::CLOCK_MONOTONIC).to_f * 1000.0).to_i
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
now_ms
|
||
|
|
rescue
|
||
|
|
now_ms
|
||
|
|
end
|
||
|
|
|
||
|
|
def calibrate_server_clock(server_now_ms)
|
||
|
|
value = server_now_ms.to_i
|
||
|
|
return false if value <= 0
|
||
|
|
@server_clock_server_ms = value
|
||
|
|
@server_clock_local_ms = monotonic_ms
|
||
|
|
true
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def display_server_now_ms
|
||
|
|
base = @server_clock_server_ms.to_i
|
||
|
|
local = @server_clock_local_ms.to_i
|
||
|
|
return now_ms if base <= 0 || local <= 0
|
||
|
|
base + [monotonic_ms - local, 0].max
|
||
|
|
rescue
|
||
|
|
now_ms
|
||
|
|
end
|
||
|
|
|
||
|
|
def frame_now
|
||
|
|
Graphics.frame_count.to_i
|
||
|
|
rescue
|
||
|
|
0
|
||
|
|
end
|
||
|
|
|
||
|
|
def connected?
|
||
|
|
defined?(WebSocket) && WebSocket.respond_to?(:connected?) && WebSocket.connected?
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def notify(text, type=:info)
|
||
|
|
begin
|
||
|
|
if defined?(System_NotificationOverlay)
|
||
|
|
if type == :error && System_NotificationOverlay.respond_to?(:error)
|
||
|
|
System_NotificationOverlay.error(text.to_s)
|
||
|
|
return
|
||
|
|
elsif type == :success && System_NotificationOverlay.respond_to?(:success)
|
||
|
|
System_NotificationOverlay.success(text.to_s)
|
||
|
|
return
|
||
|
|
elsif System_NotificationOverlay.respond_to?(:notify)
|
||
|
|
System_NotificationOverlay.notify(text.to_s, type)
|
||
|
|
return
|
||
|
|
end
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
puts "[CORPSE] #{text}" rescue nil
|
||
|
|
end
|
||
|
|
|
||
|
|
def current_map_id
|
||
|
|
($game_map && $game_map.map_id.to_i) rescue 0
|
||
|
|
end
|
||
|
|
|
||
|
|
# LastOverMapX/Y are written immediately before the base game enters a tag or
|
||
|
|
# region map. Send that entrance tile with the protected death snapshot so the
|
||
|
|
# server can persist it and Map002 can point at an indoor/sub-map corpse.
|
||
|
|
def capture_death_overmap_origin(death_map_id, death_x, death_y)
|
||
|
|
if death_map_id.to_i == OVERMAP_MAP_ID
|
||
|
|
return {
|
||
|
|
"map_id" => OVERMAP_MAP_ID,
|
||
|
|
"x" => death_x.to_i,
|
||
|
|
"y" => death_y.to_i
|
||
|
|
}
|
||
|
|
end
|
||
|
|
|
||
|
|
story = nil
|
||
|
|
begin
|
||
|
|
story = $story_stats if defined?($story_stats)
|
||
|
|
rescue
|
||
|
|
story = nil
|
||
|
|
end
|
||
|
|
return nil if story.nil? || !story.respond_to?(:[])
|
||
|
|
return nil unless story["OverMapID"].to_i == OVERMAP_MAP_ID
|
||
|
|
|
||
|
|
x = story["LastOverMapX"].to_i
|
||
|
|
y = story["LastOverMapY"].to_i
|
||
|
|
return nil if x < 0 || y < 0
|
||
|
|
{ "map_id" => OVERMAP_MAP_ID, "x" => x, "y" => y }
|
||
|
|
rescue
|
||
|
|
nil
|
||
|
|
end
|
||
|
|
|
||
|
|
# Build a corpse body blob that prioritizes quest/mission progress.
|
||
|
|
# Normal live-sync already includes quest keys in body.story_stats, but the
|
||
|
|
# corpse path must never silently drop them just because the wider body blob
|
||
|
|
# grew large. If the full body cannot fit, fall back to a quest-only body.
|
||
|
|
def collect_quest_story_state
|
||
|
|
out = {}
|
||
|
|
story = nil
|
||
|
|
begin
|
||
|
|
story = $story_stats if defined?($story_stats)
|
||
|
|
rescue
|
||
|
|
story = nil
|
||
|
|
end
|
||
|
|
return out if story.nil?
|
||
|
|
source = nil
|
||
|
|
begin
|
||
|
|
source = story.data if story.respond_to?(:data)
|
||
|
|
rescue
|
||
|
|
source = nil
|
||
|
|
end
|
||
|
|
source = story if !source.is_a?(Hash) && story.is_a?(Hash)
|
||
|
|
return out unless source && source.respond_to?(:each)
|
||
|
|
|
||
|
|
source.each do |raw_key, raw_value|
|
||
|
|
key = raw_key.to_s
|
||
|
|
next if key.empty?
|
||
|
|
is_quest = false
|
||
|
|
begin
|
||
|
|
is_quest = MPQuestCloudState.quest_key?(key) if defined?(MPQuestCloudState) && MPQuestCloudState.respond_to?(:quest_key?)
|
||
|
|
rescue
|
||
|
|
is_quest = false
|
||
|
|
end
|
||
|
|
next unless is_quest
|
||
|
|
value = raw_value
|
||
|
|
begin
|
||
|
|
if WebSocket.respond_to?(:_live_sync_body_safe_value)
|
||
|
|
value = WebSocket._live_sync_body_safe_value(raw_value)
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
value = raw_value
|
||
|
|
end
|
||
|
|
out[key] = value unless value.nil?
|
||
|
|
break if out.length >= 4096
|
||
|
|
end
|
||
|
|
out
|
||
|
|
rescue
|
||
|
|
{}
|
||
|
|
end
|
||
|
|
|
||
|
|
def pack_body_object(obj, label)
|
||
|
|
return "" unless obj.is_a?(Hash)
|
||
|
|
begin
|
||
|
|
if WebSocket.respond_to?(:_live_sync_blob_from_object)
|
||
|
|
return WebSocket._live_sync_blob_from_object(obj, MAX_BODY_CHARS, label.to_s).to_s
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
""
|
||
|
|
end
|
||
|
|
|
||
|
|
def quest_only_body_blob
|
||
|
|
quests = collect_quest_story_state
|
||
|
|
return "" if quests.empty?
|
||
|
|
pack_body_object({ "schema" => 3, "story_stats" => quests }, "corpse_quests")
|
||
|
|
rescue
|
||
|
|
""
|
||
|
|
end
|
||
|
|
|
||
|
|
def prioritized_body_blob(actor, original_blob)
|
||
|
|
original = original_blob.to_s
|
||
|
|
return original if !original.empty? && original.length <= MAX_BODY_CHARS
|
||
|
|
|
||
|
|
begin
|
||
|
|
if WebSocket.respond_to?(:_live_sync_collect_body)
|
||
|
|
full = WebSocket._live_sync_collect_body(actor)
|
||
|
|
packed = pack_body_object(full, "corpse_body")
|
||
|
|
return packed unless packed.empty?
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
quest_only_body_blob
|
||
|
|
rescue
|
||
|
|
quest_only_body_blob
|
||
|
|
end
|
||
|
|
|
||
|
|
# Survival resources are deliberately NOT part of corpse recovery. The
|
||
|
|
# corpse contains death-time values (usually health/STA close to zero), but
|
||
|
|
# picking it up must keep the resources of the CURRENT living character.
|
||
|
|
#
|
||
|
|
# Lona has two different health values: RGSS actor.hp and Lona's own
|
||
|
|
# actor.health stored in @actStat. The HUD/gameplay uses actor.health, so both
|
||
|
|
# must be protected. STA and satiety live in @actStat as well.
|
||
|
|
def active_local_actor
|
||
|
|
actor = nil
|
||
|
|
begin
|
||
|
|
actor = $game_player.actor if defined?($game_player) && $game_player && $game_player.respond_to?(:actor)
|
||
|
|
rescue
|
||
|
|
actor = nil
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
actor = $game_party.members[0] if actor.nil? && defined?($game_party) && $game_party && $game_party.respond_to?(:members)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
actor
|
||
|
|
rescue
|
||
|
|
nil
|
||
|
|
end
|
||
|
|
|
||
|
|
def current_survival_resources
|
||
|
|
actor = active_local_actor
|
||
|
|
return {} if actor.nil?
|
||
|
|
out = {}
|
||
|
|
begin; out["hp"] = actor.hp if actor.respond_to?(:hp); rescue; end
|
||
|
|
begin; out["health"] = actor.health if actor.respond_to?(:health); rescue; end
|
||
|
|
begin; out["sta"] = actor.sta if actor.respond_to?(:sta); rescue; end
|
||
|
|
begin; out["sat"] = actor.sat if actor.respond_to?(:sat); rescue; end
|
||
|
|
out
|
||
|
|
rescue
|
||
|
|
{}
|
||
|
|
end
|
||
|
|
|
||
|
|
def survival_current_stat_index
|
||
|
|
begin
|
||
|
|
return ActorStat::CURRENT_STAT.to_i if defined?(ActorStat::CURRENT_STAT)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
0
|
||
|
|
rescue
|
||
|
|
0
|
||
|
|
end
|
||
|
|
|
||
|
|
# The bootstrap stats blob contains the whole @actStat table and is applied
|
||
|
|
# AFTER the top-level hp/sta/sat fields. If it is left untouched it can put
|
||
|
|
# the corpse's zero health/STA straight back into the living character.
|
||
|
|
# Replace only CURRENT resource values; max/min/base stats still come from
|
||
|
|
# the recovered corpse as intended.
|
||
|
|
def protect_survival_in_restore_payload(payload, snapshot)
|
||
|
|
return unless payload.is_a?(Hash) && snapshot.is_a?(Hash)
|
||
|
|
|
||
|
|
payload["hp"] = snapshot["hp"] if snapshot.has_key?("hp")
|
||
|
|
payload["sta"] = snapshot["sta"] if snapshot.has_key?("sta")
|
||
|
|
payload["sat"] = snapshot["sat"] if snapshot.has_key?("sat")
|
||
|
|
|
||
|
|
stats = payload["stats_json"]
|
||
|
|
if stats.is_a?(Hash)
|
||
|
|
full = stats["act_stat_full"]
|
||
|
|
idx = survival_current_stat_index
|
||
|
|
{ "health" => "health", "sta" => "sta", "sat" => "sat" }.each do |stat_key, snap_key|
|
||
|
|
next unless snapshot.has_key?(snap_key)
|
||
|
|
value = snapshot[snap_key]
|
||
|
|
stats[stat_key] = value
|
||
|
|
next unless full.is_a?(Hash) && full.has_key?(stat_key)
|
||
|
|
row = full[stat_key]
|
||
|
|
if row.is_a?(Array)
|
||
|
|
row[idx] = value if idx >= 0 && idx < row.length
|
||
|
|
else
|
||
|
|
full[stat_key] = value
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
# This normally does not contain these keys, but sanitize them too so a
|
||
|
|
# future body schema cannot accidentally re-introduce death resources.
|
||
|
|
body = payload["body_json"]
|
||
|
|
if body.is_a?(Hash) && body["body_stats"].is_a?(Hash)
|
||
|
|
body_stats = body["body_stats"]
|
||
|
|
["health", "sta", "sat"].each do |key|
|
||
|
|
body_stats[key] = snapshot[key] if snapshot.has_key?(key) && body_stats.has_key?(key)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
rescue => e
|
||
|
|
puts "[CORPSE] survival payload protection failed: #{e.class}: #{e.message}" rescue nil
|
||
|
|
end
|
||
|
|
|
||
|
|
def restore_survival_resources(snapshot)
|
||
|
|
return unless snapshot.is_a?(Hash)
|
||
|
|
# Re-acquire the actor AFTER bootstrap. Some restore/bootstrap paths may
|
||
|
|
# replace the local actor object, so keeping the pre-apply object reference
|
||
|
|
# is not reliable.
|
||
|
|
actor = active_local_actor
|
||
|
|
return if actor.nil?
|
||
|
|
|
||
|
|
begin
|
||
|
|
if snapshot.has_key?("health")
|
||
|
|
if actor.respond_to?(:health=)
|
||
|
|
actor.health = snapshot["health"]
|
||
|
|
else
|
||
|
|
act_stat = actor.instance_variable_get(:@actStat) rescue nil
|
||
|
|
act_stat.set_stat("health", snapshot["health"], survival_current_stat_index) if act_stat && act_stat.respond_to?(:set_stat)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
if snapshot.has_key?("sta")
|
||
|
|
if actor.respond_to?(:sta=)
|
||
|
|
actor.sta = snapshot["sta"]
|
||
|
|
else
|
||
|
|
act_stat = actor.instance_variable_get(:@actStat) rescue nil
|
||
|
|
act_stat.set_stat("sta", snapshot["sta"], survival_current_stat_index) if act_stat && act_stat.respond_to?(:set_stat)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
if snapshot.has_key?("sat")
|
||
|
|
if actor.respond_to?(:sat=)
|
||
|
|
actor.sat = snapshot["sat"]
|
||
|
|
else
|
||
|
|
act_stat = actor.instance_variable_get(:@actStat) rescue nil
|
||
|
|
act_stat.set_stat("sat", snapshot["sat"], survival_current_stat_index) if act_stat && act_stat.respond_to?(:set_stat)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
if snapshot.has_key?("hp")
|
||
|
|
if actor.respond_to?(:hp=)
|
||
|
|
actor.hp = snapshot["hp"]
|
||
|
|
else
|
||
|
|
actor.instance_variable_set(:@hp, snapshot["hp"])
|
||
|
|
end
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
actor.instance_variable_set(:@stat_changed, true)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def submit_death_snapshot
|
||
|
|
@death_pending = false
|
||
|
|
@death_corpse_id = nil
|
||
|
|
return false unless connected?
|
||
|
|
return false unless defined?($game_map) && $game_map
|
||
|
|
return false unless defined?($game_player) && $game_player
|
||
|
|
return false unless WebSocket.respond_to?(:_live_sync_build_packet)
|
||
|
|
|
||
|
|
built = WebSocket._live_sync_build_packet rescue nil
|
||
|
|
base = if built.is_a?(Array)
|
||
|
|
built[0].to_s
|
||
|
|
else
|
||
|
|
built.to_s
|
||
|
|
end
|
||
|
|
return false if base.empty?
|
||
|
|
|
||
|
|
parts = base.split(":", -1)
|
||
|
|
return false if parts.length < 16 || parts[0].to_s != "sync_state"
|
||
|
|
|
||
|
|
map_id = current_map_id
|
||
|
|
x = $game_player.x.to_i rescue 0
|
||
|
|
y = $game_player.y.to_i rescue 0
|
||
|
|
dir = $game_player.direction.to_i rescue 2
|
||
|
|
death_overmap_origin = capture_death_overmap_origin(map_id, x, y)
|
||
|
|
|
||
|
|
actor = nil
|
||
|
|
begin
|
||
|
|
actor = $game_player.actor if $game_player.respond_to?(:actor)
|
||
|
|
rescue
|
||
|
|
actor = nil
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
actor = $game_party.members[0] if actor.nil? && $game_party && $game_party.respond_to?(:members)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
sta = 0
|
||
|
|
sat = 0
|
||
|
|
begin
|
||
|
|
sta = actor.sta.to_i if actor && actor.respond_to?(:sta)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
sat = actor.sat.to_i if actor && actor.respond_to?(:sat)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
body = prioritized_body_blob(actor, parts[15].to_s)
|
||
|
|
|
||
|
|
packet = [
|
||
|
|
"sync_state", "corpse_death",
|
||
|
|
map_id, x, y, dir,
|
||
|
|
parts[1].to_i, # level
|
||
|
|
parts[2].to_i, # gold
|
||
|
|
[parts[4].to_i, 1].max,
|
||
|
|
sta, sat,
|
||
|
|
parts[5].to_s, # items
|
||
|
|
parts[6].to_s, # weapons
|
||
|
|
parts[7].to_s, # armors
|
||
|
|
parts[8].to_s, # equips
|
||
|
|
parts[9].to_s, # skills
|
||
|
|
parts[10].to_s, # stats / EXP / trait points
|
||
|
|
parts[12].to_s, # player meta / hotkeys
|
||
|
|
body, # body/story subset; omitted if unusually large
|
||
|
|
death_overmap_origin ? death_overmap_origin["map_id"].to_i : 0,
|
||
|
|
death_overmap_origin ? death_overmap_origin["x"].to_i : 0,
|
||
|
|
death_overmap_origin ? death_overmap_origin["y"].to_i : 0
|
||
|
|
].join(":")
|
||
|
|
|
||
|
|
if packet.length > MAX_WIRE_CHARS
|
||
|
|
# Keep mission/quest progress even when non-critical body data is large.
|
||
|
|
chunks = packet.split(":", -1)
|
||
|
|
quest_blob = quest_only_body_blob
|
||
|
|
chunks[18] = quest_blob if chunks.length > 18
|
||
|
|
packet = chunks.join(":")
|
||
|
|
end
|
||
|
|
if packet.length > MAX_WIRE_CHARS
|
||
|
|
notify("Труп не сохранён: снимок слишком большой даже после сохранения только прогресса миссий.", :error)
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
result = WebSocket.send_line(packet)
|
||
|
|
ok = !result.nil? && result.to_i >= 0
|
||
|
|
if ok
|
||
|
|
@death_pending = true
|
||
|
|
@death_deadline_frame = frame_now + DEATH_ACK_WAIT_FRAMES
|
||
|
|
end
|
||
|
|
ok
|
||
|
|
rescue => e
|
||
|
|
puts "[CORPSE] death snapshot failed: #{e.class}: #{e.message}" rescue nil
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def waiting_death_ack?
|
||
|
|
return false unless @death_pending
|
||
|
|
if frame_now >= @death_deadline_frame.to_i
|
||
|
|
@death_pending = false
|
||
|
|
notify("Сервер не подтвердил создание трупа. Респавн продолжен.", :error)
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
true
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def death_ok(id, expires_at_ms, server_now_ms=nil)
|
||
|
|
@death_pending = false
|
||
|
|
@death_corpse_id = id.to_i
|
||
|
|
calibrate_server_clock(server_now_ms) if server_now_ms.to_i > 0
|
||
|
|
notify("Труп защищён для вас на 15 минут. Затем его смогут обыскать другие игроки.", :info)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def decode_nick(value)
|
||
|
|
raw = value.to_s
|
||
|
|
return "Player" if raw.empty?
|
||
|
|
begin
|
||
|
|
if defined?(Base64)
|
||
|
|
pad = (4 - raw.length % 4) % 4
|
||
|
|
padded = raw.tr("-_", "+/") + ("=" * pad)
|
||
|
|
decoded = if Base64.respond_to?(:strict_decode64)
|
||
|
|
Base64.strict_decode64(padded)
|
||
|
|
elsif Base64.respond_to?(:decode64)
|
||
|
|
Base64.decode64(padded)
|
||
|
|
else
|
||
|
|
nil
|
||
|
|
end
|
||
|
|
unless decoded.nil?
|
||
|
|
decoded = decoded.to_s
|
||
|
|
decoded.force_encoding("UTF-8") if decoded.respond_to?(:force_encoding)
|
||
|
|
return decoded
|
||
|
|
end
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
raw
|
||
|
|
rescue
|
||
|
|
"Player"
|
||
|
|
end
|
||
|
|
|
||
|
|
def upsert_corpse(id, map_id, x, y, public_at_ms, owner, nick_b64, server_now_ms=nil,
|
||
|
|
overmap_map_id=nil, overmap_x=nil, overmap_y=nil, expires_at_ms=nil)
|
||
|
|
cid = id.to_i
|
||
|
|
return if cid <= 0
|
||
|
|
calibrate_server_clock(server_now_ms) if server_now_ms.to_i > 0
|
||
|
|
corpse = {
|
||
|
|
"id" => cid,
|
||
|
|
"map_id" => map_id.to_i,
|
||
|
|
"x" => x.to_i,
|
||
|
|
"y" => y.to_i,
|
||
|
|
"public_at_ms" => public_at_ms.to_i,
|
||
|
|
# Old 1.0.x servers sent only one expiry field. Keep that protocol valid.
|
||
|
|
"expires_at_ms" => (expires_at_ms.nil? ? public_at_ms.to_i : expires_at_ms.to_i),
|
||
|
|
"owner" => owner.to_i == 1,
|
||
|
|
"nick" => decode_nick(nick_b64)
|
||
|
|
}
|
||
|
|
if overmap_map_id.to_i == OVERMAP_MAP_ID && overmap_x.to_i >= 0 && overmap_y.to_i >= 0
|
||
|
|
corpse["overmap_origin"] = {
|
||
|
|
"map_id" => OVERMAP_MAP_ID,
|
||
|
|
"x" => overmap_x.to_i,
|
||
|
|
"y" => overmap_y.to_i
|
||
|
|
}
|
||
|
|
end
|
||
|
|
@corpses[cid] = corpse
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def remove_corpse(id)
|
||
|
|
@corpses.delete(id.to_i)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def corpses_for_current_map
|
||
|
|
map_id = current_map_id
|
||
|
|
now = display_server_now_ms
|
||
|
|
out = []
|
||
|
|
@corpses.keys.each do |id|
|
||
|
|
c = @corpses[id]
|
||
|
|
next unless c.is_a?(Hash)
|
||
|
|
if c["expires_at_ms"].to_i <= now
|
||
|
|
@corpses.delete(id)
|
||
|
|
next
|
||
|
|
end
|
||
|
|
out << c if c["map_id"].to_i == map_id
|
||
|
|
end
|
||
|
|
out
|
||
|
|
rescue
|
||
|
|
[]
|
||
|
|
end
|
||
|
|
|
||
|
|
# Real corpse markers remain on their actual map. On Map002, a display-only
|
||
|
|
# proxy points at the entrance tile of the location where the death occurred.
|
||
|
|
# A proxy is never claimable from OverMap.
|
||
|
|
def marker_corpses_for_current_map
|
||
|
|
out = corpses_for_current_map
|
||
|
|
return out unless current_map_id == OVERMAP_MAP_ID
|
||
|
|
|
||
|
|
seen = {}
|
||
|
|
out.each { |corpse| seen[corpse["id"].to_i] = true if corpse.is_a?(Hash) }
|
||
|
|
now = display_server_now_ms
|
||
|
|
@corpses.each_value do |corpse|
|
||
|
|
next unless corpse.is_a?(Hash)
|
||
|
|
next if seen[corpse["id"].to_i]
|
||
|
|
next if corpse["expires_at_ms"].to_i <= now
|
||
|
|
origin = corpse["overmap_origin"]
|
||
|
|
next unless origin.is_a?(Hash) && origin["map_id"].to_i == OVERMAP_MAP_ID
|
||
|
|
|
||
|
|
proxy = corpse.dup
|
||
|
|
proxy["x"] = origin["x"].to_i
|
||
|
|
proxy["y"] = origin["y"].to_i
|
||
|
|
proxy["overmap_proxy"] = true
|
||
|
|
out << proxy
|
||
|
|
end
|
||
|
|
out
|
||
|
|
rescue
|
||
|
|
corpses_for_current_map
|
||
|
|
end
|
||
|
|
|
||
|
|
def remaining_seconds(corpse)
|
||
|
|
return 0 unless corpse.is_a?(Hash)
|
||
|
|
now = display_server_now_ms
|
||
|
|
target = corpse_public?(corpse, now) ? corpse["expires_at_ms"].to_i : corpse["public_at_ms"].to_i
|
||
|
|
left = target - now
|
||
|
|
[(left / 1000.0).ceil, 0].max
|
||
|
|
rescue
|
||
|
|
0
|
||
|
|
end
|
||
|
|
|
||
|
|
def corpse_public?(corpse, now=nil)
|
||
|
|
return false unless corpse.is_a?(Hash)
|
||
|
|
current = now.nil? ? display_server_now_ms : now.to_i
|
||
|
|
public_at = corpse["public_at_ms"].to_i
|
||
|
|
public_at > 0 && current >= public_at
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def owner_corpse
|
||
|
|
now = display_server_now_ms
|
||
|
|
best = nil
|
||
|
|
@corpses.keys.each do |id|
|
||
|
|
c = @corpses[id]
|
||
|
|
next unless c.is_a?(Hash)
|
||
|
|
if c["expires_at_ms"].to_i <= now
|
||
|
|
@corpses.delete(id)
|
||
|
|
next
|
||
|
|
end
|
||
|
|
next unless c["owner"]
|
||
|
|
best = c if best.nil? || c["expires_at_ms"].to_i > best["expires_at_ms"].to_i
|
||
|
|
end
|
||
|
|
best
|
||
|
|
rescue
|
||
|
|
nil
|
||
|
|
end
|
||
|
|
|
||
|
|
def near?(corpse)
|
||
|
|
return false unless corpse.is_a?(Hash)
|
||
|
|
return false unless defined?($game_player) && $game_player
|
||
|
|
dx = ($game_player.x.to_i - corpse["x"].to_i).abs
|
||
|
|
dy = ($game_player.y.to_i - corpse["y"].to_i).abs
|
||
|
|
[dx, dy].max <= 1
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def try_claim_nearby
|
||
|
|
return unless connected?
|
||
|
|
return unless defined?(Input)
|
||
|
|
return unless Input.trigger?(:C)
|
||
|
|
now = Time.now.to_f rescue 0.0
|
||
|
|
return if now > 0.0 && (now - @last_claim_at.to_f) < 0.45
|
||
|
|
|
||
|
|
target = corpses_for_current_map.find do |c|
|
||
|
|
near?(c) && (c["owner"] || corpse_public?(c))
|
||
|
|
end
|
||
|
|
return if target.nil?
|
||
|
|
@last_claim_at = now
|
||
|
|
WebSocket.send_line("corpse_claim:#{target['id']}")
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def begin_restore(id)
|
||
|
|
@restore_pending_id = id.to_i
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def restore_pending?
|
||
|
|
@restore_pending_id.to_i > 0
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def consume_restore_packet(msg)
|
||
|
|
return false unless restore_pending?
|
||
|
|
return false unless msg.to_s.start_with?("bootstrap_state:")
|
||
|
|
|
||
|
|
parts = msg.to_s.split(":", 21)
|
||
|
|
corpse_id = @restore_pending_id.to_i
|
||
|
|
@restore_pending_id = nil
|
||
|
|
if parts.length < 20
|
||
|
|
notify("Не удалось прочитать содержимое тела. Труп не удалён.", :error)
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
|
||
|
|
# A corpse is loot, never a character save. In particular, never feed its
|
||
|
|
# stale stats/skills/race/player/body fields to apply_bootstrap_state.
|
||
|
|
unless @restore_loot_applied[corpse_id]
|
||
|
|
items = WebSocket.bootstrap_parse_blob(parts[11].to_s, true) rescue {}
|
||
|
|
weapons = WebSocket.bootstrap_parse_blob(parts[12].to_s, true) rescue {}
|
||
|
|
armors = WebSocket.bootstrap_parse_blob(parts[13].to_s, true) rescue {}
|
||
|
|
equips = WebSocket.bootstrap_parse_blob(parts[14].to_s, false) rescue {}
|
||
|
|
begin
|
||
|
|
WebSocket._bootstrap_gain_hash("item", items) if WebSocket.respond_to?(:_bootstrap_gain_hash)
|
||
|
|
WebSocket._bootstrap_gain_hash("weapon", weapons) if WebSocket.respond_to?(:_bootstrap_gain_hash)
|
||
|
|
WebSocket._bootstrap_gain_hash("armor", armors) if WebSocket.respond_to?(:_bootstrap_gain_hash)
|
||
|
|
gain_public_equip_items(equips)
|
||
|
|
rescue => e
|
||
|
|
puts "[CORPSE] owner loot apply failed: #{e.class}: #{e.message}" rescue nil
|
||
|
|
notify("Не удалось вернуть вещи из тела. Труп не удалён.", :error)
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
@restore_loot_applied[corpse_id] = true
|
||
|
|
puts "[CORPSE] owner loot-only recovery corpse=#{corpse_id} player=#{WebSocket.instance_variable_get(:@my_id) rescue nil}" rescue nil
|
||
|
|
end
|
||
|
|
|
||
|
|
if send_compact_restore_save(corpse_id)
|
||
|
|
notify("Вещи из тела возвращены. Сохраняю на сервере…", :info)
|
||
|
|
else
|
||
|
|
notify("Вещи возвращены, но save не отправлен. Труп не удалён; попробуйте ещё раз.", :error)
|
||
|
|
end
|
||
|
|
true
|
||
|
|
rescue => e
|
||
|
|
@restore_pending_id = nil
|
||
|
|
puts "[CORPSE] restore parse failed: #{e.class}: #{e.message}" rescue nil
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def begin_public_loot(id)
|
||
|
|
@public_loot_pending_id = id.to_i
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def public_loot_pending?
|
||
|
|
@public_loot_pending_id.to_i > 0
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def gain_public_equip_items(equips)
|
||
|
|
return unless equips.is_a?(Hash)
|
||
|
|
return unless defined?($game_party) && $game_party && $game_party.respond_to?(:gain_item)
|
||
|
|
equips.each_value do |raw_token|
|
||
|
|
token = raw_token.to_s.split(",", 3)
|
||
|
|
kind = token[0].to_s.strip.downcase
|
||
|
|
item_id = token[1].to_i
|
||
|
|
item_name = token[2].to_s.strip
|
||
|
|
next if kind == "none" || item_id <= 0
|
||
|
|
item = nil
|
||
|
|
begin
|
||
|
|
if !item_name.empty? && WebSocket.respond_to?(:_bootstrap_data_item_by_name)
|
||
|
|
item = WebSocket._bootstrap_data_item_by_name(item_name)
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
item = nil
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
item = WebSocket._bootstrap_data_item(kind, item_id) if item.nil? && WebSocket.respond_to?(:_bootstrap_data_item)
|
||
|
|
rescue
|
||
|
|
item = nil
|
||
|
|
end
|
||
|
|
$game_party.gain_item(item, 1) unless item.nil?
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
# Public corpse loot is intentionally additive. It never invokes the normal
|
||
|
|
# bootstrap applier, so the looter's inventory, EXP, skills, quests, stats,
|
||
|
|
# body state, position and survival resources cannot be replaced.
|
||
|
|
def consume_public_loot_packet(msg)
|
||
|
|
return false unless public_loot_pending?
|
||
|
|
return false unless msg.to_s.start_with?("bootstrap_state:")
|
||
|
|
parts = msg.to_s.split(":", 21)
|
||
|
|
corpse_id = @public_loot_pending_id.to_i
|
||
|
|
@public_loot_pending_id = nil
|
||
|
|
if parts.length < 20
|
||
|
|
notify("Не удалось прочитать добычу из тела. Труп не удалён.", :error)
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
|
||
|
|
unless @public_loot_applied[corpse_id]
|
||
|
|
items = WebSocket.bootstrap_parse_blob(parts[11].to_s, true) rescue {}
|
||
|
|
weapons = WebSocket.bootstrap_parse_blob(parts[12].to_s, true) rescue {}
|
||
|
|
armors = WebSocket.bootstrap_parse_blob(parts[13].to_s, true) rescue {}
|
||
|
|
equips = WebSocket.bootstrap_parse_blob(parts[14].to_s, false) rescue {}
|
||
|
|
begin
|
||
|
|
WebSocket._bootstrap_gain_hash("item", items) if WebSocket.respond_to?(:_bootstrap_gain_hash)
|
||
|
|
WebSocket._bootstrap_gain_hash("weapon", weapons) if WebSocket.respond_to?(:_bootstrap_gain_hash)
|
||
|
|
WebSocket._bootstrap_gain_hash("armor", armors) if WebSocket.respond_to?(:_bootstrap_gain_hash)
|
||
|
|
gain_public_equip_items(equips)
|
||
|
|
rescue => e
|
||
|
|
puts "[CORPSE] public loot apply failed: #{e.class}: #{e.message}" rescue nil
|
||
|
|
notify("Не удалось добавить добычу. Труп не удалён.", :error)
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
@public_loot_applied[corpse_id] = true
|
||
|
|
end
|
||
|
|
|
||
|
|
if send_compact_public_loot_save(corpse_id)
|
||
|
|
notify("Добыча добавлена. Сохраняю её на сервере…", :info)
|
||
|
|
else
|
||
|
|
notify("Добыча добавлена, но серверный save не отправлен. Труп оставлен; попробуйте ещё раз.", :error)
|
||
|
|
end
|
||
|
|
true
|
||
|
|
rescue => e
|
||
|
|
@public_loot_pending_id = nil
|
||
|
|
puts "[CORPSE] public loot parse failed: #{e.class}: #{e.message}" rescue nil
|
||
|
|
true
|
||
|
|
end
|
||
|
|
|
||
|
|
def compact_reason(reason)
|
||
|
|
value = reason.to_s.strip.downcase.gsub(/[^a-z0-9_]+/, "_")
|
||
|
|
value = "cloud_corpse" if value.empty?
|
||
|
|
value = "cloud_#{value}" unless value.start_with?("cloud_")
|
||
|
|
value[0, 48]
|
||
|
|
rescue
|
||
|
|
"cloud_corpse"
|
||
|
|
end
|
||
|
|
|
||
|
|
def send_compact_current_save(reason)
|
||
|
|
return false unless connected?
|
||
|
|
return false unless WebSocket.respond_to?(:_live_sync_build_packet)
|
||
|
|
built = WebSocket._live_sync_build_packet rescue nil
|
||
|
|
base = built.is_a?(Array) ? built[0].to_s : built.to_s
|
||
|
|
parts = base.split(":", -1)
|
||
|
|
return false if parts.length < 13 || parts[0].to_s != "sync_state"
|
||
|
|
|
||
|
|
# Keep reason inside the first 14 server payload fields. LonaRPG 1.0.6
|
||
|
|
# parses sync_state with splitPayload(14); omitting bank/stat_pack/body makes
|
||
|
|
# the cloud reason visible to the stock dispatcher without changing Java core.
|
||
|
|
clean_reason = compact_reason(reason)
|
||
|
|
compact = [
|
||
|
|
"sync_state",
|
||
|
|
parts[1], parts[2], parts[3], parts[4],
|
||
|
|
parts[5], parts[6], parts[7], parts[8],
|
||
|
|
parts[9], parts[10], "", parts[12],
|
||
|
|
"reason=#{clean_reason}"
|
||
|
|
].join(":")
|
||
|
|
return false if compact.length > MAX_WIRE_CHARS
|
||
|
|
|
||
|
|
begin
|
||
|
|
map_id = current_map_id
|
||
|
|
line = WebSocket.respond_to?(:map_packet_for_server) ? WebSocket.map_packet_for_server(map_id) : "map:#{map_id}"
|
||
|
|
WebSocket.send_line(line) if map_id > 0
|
||
|
|
WebSocket.live_sync_position_now(clean_reason, true) if WebSocket.respond_to?(:live_sync_position_now)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
result = WebSocket.send_line(compact)
|
||
|
|
!result.nil? && result.to_i >= 0
|
||
|
|
rescue => e
|
||
|
|
puts "[CORPSE] compact save failed: #{e.class}: #{e.message}" rescue nil
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def send_compact_restore_save(corpse_id, retrying=false)
|
||
|
|
ok = send_compact_current_save("cloud_corpse_restore")
|
||
|
|
if ok
|
||
|
|
@restore_save_pending_id = corpse_id.to_i
|
||
|
|
@restore_save_attempts = retrying ? (@restore_save_attempts.to_i + 1) : 1
|
||
|
|
@restore_save_next_retry_frame = frame_now + 90
|
||
|
|
end
|
||
|
|
ok
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def tick_restore_save
|
||
|
|
id = @restore_save_pending_id.to_i
|
||
|
|
return if id <= 0
|
||
|
|
return if frame_now < @restore_save_next_retry_frame.to_i
|
||
|
|
if @restore_save_attempts.to_i >= 4
|
||
|
|
@restore_save_pending_id = nil
|
||
|
|
@restore_save_attempts = 0
|
||
|
|
notify("Сервер не подтвердил сохранение восстановленного тела. Труп оставлен; подойдите и попробуйте снова.", :error)
|
||
|
|
return
|
||
|
|
end
|
||
|
|
send_compact_restore_save(id, true)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def send_compact_public_loot_save(corpse_id, retrying=false)
|
||
|
|
ok = send_compact_current_save("cloud_corpse_public_loot")
|
||
|
|
if ok
|
||
|
|
@public_loot_save_pending_id = corpse_id.to_i
|
||
|
|
@public_loot_save_attempts = retrying ? (@public_loot_save_attempts.to_i + 1) : 1
|
||
|
|
@public_loot_save_next_retry_frame = frame_now + 90
|
||
|
|
end
|
||
|
|
ok
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def tick_public_loot_save
|
||
|
|
id = @public_loot_save_pending_id.to_i
|
||
|
|
return if id <= 0
|
||
|
|
return if frame_now < @public_loot_save_next_retry_frame.to_i
|
||
|
|
if @public_loot_save_attempts.to_i >= 4
|
||
|
|
@public_loot_save_pending_id = nil
|
||
|
|
@public_loot_save_attempts = 0
|
||
|
|
notify("Сервер не подтвердил сохранение добычи. Труп оставлен; попробуйте снова.", :error)
|
||
|
|
return
|
||
|
|
end
|
||
|
|
send_compact_public_loot_save(id, true)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def request_post_death_reset_save
|
||
|
|
@post_death_reset_save = true
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def request_tutorial_initial_save
|
||
|
|
@tutorial_initial_save = true
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def post_death_reset_save_pending?
|
||
|
|
!!@post_death_reset_save
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def tutorial_initial_save_pending?
|
||
|
|
!!@tutorial_initial_save
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def send_post_death_reset_save
|
||
|
|
if send_compact_current_save("cloud_corpse_death_reset")
|
||
|
|
@post_death_reset_save = false
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
false
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def send_tutorial_initial_save
|
||
|
|
if send_compact_current_save("cloud_tutorial_initial")
|
||
|
|
@tutorial_initial_save = false
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
false
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def cloud_restore_saved
|
||
|
|
id = @restore_save_pending_id.to_i
|
||
|
|
return if id <= 0
|
||
|
|
@restore_save_pending_id = nil
|
||
|
|
@restore_save_attempts = 0
|
||
|
|
@restore_save_next_retry_frame = 0
|
||
|
|
begin
|
||
|
|
WebSocket.send_line("corpse_restore_ack:#{id}") if connected?
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def cloud_public_loot_saved
|
||
|
|
id = @public_loot_save_pending_id.to_i
|
||
|
|
return if id <= 0
|
||
|
|
@public_loot_save_pending_id = nil
|
||
|
|
@public_loot_save_attempts = 0
|
||
|
|
@public_loot_save_next_retry_frame = 0
|
||
|
|
begin
|
||
|
|
WebSocket.send_line("corpse_loot_ack:#{id}") if connected?
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def restore_done(id)
|
||
|
|
cid = id.to_i
|
||
|
|
remove_corpse(cid)
|
||
|
|
@restore_loot_applied.delete(cid)
|
||
|
|
notify("💀 Тело подобрано: вещи возвращены, текущее развитие персонажа сохранено.", :success)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def public_loot_done(id)
|
||
|
|
cid = id.to_i
|
||
|
|
remove_corpse(cid)
|
||
|
|
@public_loot_applied.delete(cid)
|
||
|
|
notify("💀 Чужое тело обыскано: предметы, оружие, броня и монеты добавлены к вашему инвентарю.", :success)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def claim_error(code)
|
||
|
|
@restore_pending_id = nil
|
||
|
|
@public_loot_pending_id = nil
|
||
|
|
text = case code.to_s
|
||
|
|
when "too_far" then "Подойдите ближе к телу."
|
||
|
|
when "wrong_map" then "Тело находится на другой карте."
|
||
|
|
when "expired", "not_found" then "Это тело уже исчезло."
|
||
|
|
when "not_owner" then "Можно подобрать только собственное тело."
|
||
|
|
when "protected" then "Тело пока защищено владельцем."
|
||
|
|
when "busy" then "Это тело сейчас обыскивает другой игрок."
|
||
|
|
when "restore_too_large" then "Снимок тела слишком большой для восстановления."
|
||
|
|
else "Тело пока нельзя подобрать (#{code})."
|
||
|
|
end
|
||
|
|
notify(text, :error)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def mark_new_registration_tutorial(reset_consumed=true)
|
||
|
|
@new_registration_tutorial = true
|
||
|
|
# auth_ok:created starts a genuinely new registration. A later helper
|
||
|
|
# packet must not re-arm TutorialOP after the first bootstrap was consumed.
|
||
|
|
@new_registration_tutorial_consumed = false if reset_consumed
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def new_registration_tutorial?
|
||
|
|
!!@new_registration_tutorial && !tutorial_bootstrap_consumed?
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def tutorial_bootstrap_consumed?
|
||
|
|
!!@new_registration_tutorial_consumed
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
|
||
|
|
def finish_new_registration_tutorial
|
||
|
|
@new_registration_tutorial = false
|
||
|
|
@new_registration_tutorial_consumed = true
|
||
|
|
@post_death_reset_save = false
|
||
|
|
@tutorial_initial_save = true
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def tutorial_new(map_id, x, y, direction)
|
||
|
|
begin
|
||
|
|
WebSocket.set_bootstrap_map(map_id.to_i) if WebSocket.respond_to?(:set_bootstrap_map)
|
||
|
|
WebSocket.set_bootstrap_position(x.to_i, y.to_i, direction.to_i) if WebSocket.respond_to?(:set_bootstrap_position)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
#--------------------------------------------------------------------------
|
||
|
|
# Owner corpse HUD: always fixed at the top-center of the screen. It uses the
|
||
|
|
# real VIP skull asset (U+1F480 / 1f480.png) and the authoritative server
|
||
|
|
# expiration timestamp. This is display-only; server cleanup remains final.
|
||
|
|
#--------------------------------------------------------------------------
|
||
|
|
class TopHud
|
||
|
|
def initialize
|
||
|
|
@last_id = 0
|
||
|
|
@last_second = -1
|
||
|
|
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
|
||
|
|
@viewport.z = 10_000
|
||
|
|
@panel = Sprite.new(@viewport)
|
||
|
|
@panel.bitmap = Bitmap.new(TOP_HUD_WIDTH, TOP_HUD_HEIGHT)
|
||
|
|
@panel.x = (Graphics.width - TOP_HUD_WIDTH) / 2
|
||
|
|
@panel.y = TOP_HUD_Y
|
||
|
|
@panel.z = 1
|
||
|
|
@skull_left = Sprite.new(@viewport)
|
||
|
|
@skull_right = Sprite.new(@viewport)
|
||
|
|
@skull_left.z = 2
|
||
|
|
@skull_right.z = 2
|
||
|
|
render_skull(@skull_left)
|
||
|
|
render_skull(@skull_right)
|
||
|
|
hide
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def render_skull(sprite)
|
||
|
|
return if sprite.nil?
|
||
|
|
rendered = false
|
||
|
|
begin
|
||
|
|
rendered = !!MPNickEmoji.redraw_sprite(sprite, SKULL, 16) if defined?(MPNickEmoji) && MPNickEmoji.respond_to?(:redraw_sprite)
|
||
|
|
rescue
|
||
|
|
rendered = false
|
||
|
|
end
|
||
|
|
unless rendered
|
||
|
|
bmp = Bitmap.new(22, 22)
|
||
|
|
begin
|
||
|
|
bmp.font.name = MPNickEmoji.font_name if defined?(MPNickEmoji) && MPNickEmoji.respond_to?(:font_name)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
bmp.font.size = 16
|
||
|
|
bmp.draw_text(0, 0, 22, 22, SKULL, 1)
|
||
|
|
sprite.bitmap = bmp
|
||
|
|
sprite.ox = 11
|
||
|
|
sprite.oy = 22
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def hide
|
||
|
|
@panel.visible = false if @panel
|
||
|
|
@skull_left.visible = false if @skull_left
|
||
|
|
@skull_right.visible = false if @skull_right
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def update
|
||
|
|
corpse = MPCorpseRecovery.owner_corpse
|
||
|
|
if corpse.nil?
|
||
|
|
@last_id = 0
|
||
|
|
@last_second = -1
|
||
|
|
hide
|
||
|
|
return
|
||
|
|
end
|
||
|
|
sec = MPCorpseRecovery.remaining_seconds(corpse)
|
||
|
|
if sec <= 0
|
||
|
|
hide
|
||
|
|
return
|
||
|
|
end
|
||
|
|
@panel.visible = true if @panel
|
||
|
|
@skull_left.visible = true if @skull_left
|
||
|
|
@skull_right.visible = true if @skull_right
|
||
|
|
|
||
|
|
# Symmetric layout: timer is exactly centered. Compared with the previous
|
||
|
|
# HUD the skull-to-clock gap is roughly halved, but they do not touch.
|
||
|
|
center = Graphics.width / 2
|
||
|
|
skull_offset = 33
|
||
|
|
@skull_left.x = center - skull_offset
|
||
|
|
@skull_left.y = TOP_HUD_Y + 21
|
||
|
|
@skull_right.x = center + skull_offset
|
||
|
|
@skull_right.y = TOP_HUD_Y + 21
|
||
|
|
|
||
|
|
id = corpse["id"].to_i
|
||
|
|
return if @last_id == id && @last_second == sec
|
||
|
|
@last_id = id
|
||
|
|
@last_second = sec
|
||
|
|
redraw(corpse, sec)
|
||
|
|
rescue
|
||
|
|
hide
|
||
|
|
end
|
||
|
|
|
||
|
|
def redraw(corpse, sec)
|
||
|
|
bmp = @panel.bitmap
|
||
|
|
return if bmp.nil?
|
||
|
|
bmp.clear
|
||
|
|
# Transparent HUD: two VIP skulls + centered timer, no background.
|
||
|
|
bmp.font.size = 13
|
||
|
|
bmp.font.bold = true
|
||
|
|
bmp.font.outline = true rescue nil
|
||
|
|
bmp.font.color = Color.new(255, 255, 255, 255) rescue nil
|
||
|
|
mins = sec / 60
|
||
|
|
secs = sec % 60
|
||
|
|
bmp.draw_text(0, 1, TOP_HUD_WIDTH, 20, "%02d:%02d" % [mins, secs], 1)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def dispose_sprite(sprite)
|
||
|
|
return if sprite.nil?
|
||
|
|
begin
|
||
|
|
own = sprite.bitmap
|
||
|
|
sprite.dispose unless sprite.disposed?
|
||
|
|
own.dispose if own && !own.disposed?
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
def dispose
|
||
|
|
dispose_sprite(@skull_left)
|
||
|
|
dispose_sprite(@skull_right)
|
||
|
|
begin
|
||
|
|
if @panel
|
||
|
|
own = @panel.bitmap
|
||
|
|
@panel.dispose unless @panel.disposed?
|
||
|
|
own.dispose if own && !own.disposed?
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
@viewport.dispose if @viewport && !@viewport.disposed?
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
@skull_left = nil
|
||
|
|
@skull_right = nil
|
||
|
|
@panel = nil
|
||
|
|
@viewport = nil
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
#--------------------------------------------------------------------------
|
||
|
|
# Map marker sprite
|
||
|
|
#--------------------------------------------------------------------------
|
||
|
|
class Marker
|
||
|
|
def initialize(corpse, viewport=nil)
|
||
|
|
@corpse = corpse
|
||
|
|
@last_second = nil
|
||
|
|
@last_near = nil
|
||
|
|
# OverMap proxy markers are skull-only. The marker is recreated when the
|
||
|
|
# player changes map / switches between OverMap and a normal map, so a
|
||
|
|
# real corpse on a normal map gets its nickname, timer and action text.
|
||
|
|
@overmap = !!@corpse["overmap_proxy"]
|
||
|
|
@skull = Sprite.new(viewport)
|
||
|
|
@label = nil
|
||
|
|
unless @overmap
|
||
|
|
@label = Sprite.new(viewport)
|
||
|
|
@label.bitmap = Bitmap.new(MARKER_WIDTH, MARKER_HEIGHT)
|
||
|
|
@label.z = 239
|
||
|
|
end
|
||
|
|
@skull.z = 240
|
||
|
|
begin
|
||
|
|
rendered = false
|
||
|
|
if defined?(MPNickEmoji) && MPNickEmoji.respond_to?(:redraw_sprite)
|
||
|
|
rendered = !!MPNickEmoji.redraw_sprite(@skull, SKULL, 15)
|
||
|
|
end
|
||
|
|
unless rendered
|
||
|
|
bmp = Bitmap.new(22, 22)
|
||
|
|
bmp.font.name = MPNickEmoji.font_name if defined?(MPNickEmoji) && MPNickEmoji.respond_to?(:font_name)
|
||
|
|
bmp.font.size = 15
|
||
|
|
bmp.draw_text(0, 0, 22, 22, SKULL, 1)
|
||
|
|
@skull.bitmap = bmp
|
||
|
|
@skull.ox = 11
|
||
|
|
@skull.oy = 22
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
redraw(true)
|
||
|
|
end
|
||
|
|
|
||
|
|
def id
|
||
|
|
@corpse["id"].to_i
|
||
|
|
rescue
|
||
|
|
0
|
||
|
|
end
|
||
|
|
|
||
|
|
def update(corpse)
|
||
|
|
@corpse = corpse if corpse.is_a?(Hash)
|
||
|
|
reposition
|
||
|
|
redraw(false)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def reposition
|
||
|
|
tile_w = 32
|
||
|
|
tile_h = 32
|
||
|
|
begin
|
||
|
|
tile_w = $game_map.tile_width.to_i if $game_map.respond_to?(:tile_width)
|
||
|
|
tile_h = $game_map.tile_height.to_i if $game_map.respond_to?(:tile_height)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
tile_w = 32 if tile_w <= 0
|
||
|
|
tile_h = 32 if tile_h <= 0
|
||
|
|
sx = (($game_map.adjust_x(@corpse["x"].to_i) * tile_w) + tile_w / 2).to_i
|
||
|
|
sy = (($game_map.adjust_y(@corpse["y"].to_i) * tile_h) + tile_h).to_i
|
||
|
|
if @corpse["overmap_proxy"]
|
||
|
|
# Match OverMap mission-guide behavior: the skull stays visible at the
|
||
|
|
# screen edge while its location tile is outside the camera.
|
||
|
|
sx = [[sx, 32].max, Graphics.width - 32].min
|
||
|
|
sy = [[sy - 6, 32].max, Graphics.height - 32].min + 6
|
||
|
|
end
|
||
|
|
@skull.x = sx
|
||
|
|
@skull.y = sy - 6
|
||
|
|
if @label
|
||
|
|
label_x = sx - MARKER_WIDTH / 2
|
||
|
|
if @corpse["overmap_proxy"]
|
||
|
|
label_x = [[label_x, 0].max, Graphics.width - MARKER_WIDTH].min
|
||
|
|
end
|
||
|
|
@label.x = label_x
|
||
|
|
@label.y = sy - 5
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def redraw(force=false)
|
||
|
|
# OverMap intentionally shows only the skull.
|
||
|
|
return if @overmap
|
||
|
|
sec = MPCorpseRecovery.remaining_seconds(@corpse)
|
||
|
|
near = !!(!@corpse["overmap_proxy"] &&
|
||
|
|
(@corpse["owner"] || MPCorpseRecovery.corpse_public?(@corpse)) &&
|
||
|
|
MPCorpseRecovery.near?(@corpse))
|
||
|
|
return if !force && @last_second == sec && @last_near == near
|
||
|
|
@last_second = sec
|
||
|
|
@last_near = near
|
||
|
|
|
||
|
|
bmp = @label.bitmap
|
||
|
|
return if bmp.nil?
|
||
|
|
bmp.clear
|
||
|
|
# Transparent corpse marker: no dark rectangle behind the text.
|
||
|
|
bmp.font.size = 10
|
||
|
|
bmp.font.bold = true
|
||
|
|
bmp.font.outline = true rescue nil
|
||
|
|
bmp.font.color = Color.new(255, 255, 255, 255) rescue nil
|
||
|
|
owner = @corpse["nick"].to_s
|
||
|
|
owner = owner[0, 16] if owner.length > 16
|
||
|
|
mins = sec / 60
|
||
|
|
secs = sec % 60
|
||
|
|
bmp.draw_text(3, 0, MARKER_WIDTH - 6, 13, "#{owner} %02d:%02d" % [mins, secs], 1)
|
||
|
|
if near
|
||
|
|
bmp.font.size = 9
|
||
|
|
action = @corpse["owner"] ? "Забрать тело" : "Обыскать тело"
|
||
|
|
bmp.draw_text(3, 13, MARKER_WIDTH - 6, 13, action, 1)
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def dispose
|
||
|
|
begin
|
||
|
|
if @skull
|
||
|
|
bmp = @skull.bitmap
|
||
|
|
@skull.dispose unless @skull.disposed?
|
||
|
|
bmp.dispose if bmp && !bmp.disposed?
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
if @label
|
||
|
|
bmp = @label.bitmap
|
||
|
|
@label.dispose unless @label.disposed?
|
||
|
|
bmp.dispose if bmp && !bmp.disposed?
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
@skull = nil
|
||
|
|
@label = nil
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
#==============================================================================
|
||
|
|
# Corpse restore map-entry safety.
|
||
|
|
#
|
||
|
|
# Some normal maps (for example map 20) intentionally have no "WakeUp"
|
||
|
|
# storypoint. A restored quest/body snapshot may legitimately contain
|
||
|
|
# Captured/RapeLoop progress from the moment of death. The stock
|
||
|
|
# enter_static_tag_map then assumes WakeUp exists and raises before the
|
||
|
|
# reserved corpse-position transfer can finish.
|
||
|
|
#
|
||
|
|
# Do NOT delete the mission state. We only suppress the two transient entry
|
||
|
|
# routing flags while the stock map-entry cleanup runs, then restore them.
|
||
|
|
# This keeps quest progress intact and prevents the missing-WakeUp crash.
|
||
|
|
#==============================================================================
|
||
|
|
if defined?(GIM_ADDON)
|
||
|
|
module GIM_ADDON
|
||
|
|
unless instance_methods.include?(:mp_corpse_safe_enter_static_tag_map_without_guard)
|
||
|
|
alias mp_corpse_safe_enter_static_tag_map_without_guard enter_static_tag_map
|
||
|
|
end
|
||
|
|
|
||
|
|
def enter_static_tag_map(event_id=nil, fadeout=false)
|
||
|
|
needs_guard = false
|
||
|
|
old_captured = nil
|
||
|
|
old_rape_loop = nil
|
||
|
|
|
||
|
|
begin
|
||
|
|
if event_id.nil? && defined?($story_stats) && $story_stats && defined?($game_map) && $game_map
|
||
|
|
captured = ($story_stats["Captured"].to_i == 1 rescue false)
|
||
|
|
rape_loop = ($story_stats["RapeLoop"].to_i == 1 rescue false)
|
||
|
|
if captured || rape_loop
|
||
|
|
points = ($game_map.list_storypoints rescue nil)
|
||
|
|
wake_up = (points["WakeUp"] rescue nil) if points
|
||
|
|
needs_guard = wake_up.nil?
|
||
|
|
end
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
needs_guard = false
|
||
|
|
end
|
||
|
|
|
||
|
|
return mp_corpse_safe_enter_static_tag_map_without_guard(event_id, fadeout) unless needs_guard
|
||
|
|
|
||
|
|
begin
|
||
|
|
old_captured = $story_stats["Captured"]
|
||
|
|
old_rape_loop = $story_stats["RapeLoop"]
|
||
|
|
# Skip only the stock WakeUp routing branch. The original routine still
|
||
|
|
# performs its normal map-entry cleanup, while the player remains at the
|
||
|
|
# position reserved by corpse bootstrap/transfer.
|
||
|
|
$story_stats["Captured"] = 0
|
||
|
|
$story_stats["RapeLoop"] = 0
|
||
|
|
$story_stats["ReRollHalfEvents"] = 0
|
||
|
|
puts "[CORPSE] map entry: WakeUp missing on map=#{$game_map.map_id}; preserving corpse quest state without WakeUp routing" rescue nil
|
||
|
|
mp_corpse_safe_enter_static_tag_map_without_guard(nil, fadeout)
|
||
|
|
ensure
|
||
|
|
begin
|
||
|
|
$story_stats["Captured"] = old_captured unless old_captured.nil?
|
||
|
|
$story_stats["RapeLoop"] = old_rape_loop unless old_rape_loop.nil?
|
||
|
|
$game_map.need_refresh = true if $game_map && $game_map.respond_to?(:need_refresh=)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
#==============================================================================
|
||
|
|
# Network parser bridge
|
||
|
|
#==============================================================================
|
||
|
|
if defined?(WebSocket)
|
||
|
|
module WebSocket
|
||
|
|
class << self
|
||
|
|
alias mp_corpse_recovery_parse parse
|
||
|
|
def parse(msg)
|
||
|
|
text = msg.to_s
|
||
|
|
|
||
|
|
# auth_ok:created is the exact client-visible signal that this profile was
|
||
|
|
# registered right now. Prime TutorialOP before bootstrap_mode:new is applied.
|
||
|
|
if text == "auth_ok:created"
|
||
|
|
MPCorpseRecovery.mark_new_registration_tutorial
|
||
|
|
end
|
||
|
|
if text.start_with?("bootstrap_mode:new") && MPCorpseRecovery.new_registration_tutorial?
|
||
|
|
MPCorpseRecovery.tutorial_new(
|
||
|
|
MPCorpseRecovery::TUTORIAL_MAP_ID, MPCorpseRecovery::TUTORIAL_X,
|
||
|
|
MPCorpseRecovery::TUTORIAL_Y, MPCorpseRecovery::TUTORIAL_DIRECTION
|
||
|
|
)
|
||
|
|
# Keep the flag until MPCloudOnlySave creates the actual new-game base.
|
||
|
|
end
|
||
|
|
|
||
|
|
if text.start_with?("corpse_spawn:")
|
||
|
|
p = text.split(":", 13)
|
||
|
|
if p.length >= 8
|
||
|
|
MPCorpseRecovery.upsert_corpse(
|
||
|
|
p[1], p[2], p[3], p[4], p[5], p[6], p[7],
|
||
|
|
(p.length >= 9 ? p[8] : nil),
|
||
|
|
(p.length >= 10 ? p[9] : nil),
|
||
|
|
(p.length >= 11 ? p[10] : nil),
|
||
|
|
(p.length >= 12 ? p[11] : nil),
|
||
|
|
(p.length >= 13 ? p[12] : nil)
|
||
|
|
)
|
||
|
|
end
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_remove:")
|
||
|
|
p = text.split(":", 3)
|
||
|
|
MPCorpseRecovery.remove_corpse(p[1]) if p.length >= 2
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_death_ok:")
|
||
|
|
p = text.split(":", 4)
|
||
|
|
MPCorpseRecovery.death_ok(p[1], p[2], (p.length >= 4 ? p[3] : nil)) if p.length >= 3
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_death_error:")
|
||
|
|
code = text.split(":", 2)[1].to_s
|
||
|
|
MPCorpseRecovery.instance_variable_set(:@death_pending, false)
|
||
|
|
MPCorpseRecovery.notify("Труп не создан (#{code}).", :error)
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_claim_error:")
|
||
|
|
MPCorpseRecovery.claim_error(text.split(":", 2)[1].to_s)
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_restore_begin:")
|
||
|
|
MPCorpseRecovery.begin_restore(text.split(":", 2)[1])
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_loot_begin:")
|
||
|
|
MPCorpseRecovery.begin_public_loot(text.split(":", 2)[1])
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if MPCorpseRecovery.public_loot_pending? && text.start_with?("bootstrap_state:")
|
||
|
|
return if MPCorpseRecovery.consume_public_loot_packet(text)
|
||
|
|
end
|
||
|
|
if MPCorpseRecovery.restore_pending? && text.start_with?("bootstrap_state:")
|
||
|
|
return if MPCorpseRecovery.consume_restore_packet(text)
|
||
|
|
end
|
||
|
|
if text == "cloud_save_ok:cloud_corpse_restore"
|
||
|
|
MPCorpseRecovery.cloud_restore_saved
|
||
|
|
# Let the normal CloudOnlySave parser see the acknowledgement too.
|
||
|
|
end
|
||
|
|
if text == "cloud_save_ok:cloud_corpse_public_loot"
|
||
|
|
MPCorpseRecovery.cloud_public_loot_saved
|
||
|
|
# Let the normal CloudOnlySave parser see the acknowledgement too.
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_restore_done:")
|
||
|
|
MPCorpseRecovery.restore_done(text.split(":", 2)[1])
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_loot_done:")
|
||
|
|
MPCorpseRecovery.public_loot_done(text.split(":", 2)[1])
|
||
|
|
return
|
||
|
|
end
|
||
|
|
if text.start_with?("corpse_tutorial_new:")
|
||
|
|
p = text.split(":", 5)
|
||
|
|
if p.length >= 5 && !MPCorpseRecovery.tutorial_bootstrap_consumed?
|
||
|
|
# Do not let a delayed/repeated helper packet re-arm the tutorial.
|
||
|
|
MPCorpseRecovery.mark_new_registration_tutorial(false)
|
||
|
|
MPCorpseRecovery.tutorial_new(p[1], p[2], p[3], p[4])
|
||
|
|
end
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
mp_corpse_recovery_parse(msg)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
#==============================================================================
|
||
|
|
# Tutorial bootstrap is one-shot.
|
||
|
|
#
|
||
|
|
# The stock new_game_setting asks WebSocket.bootstrap_new_character_spawn on
|
||
|
|
# every DataManager.setup_new_game. Tutorial completion itself creates a fresh
|
||
|
|
# NoerSewer game, so leaving the original spawn (TutorialOP/139) alive rewrites
|
||
|
|
# OverMapID back to 139 and the sewer exit sends the player into the tutorial
|
||
|
|
# again. Once the first TutorialOP base exists, keep its position transfer but
|
||
|
|
# stop exposing that spawn to subsequent new-game setup calls.
|
||
|
|
#==============================================================================
|
||
|
|
if defined?(WebSocket)
|
||
|
|
module WebSocket
|
||
|
|
class << self
|
||
|
|
if method_defined?(:bootstrap_new_character_spawn) && !method_defined?(:mp_corpse_bootstrap_new_character_spawn_without_tutorial_once)
|
||
|
|
alias mp_corpse_bootstrap_new_character_spawn_without_tutorial_once bootstrap_new_character_spawn
|
||
|
|
def bootstrap_new_character_spawn
|
||
|
|
if defined?(MPCorpseRecovery) && MPCorpseRecovery.tutorial_bootstrap_consumed?
|
||
|
|
return nil
|
||
|
|
end
|
||
|
|
mp_corpse_bootstrap_new_character_spawn_without_tutorial_once
|
||
|
|
rescue
|
||
|
|
nil
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
if method_defined?(:_bootstrap_apply_new_character_overmap_spawn) && !method_defined?(:mp_corpse_apply_new_character_overmap_spawn_without_tutorial_once)
|
||
|
|
alias mp_corpse_apply_new_character_overmap_spawn_without_tutorial_once _bootstrap_apply_new_character_overmap_spawn
|
||
|
|
def _bootstrap_apply_new_character_overmap_spawn(state)
|
||
|
|
begin
|
||
|
|
if defined?(MPCorpseRecovery) && MPCorpseRecovery.tutorial_bootstrap_consumed? && state.is_a?(Hash) && state['map_id'].to_i == MPCorpseRecovery::TUTORIAL_MAP_ID
|
||
|
|
# Position is still applied by apply_bootstrap_state; only avoid
|
||
|
|
# poisoning OverMapID/LastOverMap* with TutorialOP.
|
||
|
|
return true
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
mp_corpse_apply_new_character_overmap_spawn_without_tutorial_once(state)
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
#==============================================================================
|
||
|
|
# Exact first-registration tutorial base. NewGameTutorialOP in this client is
|
||
|
|
# functionally DataManager.setup_new_game(true, "TutorialOP") + Scene_Map.
|
||
|
|
# We keep the CloudOnly bootstrap flow but create its blank base on TutorialOP
|
||
|
|
# only when the server explicitly answered auth_ok:created.
|
||
|
|
#==============================================================================
|
||
|
|
if defined?(MPCloudOnlySave)
|
||
|
|
module MPCloudOnlySave
|
||
|
|
class << self
|
||
|
|
if method_defined?(:setup_blank_cloud_base) && !method_defined?(:mp_corpse_setup_blank_cloud_base_without_tutorial)
|
||
|
|
alias mp_corpse_setup_blank_cloud_base_without_tutorial setup_blank_cloud_base
|
||
|
|
def setup_blank_cloud_base(tag="cloud_only_base")
|
||
|
|
unless MPCorpseRecovery.new_registration_tutorial?
|
||
|
|
return mp_corpse_setup_blank_cloud_base_without_tutorial(tag)
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
progress_update(0.58, "Подготовка обучения...") if respond_to?(:progress_update)
|
||
|
|
if defined?(MPStateInfra) && MPStateInfra.respond_to?(:with_sync_suppressed)
|
||
|
|
MPStateInfra.with_sync_suppressed(tag) { DataManager.setup_new_game(true, "TutorialOP") }
|
||
|
|
else
|
||
|
|
DataManager.setup_new_game(true, "TutorialOP")
|
||
|
|
end
|
||
|
|
MPCorpseRecovery.finish_new_registration_tutorial
|
||
|
|
progress_update(0.68, "Обучающая карта готова...") if respond_to?(:progress_update)
|
||
|
|
return true
|
||
|
|
rescue => e
|
||
|
|
puts "[CORPSE] TutorialOP base failed: #{e.class}: #{e.message}" rescue nil
|
||
|
|
MPCorpseRecovery.finish_new_registration_tutorial
|
||
|
|
return mp_corpse_setup_blank_cloud_base_without_tutorial(tag)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
#==============================================================================
|
||
|
|
# Game-over integration: capture state before the existing death new-game reset.
|
||
|
|
#==============================================================================
|
||
|
|
if defined?(Scene_Gameover)
|
||
|
|
class Scene_Gameover
|
||
|
|
alias mp_corpse_recovery_start start
|
||
|
|
def start(*args)
|
||
|
|
mp_corpse_recovery_start(*args)
|
||
|
|
@mp_corpse_deferred_restart = false
|
||
|
|
MPCorpseRecovery.submit_death_snapshot
|
||
|
|
end
|
||
|
|
|
||
|
|
alias mp_corpse_recovery_update update
|
||
|
|
def update(*args)
|
||
|
|
mp_corpse_recovery_update(*args)
|
||
|
|
if @mp_corpse_deferred_restart && !MPCorpseRecovery.waiting_death_ack?
|
||
|
|
@mp_corpse_deferred_restart = false
|
||
|
|
mp_corpse_recovery_goto_title
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
alias mp_corpse_recovery_goto_title goto_title
|
||
|
|
def goto_title(*args)
|
||
|
|
if MPCorpseRecovery.waiting_death_ack?
|
||
|
|
@mp_corpse_deferred_restart = true
|
||
|
|
return
|
||
|
|
end
|
||
|
|
mp_corpse_recovery_goto_title(*args)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
#==============================================================================
|
||
|
|
# Death respawn: sewer. TutorialOP is reserved for a truly new server profile.
|
||
|
|
#==============================================================================
|
||
|
|
if defined?(MP_DeathRestart)
|
||
|
|
module MP_DeathRestart
|
||
|
|
class << self
|
||
|
|
alias mp_corpse_original_start_new_game_now start_new_game_now
|
||
|
|
end
|
||
|
|
|
||
|
|
def self.start_new_game_now(scene=nil)
|
||
|
|
begin
|
||
|
|
case rand(3)
|
||
|
|
when 0 then SndLib.sound_OrcSpot(95)
|
||
|
|
when 1 then SndLib.sound_MaleWarriorSpot(95)
|
||
|
|
when 2 then SndLib.sound_UndeadQuestion(95)
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
scene.fadeout_all if scene && scene.respond_to?(:fadeout_all)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
Cache.clear rescue nil
|
||
|
|
|
||
|
|
begin
|
||
|
|
DataManager.setup_new_game(true, "NoerSewer")
|
||
|
|
$titleCreateActorReq = true
|
||
|
|
$hudForceHide = false
|
||
|
|
$balloonForceHide = false
|
||
|
|
begin
|
||
|
|
$game_map.interpreter.new_game_setup
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
SceneManager.prevOptChooseSet(nil)
|
||
|
|
SceneManager.prevTitleOptChooseSet(nil)
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
$game_map.interpreter.change_map_weather_cleaner
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
$game_player.force_update = true
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
begin
|
||
|
|
$game_system.menu_disabled = false
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
clear_autostart
|
||
|
|
begin_resync
|
||
|
|
MPCorpseRecovery.request_post_death_reset_save
|
||
|
|
SceneManager.goto(Scene_Map)
|
||
|
|
return true
|
||
|
|
rescue => e
|
||
|
|
begin
|
||
|
|
msgbox "CorpseRecovery: ошибка респавна в канализации\n#{e.class}: #{e.message}"
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
end
|
||
|
|
false
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
#==============================================================================
|
||
|
|
# Scene_Map corpse markers + interaction.
|
||
|
|
#==============================================================================
|
||
|
|
if defined?(Scene_Map)
|
||
|
|
class Scene_Map
|
||
|
|
alias mp_corpse_recovery_map_start start
|
||
|
|
def start(*args)
|
||
|
|
mp_corpse_recovery_map_start(*args)
|
||
|
|
@mp_corpse_markers = {}
|
||
|
|
@mp_corpse_marker_map_id = nil
|
||
|
|
@mp_corpse_marker_overmap = nil
|
||
|
|
@mp_corpse_overmap_viewport = nil
|
||
|
|
@mp_corpse_save_tick = 0
|
||
|
|
@mp_corpse_top_hud = MPCorpseRecovery::TopHud.new
|
||
|
|
end
|
||
|
|
|
||
|
|
alias mp_corpse_recovery_map_update update
|
||
|
|
def update(*args)
|
||
|
|
mp_corpse_recovery_map_update(*args)
|
||
|
|
mp_corpse_update_markers
|
||
|
|
@mp_corpse_top_hud.update if @mp_corpse_top_hud
|
||
|
|
MPCorpseRecovery.try_claim_nearby
|
||
|
|
MPCorpseRecovery.tick_restore_save
|
||
|
|
MPCorpseRecovery.tick_public_loot_save
|
||
|
|
@mp_corpse_save_tick = @mp_corpse_save_tick.to_i + 1
|
||
|
|
if MPCorpseRecovery.post_death_reset_save_pending? && [45, 90, 150].include?(@mp_corpse_save_tick)
|
||
|
|
MPCorpseRecovery.send_post_death_reset_save
|
||
|
|
end
|
||
|
|
if MPCorpseRecovery.tutorial_initial_save_pending? && [90, 150, 240].include?(@mp_corpse_save_tick)
|
||
|
|
MPCorpseRecovery.send_tutorial_initial_save
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
alias mp_corpse_recovery_map_terminate terminate
|
||
|
|
def terminate(*args)
|
||
|
|
mp_corpse_dispose_markers
|
||
|
|
begin
|
||
|
|
@mp_corpse_top_hud.dispose if @mp_corpse_top_hud
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
@mp_corpse_top_hud = nil
|
||
|
|
mp_corpse_recovery_map_terminate(*args)
|
||
|
|
end
|
||
|
|
|
||
|
|
def mp_corpse_marker_viewport
|
||
|
|
begin
|
||
|
|
# OverMap gets a dedicated high viewport so buildings/events cannot
|
||
|
|
# cover the skull. Normal maps keep the original map viewport.
|
||
|
|
if $game_map && $game_map.respond_to?(:isOverMap) && $game_map.isOverMap
|
||
|
|
if @mp_corpse_overmap_viewport.nil? || @mp_corpse_overmap_viewport.disposed?
|
||
|
|
@mp_corpse_overmap_viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
|
||
|
|
z = 1119
|
||
|
|
begin
|
||
|
|
if defined?(System_Settings) && System_Settings.const_defined?(:MAP_HUD_Z)
|
||
|
|
z = System_Settings::MAP_HUD_Z.to_i - 1
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
@mp_corpse_overmap_viewport.z = z
|
||
|
|
end
|
||
|
|
return @mp_corpse_overmap_viewport
|
||
|
|
end
|
||
|
|
|
||
|
|
spriteset = instance_variable_get(:@spriteset)
|
||
|
|
return spriteset.instance_variable_get(:@viewport1) if spriteset
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
nil
|
||
|
|
end
|
||
|
|
|
||
|
|
def mp_corpse_update_markers
|
||
|
|
@mp_corpse_markers ||= {}
|
||
|
|
|
||
|
|
# Scene_Map survives ordinary map transfers. A corpse can therefore have
|
||
|
|
# the same id first as an OverMap proxy and then as the real local corpse.
|
||
|
|
# Recreate marker sprites whenever map/type changes so the skull moves to
|
||
|
|
# the correct viewport and normal-map labels are restored.
|
||
|
|
current_map_id = ($game_map.map_id.to_i rescue 0)
|
||
|
|
current_overmap = begin
|
||
|
|
!!($game_map && $game_map.respond_to?(:isOverMap) && $game_map.isOverMap)
|
||
|
|
rescue
|
||
|
|
false
|
||
|
|
end
|
||
|
|
if @mp_corpse_marker_map_id != current_map_id || @mp_corpse_marker_overmap != current_overmap
|
||
|
|
mp_corpse_dispose_markers
|
||
|
|
@mp_corpse_marker_map_id = current_map_id
|
||
|
|
@mp_corpse_marker_overmap = current_overmap
|
||
|
|
end
|
||
|
|
|
||
|
|
current = {}
|
||
|
|
MPCorpseRecovery.marker_corpses_for_current_map.each do |corpse|
|
||
|
|
id = corpse["id"].to_i
|
||
|
|
current[id] = true
|
||
|
|
marker = @mp_corpse_markers[id]
|
||
|
|
if marker.nil?
|
||
|
|
marker = MPCorpseRecovery::Marker.new(corpse, mp_corpse_marker_viewport)
|
||
|
|
@mp_corpse_markers[id] = marker
|
||
|
|
end
|
||
|
|
marker.update(corpse)
|
||
|
|
end
|
||
|
|
@mp_corpse_markers.keys.each do |id|
|
||
|
|
next if current[id]
|
||
|
|
begin
|
||
|
|
@mp_corpse_markers[id].dispose
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
@mp_corpse_markers.delete(id)
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
|
||
|
|
def mp_corpse_dispose_markers
|
||
|
|
if @mp_corpse_markers
|
||
|
|
@mp_corpse_markers.each_value do |marker|
|
||
|
|
marker.dispose rescue nil
|
||
|
|
end
|
||
|
|
end
|
||
|
|
@mp_corpse_markers = {}
|
||
|
|
begin
|
||
|
|
if @mp_corpse_overmap_viewport && !@mp_corpse_overmap_viewport.disposed?
|
||
|
|
@mp_corpse_overmap_viewport.dispose
|
||
|
|
end
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
@mp_corpse_overmap_viewport = nil
|
||
|
|
rescue
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|