2272 lines
67 KiB
Ruby
2272 lines
67 KiB
Ruby
require 'zlib'
|
||||
|
|
|
|||
|
|
# Quest progress is spread across Story_Stats and does not have a single
|
|||
|
|
# registry in the base game. Keep the predicate in one place so both the
|
|||
|
|
# cloud serializer and Story_Stats change hook use exactly the same rules.
|
|||
|
|
module MPQuestCloudState
|
|||
|
|
QUEST_KEY_PREFIXES = [
|
|||
|
|
"quprog", "rec", "guild", "unique", "hostage",
|
|||
|
|
"ending_", "endunlock", "recordfirstmission",
|
|||
|
|
"nfl_", "southfl_", "smcloudvillage_", "syb_"
|
|||
|
|
] unless const_defined?(:QUEST_KEY_PREFIXES)
|
|||
|
|
|
|||
|
|
QUEST_EXACT_KEYS = [
|
|||
|
|
"BackStreetArrearsInterest",
|
|||
|
|
"BackStreetArrearsPrepayDateAMT",
|
|||
|
|
"BackStreetArrearsPrincipal",
|
|||
|
|
"BackStreetArrearsWhorePrincipal",
|
|||
|
|
"Captured",
|
|||
|
|
"CapturedStatic",
|
|||
|
|
"Captured_PrisonMiningNeed",
|
|||
|
|
"Captured_PrisonMiningPoint",
|
|||
|
|
"CecilyCoinSupport",
|
|||
|
|
"CoconaFoodSupport",
|
|||
|
|
"DreamPTSD",
|
|||
|
|
"Kidnapping",
|
|||
|
|
"NoerHouseBought",
|
|||
|
|
"LonaCraftHome_noer_shack",
|
|||
|
|
"LonaCraftHome_noer_stonehouse",
|
|||
|
|
"LonaCraftOnlineId",
|
|||
|
|
"LonaCraftOnlineIds",
|
|||
|
|
"LonaCraftChests",
|
|||
|
|
"SlaveOwner"
|
|||
|
|
] unless const_defined?(:QUEST_EXACT_KEYS)
|
|||
|
|
|
|||
|
|
def self.quest_key?(key)
|
|||
|
|
text = key.to_s
|
|||
|
|
return false if text == ""
|
|||
|
|
down = text.downcase
|
|||
|
|
return true if down.include?("quest") || down.include?("mission")
|
|||
|
|
return true if QUEST_KEY_PREFIXES.any? { |prefix| down.start_with?(prefix) }
|
|||
|
|
QUEST_EXACT_KEYS.include?(text)
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
# encoding: UTF-8
|
|||
|
|
#==============================================================================
|
|||
|
|
# 20_sync.rb
|
|||
|
|
#------------------------------------------------------------------------------
|
|||
|
|
# Отправляет на сервер в реальном времени слепок состояния игрока:
|
|||
|
|
# - уровень
|
|||
|
|
# - золото
|
|||
|
|
# - HP / MaxHP
|
|||
|
|
# - предметы, оружие, броня
|
|||
|
|
# - экипировка по слотам
|
|||
|
|
#
|
|||
|
|
# Формат пакета:
|
|||
|
|
# sync_state:<level>:<gold>:<hp>:<max_hp>:<items>:<weapons>:<armors>:<equips>
|
|||
|
|
#==============================================================================
|
|||
|
|
|
|||
|
|
module WebSocket
|
|||
|
|
LIVE_SYNC_INTERVAL = 0.50 unless const_defined?(:LIVE_SYNC_INTERVAL)
|
|||
|
|
LIVE_SYNC_FORCE_INTERVAL = 5.00 unless const_defined?(:LIVE_SYNC_FORCE_INTERVAL)
|
|||
|
|
LIVE_SYNC_PROBE_INTERVAL = 0.20 unless const_defined?(:LIVE_SYNC_PROBE_INTERVAL)
|
|||
|
|
LIVE_SYNC_STATS_BLOB_LIMIT = 32768 unless const_defined?(:LIVE_SYNC_STATS_BLOB_LIMIT)
|
|||
|
|
LIVE_SYNC_AUX_BLOB_LIMIT = 32768 unless const_defined?(:LIVE_SYNC_AUX_BLOB_LIMIT)
|
|||
|
|
LIVE_SYNC_BANK_BLOB_LIMIT = 262144 unless const_defined?(:LIVE_SYNC_BANK_BLOB_LIMIT)
|
|||
|
|
LIVE_SYNC_BODY_BLOB_LIMIT = 262144 unless const_defined?(:LIVE_SYNC_BODY_BLOB_LIMIT)
|
|||
|
|
|
|||
|
|
@live_sync_last_sig = nil
|
|||
|
|
@live_sync_last_at = 0.0
|
|||
|
|
@live_sync_last_force_at = 0.0
|
|||
|
|
@live_sync_last_probe_at = 0.0
|
|||
|
|
|
|||
|
|
def self._live_sync_now
|
|||
|
|
begin
|
|||
|
|
Time.now.to_f
|
|||
|
|
rescue
|
|||
|
|
0.0
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_log(tag, message)
|
|||
|
|
if defined?(MPStateInfra) && MPStateInfra.respond_to?(:log_line)
|
|||
|
|
MPStateInfra.log_line(tag.to_s, message.to_s)
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_hotkey_summary
|
|||
|
|
player = nil
|
|||
|
|
begin
|
|||
|
|
player = $game_player if defined?($game_player)
|
|||
|
|
rescue
|
|||
|
|
player = nil
|
|||
|
|
end
|
|||
|
|
return "player=nil" if player.nil?
|
|||
|
|
names = %w[slot_skill_normal slot_skill_heavy slot_skill_control slot_hotkey_0 slot_hotkey_1 slot_hotkey_2 slot_hotkey_3 slot_hotkey_4 slot_hotkey_other slot_RosterCurrent slot_RosterArray]
|
|||
|
|
out = []
|
|||
|
|
names.each do |name|
|
|||
|
|
begin
|
|||
|
|
value = nil
|
|||
|
|
if player.respond_to?(name)
|
|||
|
|
value = player.send(name)
|
|||
|
|
else
|
|||
|
|
value = player.instance_variable_get(("@" + name).to_sym)
|
|||
|
|
end
|
|||
|
|
if name == "slot_RosterArray" && value.respond_to?(:length)
|
|||
|
|
current = 0
|
|||
|
|
begin
|
|||
|
|
current = player.slot_RosterCurrent.to_i if player.respond_to?(:slot_RosterCurrent)
|
|||
|
|
rescue
|
|||
|
|
current = 0
|
|||
|
|
end
|
|||
|
|
row = nil
|
|||
|
|
begin
|
|||
|
|
row = value[current]
|
|||
|
|
rescue
|
|||
|
|
row = nil
|
|||
|
|
end
|
|||
|
|
value = "len=#{value.length},cur=#{current},row=#{row.inspect}"
|
|||
|
|
end
|
|||
|
|
out << "#{name}=#{value.inspect}"
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
out.join(" ")
|
|||
|
|
rescue
|
|||
|
|
"summary_error"
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_actor
|
|||
|
|
actor = nil
|
|||
|
|
begin
|
|||
|
|
actor = $game_player.actor if $game_player && $game_player.respond_to?(:actor)
|
|||
|
|
rescue
|
|||
|
|
actor = nil
|
|||
|
|
end
|
|||
|
|
if actor.nil?
|
|||
|
|
begin
|
|||
|
|
actor = $game_party.leader if $game_party
|
|||
|
|
rescue
|
|||
|
|
actor = nil
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
actor
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_arena_mode?
|
|||
|
|
begin
|
|||
|
|
return arena_active_runtime? if respond_to?(:arena_active_runtime?)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return !!MP_ArenaFlag.arena_active? if defined?(MP_ArenaFlag) && MP_ArenaFlag.respond_to?(:arena_active?)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
runtime = $mp_arena_runtime_flag
|
|||
|
|
return runtime.to_i == 1 unless runtime.nil?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
false
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_item_count(db_item)
|
|||
|
|
return 0 if db_item.nil?
|
|||
|
|
begin
|
|||
|
|
return $game_party.item_number(db_item).to_i if $game_party && $game_party.respond_to?(:item_number)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_array(arr)
|
|||
|
|
out = {}
|
|||
|
|
return out if arr.nil?
|
|||
|
|
begin
|
|||
|
|
arr.each do |obj|
|
|||
|
|
next if obj.nil?
|
|||
|
|
item_id = 0
|
|||
|
|
begin
|
|||
|
|
item_id = obj.id.to_i
|
|||
|
|
rescue
|
|||
|
|
item_id = 0
|
|||
|
|
end
|
|||
|
|
next if item_id <= 0
|
|||
|
|
qty = _live_sync_item_count(obj)
|
|||
|
|
next if qty <= 0
|
|||
|
|
out[item_id] = qty
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_items
|
|||
|
|
begin
|
|||
|
|
return _live_sync_collect_array($game_party.items)
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_coin3_item
|
|||
|
|
begin
|
|||
|
|
return $data_ItemName["ItemCoin3"] if defined?($data_ItemName) && $data_ItemName && $data_ItemName["ItemCoin3"]
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return $data_items[52] if defined?($data_items) && $data_items
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
nil
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_coin3_count
|
|||
|
|
item = _live_sync_coin3_item
|
|||
|
|
return 0 if item.nil? || !$game_party || !$game_party.respond_to?(:item_number)
|
|||
|
|
$game_party.item_number(item).to_i
|
|||
|
|
rescue
|
|||
|
|
0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_weapons
|
|||
|
|
begin
|
|||
|
|
return _live_sync_collect_array($game_party.weapons)
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_armors
|
|||
|
|
begin
|
|||
|
|
return _live_sync_collect_array($game_party.armors)
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_equip_kind(eq)
|
|||
|
|
return "none" if eq.nil?
|
|||
|
|
begin
|
|||
|
|
return "weapon" if defined?(RPG::Weapon) && eq.is_a?(RPG::Weapon)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "armor" if defined?(RPG::Armor) && eq.is_a?(RPG::Armor)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "weapon" if eq.respond_to?(:is_weapon?) && eq.is_weapon?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "armor" if eq.respond_to?(:is_armor?) && eq.is_armor?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "weapon" if eq.respond_to?(:weapon?) && eq.weapon?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "armor" if eq.respond_to?(:armor?) && eq.armor?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "weapon" if eq.respond_to?(:wtype_id) && !eq.wtype_id.nil?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "armor" if eq.respond_to?(:atype_id) && !eq.atype_id.nil?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
if eq.respond_to?(:etype_id)
|
|||
|
|
etype = eq.etype_id.to_i
|
|||
|
|
return "weapon" if etype == 0
|
|||
|
|
return "armor" if etype > 0
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
klass = ""
|
|||
|
|
begin
|
|||
|
|
klass = eq.class.to_s.downcase
|
|||
|
|
rescue
|
|||
|
|
klass = ""
|
|||
|
|
end
|
|||
|
|
return "weapon" if klass.include?("weapon")
|
|||
|
|
return "armor" if klass.include?("armor")
|
|||
|
|
"item"
|
|||
|
|
rescue
|
|||
|
|
"item"
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_equip_id(eq)
|
|||
|
|
return 0 if eq.nil?
|
|||
|
|
item_id = 0
|
|||
|
|
begin
|
|||
|
|
item_id = eq.id.to_i if eq.respond_to?(:id)
|
|||
|
|
rescue
|
|||
|
|
item_id = 0
|
|||
|
|
end
|
|||
|
|
if item_id <= 0
|
|||
|
|
begin
|
|||
|
|
if eq.respond_to?(:item_name)
|
|||
|
|
raw = eq.item_name.to_s
|
|||
|
|
item_id = raw.to_i
|
|||
|
|
if item_id <= 0 && defined?($data_ItemName) && $data_ItemName
|
|||
|
|
ref = $data_ItemName[raw]
|
|||
|
|
item_id = ref.id.to_i if ref && ref.respond_to?(:id)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
item_id = 0
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
if item_id <= 0
|
|||
|
|
begin
|
|||
|
|
if eq.respond_to?(:name) && defined?($data_ItemName) && $data_ItemName
|
|||
|
|
ref = $data_ItemName[eq.name.to_s]
|
|||
|
|
item_id = ref.id.to_i if ref && ref.respond_to?(:id)
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
item_id = 0 if item_id < 0
|
|||
|
|
item_id
|
|||
|
|
rescue
|
|||
|
|
0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_equip_name(eq)
|
|||
|
|
return "" if eq.nil?
|
|||
|
|
name = ""
|
|||
|
|
begin
|
|||
|
|
name = eq.item_name.to_s if eq.respond_to?(:item_name)
|
|||
|
|
rescue
|
|||
|
|
name = ""
|
|||
|
|
end
|
|||
|
|
if name.to_s.strip == ""
|
|||
|
|
begin
|
|||
|
|
name = eq.name.to_s if eq.respond_to?(:name)
|
|||
|
|
rescue
|
|||
|
|
name = ""
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
text = name.to_s.strip
|
|||
|
|
text = text.gsub(",", ";")
|
|||
|
|
text
|
|||
|
|
rescue
|
|||
|
|
""
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_storage_item_kind(item)
|
|||
|
|
return "" if item.nil?
|
|||
|
|
begin
|
|||
|
|
return "item" if defined?(RPG::Item) && item.is_a?(RPG::Item)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "weapon" if defined?(RPG::Weapon) && item.is_a?(RPG::Weapon)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "armor" if defined?(RPG::Armor) && item.is_a?(RPG::Armor)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "weapon" if item.respond_to?(:is_weapon?) && item.is_weapon?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "armor" if item.respond_to?(:is_armor?) && item.is_armor?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "weapon" if item.respond_to?(:wtype_id) && !item.wtype_id.nil?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return "armor" if item.respond_to?(:atype_id) && !item.atype_id.nil?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
raw_type = item.type.to_i if item.respond_to?(:type)
|
|||
|
|
return "item" if raw_type == 0
|
|||
|
|
return "weapon" if raw_type == 1
|
|||
|
|
return "armor" if raw_type == 2
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
klass = ""
|
|||
|
|
begin
|
|||
|
|
klass = item.class.to_s.downcase
|
|||
|
|
rescue
|
|||
|
|
klass = ""
|
|||
|
|
end
|
|||
|
|
return "weapon" if klass.include?("weapon")
|
|||
|
|
return "armor" if klass.include?("armor")
|
|||
|
|
return "item" if klass.include?("item")
|
|||
|
|
"item"
|
|||
|
|
rescue
|
|||
|
|
""
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_storage_item_id(item)
|
|||
|
|
return 0 if item.nil?
|
|||
|
|
begin
|
|||
|
|
return item.id.to_i if item.respond_to?(:id) && item.id.to_i > 0
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
0
|
|||
|
|
rescue
|
|||
|
|
0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_storage_item_name(item)
|
|||
|
|
return "" if item.nil?
|
|||
|
|
name = ""
|
|||
|
|
begin
|
|||
|
|
name = item.item_name.to_s if item.respond_to?(:item_name)
|
|||
|
|
rescue
|
|||
|
|
name = ""
|
|||
|
|
end
|
|||
|
|
if name.to_s.strip == ""
|
|||
|
|
begin
|
|||
|
|
name = item.name.to_s if item.respond_to?(:name)
|
|||
|
|
rescue
|
|||
|
|
name = ""
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
text = name.to_s.strip
|
|||
|
|
text = text.gsub("\r", " ").gsub("\n", " ").gsub(":", ";").gsub("|", "/")
|
|||
|
|
text
|
|||
|
|
rescue
|
|||
|
|
""
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_bank_storage_id
|
|||
|
|
begin
|
|||
|
|
return System_Settings::STORAGE_BANK.to_i if defined?(System_Settings) && System_Settings.const_defined?(:STORAGE_BANK)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
65533
|
|||
|
|
rescue
|
|||
|
|
65533
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_storage_box(box_id)
|
|||
|
|
out = { "storage_id" => box_id.to_i, "entries" => [] }
|
|||
|
|
return out unless defined?($game_boxes) && $game_boxes && $game_boxes.respond_to?(:box)
|
|||
|
|
box = nil
|
|||
|
|
begin
|
|||
|
|
box = $game_boxes.box(box_id)
|
|||
|
|
rescue
|
|||
|
|
box = nil
|
|||
|
|
end
|
|||
|
|
return out unless box.is_a?(Hash)
|
|||
|
|
|
|||
|
|
box.each do |item, amount|
|
|||
|
|
qty = 0
|
|||
|
|
begin
|
|||
|
|
qty = amount.to_i
|
|||
|
|
rescue
|
|||
|
|
qty = 0
|
|||
|
|
end
|
|||
|
|
next if qty <= 0 || item.nil?
|
|||
|
|
kind = _live_sync_storage_item_kind(item)
|
|||
|
|
item_id = _live_sync_storage_item_id(item)
|
|||
|
|
name = _live_sync_storage_item_name(item)
|
|||
|
|
next if kind.to_s == "" || (item_id <= 0 && name.to_s == "")
|
|||
|
|
out["entries"] << {
|
|||
|
|
"kind" => kind.to_s,
|
|||
|
|
"id" => item_id.to_i,
|
|||
|
|
"name" => name.to_s,
|
|||
|
|
"amount" => qty.to_i
|
|||
|
|
}
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["entries"].sort_by! { |entry| [entry["kind"].to_s, entry["id"].to_i, entry["name"].to_s] }
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{ "storage_id" => box_id.to_i, "entries" => [] }
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_bank_storage
|
|||
|
|
out = _live_sync_collect_storage_box(_live_sync_bank_storage_id)
|
|||
|
|
begin
|
|||
|
|
if defined?(LonaCraft::ChestCloud) && LonaCraft::ChestCloud.respond_to?(:collect_for_bank)
|
|||
|
|
chests = LonaCraft::ChestCloud.collect_for_bank
|
|||
|
|
out["lc_chests"] = chests if chests.is_a?(Array) && !chests.empty?
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{ "storage_id" => _live_sync_bank_storage_id, "entries" => [] }
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_equips(actor)
|
|||
|
|
out = {}
|
|||
|
|
return out if actor.nil?
|
|||
|
|
equips = nil
|
|||
|
|
begin
|
|||
|
|
equips = actor.equips if actor.respond_to?(:equips)
|
|||
|
|
rescue
|
|||
|
|
equips = nil
|
|||
|
|
end
|
|||
|
|
return out if equips.nil?
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
if equips.is_a?(Hash)
|
|||
|
|
equips.each do |slot_key, eq|
|
|||
|
|
slot = slot_key.to_s
|
|||
|
|
next if slot == ""
|
|||
|
|
kind = _live_sync_equip_kind(eq)
|
|||
|
|
item_id = _live_sync_equip_id(eq)
|
|||
|
|
item_name = _live_sync_equip_name(eq)
|
|||
|
|
token = kind.to_s + "," + item_id.to_i.to_s
|
|||
|
|
token += "," + item_name unless item_name.to_s.empty?
|
|||
|
|
out[slot] = token
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
equips.each_with_index do |eq, idx|
|
|||
|
|
kind = _live_sync_equip_kind(eq)
|
|||
|
|
item_id = _live_sync_equip_id(eq)
|
|||
|
|
item_name = _live_sync_equip_name(eq)
|
|||
|
|
token = kind.to_s + "," + item_id.to_i.to_s
|
|||
|
|
token += "," + item_name unless item_name.to_s.empty?
|
|||
|
|
out[idx.to_i] = token
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
out
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
def self._live_sync_skills_csv(actor)
|
|||
|
|
return "" if actor.nil?
|
|||
|
|
skill_ids = []
|
|||
|
|
begin
|
|||
|
|
# actor.skills also contains temporary equipment/state grants.
|
|||
|
|
# Only persist the actor's learned skills.
|
|||
|
|
raw = actor.instance_variable_get(:@skills)
|
|||
|
|
if raw.is_a?(Array)
|
|||
|
|
raw.each do |sid|
|
|||
|
|
begin
|
|||
|
|
sid_i = sid.to_i
|
|||
|
|
skill_ids << sid_i if sid_i > 0
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
skill_ids = skill_ids.uniq.sort
|
|||
|
|
skill_ids.join(",")
|
|||
|
|
rescue
|
|||
|
|
""
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_sanitize_json_value(value)
|
|||
|
|
return value if value.nil? || value.is_a?(Numeric) || value == true || value == false
|
|||
|
|
if value.is_a?(String)
|
|||
|
|
s = value.dup
|
|||
|
|
begin
|
|||
|
|
s.force_encoding("UTF-8")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
return s
|
|||
|
|
end
|
|||
|
|
if value.is_a?(Symbol)
|
|||
|
|
return value.to_s
|
|||
|
|
end
|
|||
|
|
if value.is_a?(Array)
|
|||
|
|
return value.map { |vv| _live_sync_sanitize_json_value(vv) }
|
|||
|
|
end
|
|||
|
|
if value.is_a?(Hash)
|
|||
|
|
out = {}
|
|||
|
|
value.each do |kk, vv|
|
|||
|
|
out[kk.to_s] = _live_sync_sanitize_json_value(vv)
|
|||
|
|
end
|
|||
|
|
return out
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return value.to_i if value.respond_to?(:to_i) && value.to_i.to_s == value.to_s
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
return value.to_f if value.respond_to?(:to_f) && value.to_f.to_s == value.to_s
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
value.to_s
|
|||
|
|
rescue
|
|||
|
|
value.to_s
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_json_escape(value)
|
|||
|
|
s = value.to_s
|
|||
|
|
begin
|
|||
|
|
s.force_encoding("UTF-8")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
# Never use a replacement string for backslashes here. Ruby interprets
|
|||
|
|
# backslashes in String#gsub replacements a second time, so the previous
|
|||
|
|
# gsub("\\", "\\\\") could leave Lona control codes such as \} in the
|
|||
|
|
# generated JSON. Jackson then rejects the whole cloud-save packet with
|
|||
|
|
# "Unrecognized character escape '}'". A block returns the exact bytes.
|
|||
|
|
s = s.gsub(/["\\\x00-\x1f]/) do |char|
|
|||
|
|
case char
|
|||
|
|
when '"' then '\\"'
|
|||
|
|
when '\\' then '\\\\'
|
|||
|
|
when "\b" then '\\b'
|
|||
|
|
when "\f" then '\\f'
|
|||
|
|
when "\n" then '\\n'
|
|||
|
|
when "\r" then '\\r'
|
|||
|
|
when "\t" then '\\t'
|
|||
|
|
else "\\u%04x" % char.ord
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
"\"" + s + "\""
|
|||
|
|
rescue
|
|||
|
|
"\"\""
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_json_generate(value)
|
|||
|
|
return "null" if value.nil?
|
|||
|
|
return "true" if value == true
|
|||
|
|
return "false" if value == false
|
|||
|
|
if value.is_a?(Numeric)
|
|||
|
|
text = value.to_s
|
|||
|
|
return "0" if text =~ /nan|inf/i
|
|||
|
|
return text
|
|||
|
|
end
|
|||
|
|
return _live_sync_json_escape(value.to_s) if value.is_a?(String) || value.is_a?(Symbol)
|
|||
|
|
if value.is_a?(Array)
|
|||
|
|
return "[" + value.map { |vv| _live_sync_json_generate(vv) }.join(",") + "]"
|
|||
|
|
end
|
|||
|
|
if value.is_a?(Hash)
|
|||
|
|
keys = []
|
|||
|
|
begin
|
|||
|
|
keys = value.keys.sort_by { |k| k.to_s }
|
|||
|
|
rescue
|
|||
|
|
keys = value.keys
|
|||
|
|
end
|
|||
|
|
pairs = []
|
|||
|
|
keys.each do |key|
|
|||
|
|
pairs << (_live_sync_json_escape(key.to_s) + ":" + _live_sync_json_generate(value[key]))
|
|||
|
|
end
|
|||
|
|
return "{" + pairs.join(",") + "}"
|
|||
|
|
end
|
|||
|
|
_live_sync_json_escape(value.to_s)
|
|||
|
|
rescue
|
|||
|
|
"null"
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_stats(actor)
|
|||
|
|
out = {}
|
|||
|
|
return out if actor.nil?
|
|||
|
|
begin
|
|||
|
|
act_stat = actor.instance_variable_get(:@actStat)
|
|||
|
|
raw = act_stat.stat if act_stat && act_stat.respond_to?(:stat)
|
|||
|
|
if raw.is_a?(Hash)
|
|||
|
|
raw.each do |kk, vv|
|
|||
|
|
key = kk.to_s
|
|||
|
|
next if key.nil? || key == ""
|
|||
|
|
if vv.is_a?(Array)
|
|||
|
|
out[key] = _live_sync_sanitize_json_value(vv[0])
|
|||
|
|
else
|
|||
|
|
out[key] = _live_sync_sanitize_json_value(vv)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
act_stat = actor.instance_variable_get(:@actStat)
|
|||
|
|
raw = act_stat.stat if act_stat && act_stat.respond_to?(:stat)
|
|||
|
|
out["act_stat_full"] = _live_sync_sanitize_json_value(raw) if raw.is_a?(Hash)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["trait_point"] = actor.trait_point.to_i if actor.respond_to?(:trait_point)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["actor_class_id"] = actor.instance_variable_get(:@class_id).to_i
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["actor_exp"] = _live_sync_sanitize_json_value(actor.instance_variable_get(:@exp))
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["actor_skills"] = _live_sync_sanitize_json_value(actor.instance_variable_get(:@skills))
|
|||
|
|
out["learned_skills_version"] = actor.instance_variable_get(:@mp_learned_skills_version).to_i
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
# Quest progress used to live only in the separately requested body blob.
|
|||
|
|
# Keep an authoritative copy in the atomic stats row as well. Bootstrap
|
|||
|
|
# applies this ledger last, after any legacy/stale body response.
|
|||
|
|
begin
|
|||
|
|
if defined?(MP_Save14) && MP_Save14.respond_to?(:collect_progression_ledger)
|
|||
|
|
ledger = MP_Save14.collect_progression_ledger
|
|||
|
|
out["progression_ledger"] = _live_sync_sanitize_json_value(ledger) if ledger.is_a?(Hash)
|
|||
|
|
out["progression_ledger_version"] = 1
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
# Race and registered cosmetic values are portrait state in LonaRPG, not
|
|||
|
|
# actStat values. Keep the registry generic so appearance mods can opt in.
|
|||
|
|
begin
|
|||
|
|
portrait = actor.respond_to?(:portrait_stat_value) ? actor.portrait_stat_value : actor.instance_variable_get(:@prt_stat)
|
|||
|
|
identity = {}
|
|||
|
|
if portrait.is_a?(Hash)
|
|||
|
|
portrait.each do |raw_key, raw_value|
|
|||
|
|
key = raw_key.to_s
|
|||
|
|
persistent_mod_key = defined?(MPPortraitPersistence) && MPPortraitPersistence.key?(key)
|
|||
|
|
next unless key.downcase.include?("race") || persistent_mod_key
|
|||
|
|
identity[key] = _live_sync_sanitize_json_value(raw_value)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
out["portrait_identity"] = identity unless identity.empty?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["hp"] = actor.hp.to_i if actor.respond_to?(:hp)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["max_hp"] = actor.mhp.to_i if actor.respond_to?(:mhp)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["level"] = actor.level.to_i if actor.respond_to?(:level)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
journal = _live_sync_collect_journal(actor)
|
|||
|
|
out["player_journal"] = journal if journal.is_a?(Hash)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
# Титул (простолюдинка / наёмница / верующая…) живёт в attr_accessor
|
|||
|
|
# actor.record_lona_title и не попадает в actStat/portrait автоматически.
|
|||
|
|
begin
|
|||
|
|
if actor.respond_to?(:record_lona_title)
|
|||
|
|
title = actor.record_lona_title
|
|||
|
|
out["record_lona_title"] = title.to_s unless title.nil?
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_states(actor)
|
|||
|
|
out = {}
|
|||
|
|
return out if actor.nil?
|
|||
|
|
begin
|
|||
|
|
state_ids = []
|
|||
|
|
if actor.respond_to?(:states)
|
|||
|
|
actor.states.each do |st|
|
|||
|
|
next if st.nil?
|
|||
|
|
begin
|
|||
|
|
sid = st.id.to_i
|
|||
|
|
state_ids << sid if sid > 0
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
# @states intentionally contains duplicate IDs: each duplicate is one
|
|||
|
|
# stack. Keep both the duplicate-preserving array and an explicit count
|
|||
|
|
# map. The latter is unambiguous while the former remains compatible
|
|||
|
|
# with readers that only understand `states`.
|
|||
|
|
out["states"] = state_ids.sort
|
|||
|
|
stacks = {}
|
|||
|
|
state_ids.each { |sid| stacks[sid.to_s] = stacks.fetch(sid.to_s, 0).to_i + 1 }
|
|||
|
|
out["state_stacks"] = stacks
|
|||
|
|
out["state_stack_version"] = 1
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["state_steps"] = _live_sync_sanitize_json_value(actor.instance_variable_get(:@state_steps))
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["state_frames"] = _live_sync_sanitize_json_value(actor.instance_variable_get(:@state_frames))
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["buffs"] = _live_sync_sanitize_json_value(actor.instance_variable_get(:@buffs))
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["buff_turns"] = _live_sync_sanitize_json_value(actor.instance_variable_get(:@buff_turns))
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
LIVE_SYNC_BODY_KEYWORDS = [
|
|||
|
|
"sex", "rape", "fuck", "vag", "vagina", "anal", "anus", "ass",
|
|||
|
|
"mouth", "oral", "kiss", "breast", "boob", "milk", "lact", "nippl",
|
|||
|
|
"cum", "semen", "sperm", "preg", "birth", "baby", "uter", "ovul",
|
|||
|
|
"menses", "menstru", "period", "arousal", "sensitivity", "virgin",
|
|||
|
|
"hymen", "urinary", "urine", "defec", "slave", "morality", "karma",
|
|||
|
|
"fame", "reputation", "relation", "favor", "affection"
|
|||
|
|
] unless const_defined?(:LIVE_SYNC_BODY_KEYWORDS)
|
|||
|
|
|
|||
|
|
def self._live_sync_body_key?(key)
|
|||
|
|
text = key.to_s.downcase
|
|||
|
|
return false if text == ""
|
|||
|
|
LIVE_SYNC_BODY_KEYWORDS.any? { |word| text.include?(word) }
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_body_safe_value(value, depth = 0)
|
|||
|
|
return nil if depth.to_i > 4
|
|||
|
|
return value if value.nil? || value.is_a?(Numeric) || value == true || value == false
|
|||
|
|
if value.is_a?(String)
|
|||
|
|
s = value.dup
|
|||
|
|
begin
|
|||
|
|
s.force_encoding("UTF-8")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
return s[0, 4096]
|
|||
|
|
end
|
|||
|
|
return value.to_s if value.is_a?(Symbol)
|
|||
|
|
if value.is_a?(Array)
|
|||
|
|
out = []
|
|||
|
|
value.first(256).each do |entry|
|
|||
|
|
safe = _live_sync_body_safe_value(entry, depth.to_i + 1)
|
|||
|
|
out << safe unless safe.nil?
|
|||
|
|
end
|
|||
|
|
return out
|
|||
|
|
end
|
|||
|
|
if value.is_a?(Hash)
|
|||
|
|
out = {}
|
|||
|
|
value.each do |raw_key, raw_value|
|
|||
|
|
break if out.length >= 512
|
|||
|
|
key = raw_key.to_s
|
|||
|
|
next if key == ""
|
|||
|
|
safe = _live_sync_body_safe_value(raw_value, depth.to_i + 1)
|
|||
|
|
out[key] = safe unless safe.nil?
|
|||
|
|
end
|
|||
|
|
return out
|
|||
|
|
end
|
|||
|
|
nil
|
|||
|
|
rescue
|
|||
|
|
nil
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_body_stats(actor)
|
|||
|
|
out = {}
|
|||
|
|
return out if actor.nil?
|
|||
|
|
begin
|
|||
|
|
act_stat = actor.instance_variable_get(:@actStat)
|
|||
|
|
raw = act_stat.stat if act_stat && act_stat.respond_to?(:stat)
|
|||
|
|
if raw.is_a?(Hash)
|
|||
|
|
raw.each do |raw_key, raw_value|
|
|||
|
|
key = raw_key.to_s
|
|||
|
|
next unless _live_sync_body_key?(key)
|
|||
|
|
safe = _live_sync_body_safe_value(raw_value)
|
|||
|
|
out[key] = safe unless safe.nil?
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_story_body
|
|||
|
|
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|
|
|||
|
|
break if out.length >= 2048
|
|||
|
|
key = raw_key.to_s
|
|||
|
|
next unless _live_sync_body_key?(key) ||
|
|||
|
|
(defined?(MPQuestCloudState) && MPQuestCloudState.quest_key?(key))
|
|||
|
|
safe = _live_sync_body_safe_value(raw_value)
|
|||
|
|
out[key] = safe unless safe.nil?
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_body_ivars(obj)
|
|||
|
|
out = {}
|
|||
|
|
return out if obj.nil?
|
|||
|
|
vars = []
|
|||
|
|
begin
|
|||
|
|
vars = obj.instance_variables
|
|||
|
|
rescue
|
|||
|
|
vars = []
|
|||
|
|
end
|
|||
|
|
vars.each do |ivar|
|
|||
|
|
key = ivar.to_s
|
|||
|
|
next unless _live_sync_body_key?(key)
|
|||
|
|
begin
|
|||
|
|
safe = _live_sync_body_safe_value(obj.instance_variable_get(ivar))
|
|||
|
|
out[key] = safe unless safe.nil?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_body(actor)
|
|||
|
|
out = { "schema" => 2 }
|
|||
|
|
body_stats = _live_sync_collect_body_stats(actor)
|
|||
|
|
story_stats = _live_sync_collect_story_body
|
|||
|
|
actor_ivars = _live_sync_collect_body_ivars(actor)
|
|||
|
|
player_ivars = _live_sync_collect_body_ivars($game_player)
|
|||
|
|
out["body_stats"] = body_stats unless body_stats.empty?
|
|||
|
|
out["story_stats"] = story_stats unless story_stats.empty?
|
|||
|
|
out["actor_ivars"] = actor_ivars unless actor_ivars.empty?
|
|||
|
|
out["player_ivars"] = player_ivars unless player_ivars.empty?
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{ "schema" => 2 }
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_player_meta(actor)
|
|||
|
|
out = {}
|
|||
|
|
begin
|
|||
|
|
unless _live_sync_arena_mode?
|
|||
|
|
begin
|
|||
|
|
out["map_id"] = ($game_map ? $game_map.map_id.to_i : 0)
|
|||
|
|
rescue
|
|||
|
|
out["map_id"] = 0
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
if $game_player
|
|||
|
|
out["x"] = $game_player.x.to_i
|
|||
|
|
out["y"] = $game_player.y.to_i
|
|||
|
|
out["direction"] = $game_player.direction.to_i
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
if $game_player
|
|||
|
|
%w[slot_skill_normal slot_skill_heavy slot_skill_control slot_hotkey_0 slot_hotkey_1 slot_hotkey_2 slot_hotkey_3 slot_hotkey_4 slot_hotkey_other slot_RosterCurrent slot_RosterArray].each do |name|
|
|||
|
|
if $game_player.respond_to?(name)
|
|||
|
|
begin
|
|||
|
|
out[name] = _live_sync_sanitize_json_value($game_player.send(name))
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
begin
|
|||
|
|
iv = $game_player.instance_variable_get(('@' + name).to_sym)
|
|||
|
|
out[name] = _live_sync_sanitize_json_value(iv) unless iv.nil?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
exp = actor.instance_variable_get(:@exp) if actor
|
|||
|
|
out["exp"] = _live_sync_sanitize_json_value(exp) if exp
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
# Quick-use slots ext-1..ext-5 (Menu_Equips) — имена предметов, не объекты.
|
|||
|
|
begin
|
|||
|
|
if actor && actor.respond_to?(:ext_items)
|
|||
|
|
raw = actor.ext_items
|
|||
|
|
if raw.is_a?(Array)
|
|||
|
|
slots = Array.new(5)
|
|||
|
|
5.times do |i|
|
|||
|
|
v = raw[i]
|
|||
|
|
next if v.nil?
|
|||
|
|
s = v.to_s.strip
|
|||
|
|
next if s.empty? || s == "nil"
|
|||
|
|
slots[i] = s
|
|||
|
|
end
|
|||
|
|
out["ext_items"] = slots
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_blob_from_object(obj, limit=nil, label=nil)
|
|||
|
|
return "" if obj.nil?
|
|||
|
|
json = ""
|
|||
|
|
begin
|
|||
|
|
json = JSON.generate(obj) if defined?(JSON) && JSON.respond_to?(:generate)
|
|||
|
|
rescue
|
|||
|
|
json = ""
|
|||
|
|
end
|
|||
|
|
if json.to_s.empty?
|
|||
|
|
begin
|
|||
|
|
json = obj.to_json
|
|||
|
|
rescue
|
|||
|
|
json = ""
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
if json.to_s.empty?
|
|||
|
|
begin
|
|||
|
|
json = _live_sync_json_generate(obj)
|
|||
|
|
rescue
|
|||
|
|
json = ""
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
_live_sync_log("live_sync_json_empty", "#{label || 'blob'} keys=#{obj.keys.join(',') rescue 'n/a'}") if json.to_s.empty?
|
|||
|
|
return "" if json.to_s.empty?
|
|||
|
|
packed = ""
|
|||
|
|
begin
|
|||
|
|
packed = Zlib::Deflate.deflate(json.to_s, Zlib::BEST_SPEED)
|
|||
|
|
rescue
|
|||
|
|
packed = json.to_s
|
|||
|
|
end
|
|||
|
|
hex = ""
|
|||
|
|
begin
|
|||
|
|
hex = packed.unpack('H*')[0].to_s
|
|||
|
|
rescue
|
|||
|
|
hex = ""
|
|||
|
|
end
|
|||
|
|
if limit && limit.to_i > 0 && hex.length > limit.to_i
|
|||
|
|
_live_sync_log("live_sync_blob_oversize", "#{label || 'blob'} hex=#{hex.length} limit=#{limit.to_i}")
|
|||
|
|
return ""
|
|||
|
|
end
|
|||
|
|
hex
|
|||
|
|
rescue
|
|||
|
|
""
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_pack_hash(h)
|
|||
|
|
return "" unless h.is_a?(Hash)
|
|||
|
|
keys = []
|
|||
|
|
begin
|
|||
|
|
keys = h.keys.sort
|
|||
|
|
rescue
|
|||
|
|
keys = h.keys
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
out = []
|
|||
|
|
keys.each do |k|
|
|||
|
|
next if k.nil?
|
|||
|
|
key = k.to_s.gsub(":", ";").gsub("|", "/").gsub("=", "-")
|
|||
|
|
val = h[k]
|
|||
|
|
val = "0" if val.nil?
|
|||
|
|
value = val.to_s.gsub(":", ";").gsub("|", "/").gsub("=", "-")
|
|||
|
|
out << (key + "=" + value)
|
|||
|
|
end
|
|||
|
|
out.join("|")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
# Full stats dump duplicates every attribute as a flat value and again inside
|
|||
|
|
# act_stat_full, then adds the quest ledger. Past the wire limit the old
|
|||
|
|
# code sent an empty blob, so login kept the level and snapped experience
|
|||
|
|
# to that level's floor. Never drop experience or spent trait points.
|
|||
|
|
LIVE_SYNC_TRAIT_KEYS = %w[
|
|||
|
|
combat_trait scoutcraft_trait wisdom_trait survival_trait constitution_trait
|
|||
|
|
] unless const_defined?(:LIVE_SYNC_TRAIT_KEYS)
|
|||
|
|
|
|||
|
|
# Body/need meters that must survive stats_core / stats_keepers truncation.
|
|||
|
|
# Distinct from the Lactation state buff (actor.stat["Lactation"]).
|
|||
|
|
LIVE_SYNC_BODY_METER_KEYS = %w[
|
|||
|
|
arousal lactation_level urinary_level defecate_level
|
|||
|
|
dirt mood sat sta health baby_health
|
|||
|
|
pee_request poo_request itch_level
|
|||
|
|
] unless const_defined?(:LIVE_SYNC_BODY_METER_KEYS)
|
|||
|
|
|
|||
|
|
LIVE_SYNC_REPRO_IVARS = %w[
|
|||
|
|
@menses_schedule @status_log @prev_menses_schedule @prev_status_log
|
|||
|
|
@prev_preg_rates @currentDay @preg_day @preg_race @preg_cycle @preg_level
|
|||
|
|
@forcePreg @labor_date @preg_date @preg_rate @preg_rates @current_log_no
|
|||
|
|
@cycle_start @baby_race @baby_birth_dialog @pain_value_preg @puke_value_preg
|
|||
|
|
] unless const_defined?(:LIVE_SYNC_REPRO_IVARS)
|
|||
|
|
|
|||
|
|
LIVE_SYNC_INTIMATE_STATS = %w[preg vag_damage anal_damage] unless const_defined?(:LIVE_SYNC_INTIMATE_STATS)
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_mails
|
|||
|
|
system = defined?($game_system) ? $game_system : nil
|
|||
|
|
mails = system ? system.instance_variable_get(:@mails) : nil
|
|||
|
|
return [] unless mails.is_a?(Hash)
|
|||
|
|
out = []
|
|||
|
|
mails.each do |symbol, mail|
|
|||
|
|
next if mail.nil?
|
|||
|
|
date = mail.instance_variable_get(:@date) rescue nil
|
|||
|
|
out << {
|
|||
|
|
"symbol" => symbol.to_s,
|
|||
|
|
"state" => (mail.instance_variable_get(:@state) || "unread").to_s,
|
|||
|
|
"deleted" => !!mail.instance_variable_get(:@deleted),
|
|||
|
|
"attachments_claimed" => !!mail.instance_variable_get(:@attachments_claimed),
|
|||
|
|
"date" => (date.respond_to?(:to_i) ? date.to_i : 0)
|
|||
|
|
}
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
[]
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_reproduction(actor)
|
|||
|
|
out = {}
|
|||
|
|
return out if actor.nil?
|
|||
|
|
LIVE_SYNC_REPRO_IVARS.each do |name|
|
|||
|
|
value = actor.instance_variable_get(name.to_sym) rescue nil
|
|||
|
|
next if value.nil?
|
|||
|
|
out[name] = _live_sync_sanitize_json_value(value)
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_sex_records
|
|||
|
|
story = defined?($story_stats) ? $story_stats : nil
|
|||
|
|
data = story.respond_to?(:data) ? story.data : nil
|
|||
|
|
return {} unless data.is_a?(Hash)
|
|||
|
|
out = {}
|
|||
|
|
data.each do |raw_key, raw_value|
|
|||
|
|
key = raw_key.to_s
|
|||
|
|
next if key.empty?
|
|||
|
|
next unless key.start_with?("sex_record_") ||
|
|||
|
|
key == "record_giveup_PeePoo" || key == "record_Rebirth" ||
|
|||
|
|
key == "record_CoconaVag" || key == "record_CoconaOgrasm" || key == "record_CoconaPeeWith"
|
|||
|
|
safe = _live_sync_sanitize_json_value(raw_value)
|
|||
|
|
out[key] = safe unless safe.nil?
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_intimate_stats(actor)
|
|||
|
|
out = {}
|
|||
|
|
return out if actor.nil?
|
|||
|
|
act_stat = actor.instance_variable_get(:@actStat) rescue nil
|
|||
|
|
return out unless act_stat && act_stat.respond_to?(:get_stat)
|
|||
|
|
LIVE_SYNC_INTIMATE_STATS.each do |key|
|
|||
|
|
begin
|
|||
|
|
out[key] = act_stat.get_stat(key)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
out["baby_health"] = act_stat.get_stat("baby_health")
|
|||
|
|
out["baby_health_max"] = act_stat.get_stat("baby_health", 2)
|
|||
|
|
out["displayBabyHealth"] = act_stat.get_stat("displayBabyHealth")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
out
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_cums(actor)
|
|||
|
|
return {} if actor.nil?
|
|||
|
|
meters = actor.instance_variable_get(:@cumsMeters) rescue nil
|
|||
|
|
vag = actor.instance_variable_get(:@vag_cums) rescue nil
|
|||
|
|
out_meters = {}
|
|||
|
|
if meters.is_a?(Hash)
|
|||
|
|
meters.each do |key, amount|
|
|||
|
|
name = key.to_s
|
|||
|
|
next if name.empty?
|
|||
|
|
out_meters[name] = amount.to_i
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
out_vag = []
|
|||
|
|
if vag.is_a?(Array)
|
|||
|
|
vag.each do |cum|
|
|||
|
|
next if cum.nil?
|
|||
|
|
out_vag << {
|
|||
|
|
"part" => cum.respond_to?(:part) ? cum.part.to_s : "",
|
|||
|
|
"race" => cum.respond_to?(:race) ? cum.race.to_s : "",
|
|||
|
|
"amt" => cum.respond_to?(:amt) ? cum.amt.to_i : 0,
|
|||
|
|
"sort" => cum.respond_to?(:sort) ? cum.sort.to_i : 0
|
|||
|
|
}
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
display = actor.respond_to?(:getDisplayCumsAmt) ? actor.getDisplayCumsAmt : {}
|
|||
|
|
{
|
|||
|
|
"meters" => out_meters,
|
|||
|
|
"vag" => out_vag,
|
|||
|
|
"number" => (actor.instance_variable_get(:@cumsNumber) rescue 0).to_i,
|
|||
|
|
"body" => display.is_a?(Hash) ? display["body"].to_i : 0,
|
|||
|
|
"vag_amt" => display.is_a?(Hash) ? display["vag"].to_i : 0,
|
|||
|
|
"anal" => display.is_a?(Hash) ? display["anal"].to_i : 0
|
|||
|
|
}
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_collect_journal(actor)
|
|||
|
|
{
|
|||
|
|
"mails" => _live_sync_collect_mails,
|
|||
|
|
"reproduction" => _live_sync_collect_reproduction(actor),
|
|||
|
|
"sex_records" => _live_sync_collect_sex_records,
|
|||
|
|
"intimate_stats" => _live_sync_collect_intimate_stats(actor),
|
|||
|
|
"cums" => _live_sync_collect_cums(actor)
|
|||
|
|
}
|
|||
|
|
rescue
|
|||
|
|
{}
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_merge_body_meters(target, full)
|
|||
|
|
return target unless target.is_a?(Hash) && full.is_a?(Hash)
|
|||
|
|
LIVE_SYNC_BODY_METER_KEYS.each do |key|
|
|||
|
|
target[key] = full[key] if full.has_key?(key)
|
|||
|
|
end
|
|||
|
|
raw_full = full["act_stat_full"]
|
|||
|
|
if raw_full.is_a?(Hash)
|
|||
|
|
merged = target["act_stat_full"].is_a?(Hash) ? target["act_stat_full"].dup : {}
|
|||
|
|
LIVE_SYNC_BODY_METER_KEYS.each do |key|
|
|||
|
|
merged[key] = raw_full[key] if raw_full.has_key?(key)
|
|||
|
|
end
|
|||
|
|
target["act_stat_full"] = merged unless merged.empty?
|
|||
|
|
end
|
|||
|
|
target
|
|||
|
|
rescue
|
|||
|
|
target
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_stats_core(full)
|
|||
|
|
core = {}
|
|||
|
|
return core unless full.is_a?(Hash)
|
|||
|
|
# morality_lona is the permanent reputation counter. The menu value and
|
|||
|
|
# morality_plus are rebuilt from states and equipment, so a temporary
|
|||
|
|
# MoralityDown30 must not become the saved number.
|
|||
|
|
# record_lona_title — постоянный титул персонажа (не пересобирается из состояний).
|
|||
|
|
%w[trait_point actor_class_id actor_exp actor_skills learned_skills_version level portrait_identity player_journal morality_lona record_lona_title mp_trait_budget_fix_v1].each do |key|
|
|||
|
|
core[key] = full[key] if full.has_key?(key)
|
|||
|
|
end
|
|||
|
|
LIVE_SYNC_TRAIT_KEYS.each do |key|
|
|||
|
|
core[key] = full[key] if full.has_key?(key)
|
|||
|
|
end
|
|||
|
|
raw_full = full["act_stat_full"]
|
|||
|
|
if raw_full.is_a?(Hash)
|
|||
|
|
traits = {}
|
|||
|
|
LIVE_SYNC_TRAIT_KEYS.each do |key|
|
|||
|
|
traits[key] = raw_full[key] if raw_full.has_key?(key)
|
|||
|
|
end
|
|||
|
|
core["act_stat_full"] = traits unless traits.empty?
|
|||
|
|
end
|
|||
|
|
_live_sync_merge_body_meters(core, full)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
# Last resort when the portrait palette and the flat stat table no longer
|
|||
|
|
# fit. Experience, spent traits, notes, the cycle calendar and intimate
|
|||
|
|
# history stay. Appearance remains in any earlier snapshot that still fit.
|
|||
|
|
def self._live_sync_stats_keepers(full)
|
|||
|
|
keepers = {}
|
|||
|
|
return keepers unless full.is_a?(Hash)
|
|||
|
|
%w[trait_point actor_class_id actor_exp actor_skills learned_skills_version level player_journal morality_lona record_lona_title mp_trait_budget_fix_v1].each do |key|
|
|||
|
|
keepers[key] = full[key] if full.has_key?(key)
|
|||
|
|
end
|
|||
|
|
LIVE_SYNC_TRAIT_KEYS.each do |key|
|
|||
|
|
keepers[key] = full[key] if full.has_key?(key)
|
|||
|
|
end
|
|||
|
|
_live_sync_merge_body_meters(keepers, full)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_stats_blob(actor)
|
|||
|
|
full = _live_sync_collect_stats(actor)
|
|||
|
|
blob = _live_sync_blob_from_object(full, LIVE_SYNC_STATS_BLOB_LIMIT, "stats")
|
|||
|
|
if blob.to_s.empty?
|
|||
|
|
trimmed = {}
|
|||
|
|
if full.is_a?(Hash)
|
|||
|
|
full.each do |key, value|
|
|||
|
|
name = key.to_s
|
|||
|
|
next if name == "act_stat_full" || name == "progression_ledger" || name == "hp" || name == "max_hp"
|
|||
|
|
trimmed[key] = value
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
blob = _live_sync_blob_from_object(trimmed, LIVE_SYNC_STATS_BLOB_LIMIT, "stats_trimmed")
|
|||
|
|
end
|
|||
|
|
if blob.to_s.empty?
|
|||
|
|
core = _live_sync_stats_core(full)
|
|||
|
|
blob = _live_sync_blob_from_object(core, LIVE_SYNC_STATS_BLOB_LIMIT, "stats_core")
|
|||
|
|
_live_sync_log("live_sync_stats_core_only", "keys=#{core.keys.join(',')}") unless blob.to_s.empty?
|
|||
|
|
end
|
|||
|
|
if blob.to_s.empty?
|
|||
|
|
keepers = _live_sync_stats_keepers(full)
|
|||
|
|
blob = _live_sync_blob_from_object(keepers, LIVE_SYNC_STATS_BLOB_LIMIT, "stats_keepers")
|
|||
|
|
_live_sync_log("live_sync_stats_keepers_only", "keys=#{keepers.keys.join(',')}") unless blob.to_s.empty?
|
|||
|
|
end
|
|||
|
|
blob.to_s
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self._live_sync_build_packet
|
|||
|
|
actor = _live_sync_actor
|
|||
|
|
return nil if actor.nil?
|
|||
|
|
return nil if _live_sync_arena_mode?
|
|||
|
|
|
|||
|
|
level = 1
|
|||
|
|
hp = 0
|
|||
|
|
max_hp = 0
|
|||
|
|
gold = 0
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
level = actor.level.to_i if actor.respond_to?(:level)
|
|||
|
|
rescue
|
|||
|
|
level = 1
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
hp = actor.hp.to_i if actor.respond_to?(:hp)
|
|||
|
|
rescue
|
|||
|
|
hp = 0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
max_hp = actor.mhp.to_i if actor.respond_to?(:mhp)
|
|||
|
|
rescue
|
|||
|
|
begin
|
|||
|
|
max_hp = actor.maxhp.to_i if actor.respond_to?(:maxhp)
|
|||
|
|
rescue
|
|||
|
|
max_hp = hp
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
gold = _live_sync_coin3_count
|
|||
|
|
|
|||
|
|
items_blob = _live_sync_pack_hash(_live_sync_collect_items)
|
|||
|
|
weapons_blob = _live_sync_pack_hash(_live_sync_collect_weapons)
|
|||
|
|
armors_blob = _live_sync_pack_hash(_live_sync_collect_armors)
|
|||
|
|
equips_blob = _live_sync_pack_hash(_live_sync_collect_equips(actor))
|
|||
|
|
skills_csv = _live_sync_skills_csv(actor)
|
|||
|
|
stats_blob = _live_sync_stats_blob(actor)
|
|||
|
|
states_blob = _live_sync_blob_from_object(_live_sync_collect_states(actor), LIVE_SYNC_AUX_BLOB_LIMIT, "states")
|
|||
|
|
player_meta = _live_sync_collect_player_meta(actor)
|
|||
|
|
player_blob = _live_sync_blob_from_object(player_meta, LIVE_SYNC_AUX_BLOB_LIMIT, "player")
|
|||
|
|
bank_payload = _live_sync_collect_bank_storage
|
|||
|
|
bank_entries = bank_payload.is_a?(Hash) ? bank_payload["entries"] : nil
|
|||
|
|
lc_chests = bank_payload.is_a?(Hash) ? bank_payload["lc_chests"] : nil
|
|||
|
|
bank_has_data = (bank_entries.is_a?(Array) && !bank_entries.empty?) ||
|
|||
|
|
(lc_chests.is_a?(Array) && !lc_chests.empty?)
|
|||
|
|
bank_blob = bank_has_data ? _live_sync_blob_from_object(bank_payload, LIVE_SYNC_BANK_BLOB_LIMIT, "bank") : ""
|
|||
|
|
stat_pack = ""
|
|||
|
|
body_blob = _live_sync_blob_from_object(_live_sync_collect_body(actor), LIVE_SYNC_BODY_BLOB_LIMIT, "body")
|
|||
|
|
if player_blob.to_s.empty?
|
|||
|
|
now = _live_sync_now
|
|||
|
|
last_warn = 0.0
|
|||
|
|
begin
|
|||
|
|
last_warn = @live_sync_last_player_blob_warning_at.to_f
|
|||
|
|
rescue
|
|||
|
|
last_warn = 0.0
|
|||
|
|
end
|
|||
|
|
if now <= 0.0 || (now - last_warn) > 3.0
|
|||
|
|
@live_sync_last_player_blob_warning_at = now
|
|||
|
|
keys = player_meta.is_a?(Hash) ? player_meta.keys.join(",") : "nil"
|
|||
|
|
_live_sync_log("live_sync_player_blob_empty", "keys=#{keys} #{_live_sync_hotkey_summary}")
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
packet = "sync_state:#{level.to_i}:#{gold.to_i}:#{hp.to_i}:#{max_hp.to_i}:#{items_blob}:#{weapons_blob}:#{armors_blob}:#{equips_blob}:#{skills_csv}:#{stats_blob}:#{states_blob}:#{player_blob}:#{bank_blob}:#{stat_pack}:#{body_blob}"
|
|||
|
|
[packet, packet]
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
def self.live_sync_position_now(reason=nil, force=false)
|
|||
|
|
return false unless @connected
|
|||
|
|
begin
|
|||
|
|
return false if respond_to?(:bootstrap_sync_unlocked?) && !bootstrap_sync_unlocked?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
now_pos = mp_position_packet if respond_to?(:mp_position_packet)
|
|||
|
|
now_pos = "#{$game_player.x}:#{$game_player.y}:#{$game_player.direction}" if now_pos.nil?
|
|||
|
|
rescue
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
return false if now_pos.nil? || now_pos.empty?
|
|||
|
|
return false if !force && now_pos == @last_pos
|
|||
|
|
send_line("pos:#{now_pos}")
|
|||
|
|
@last_pos = now_pos
|
|||
|
|
true
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.live_sync_send_now(reason=nil, with_playersync=true, with_position=false)
|
|||
|
|
return false unless @connected
|
|||
|
|
begin
|
|||
|
|
return false if respond_to?(:bootstrap_sync_unlocked?) && !bootstrap_sync_unlocked?
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
built = _live_sync_build_packet
|
|||
|
|
return false if built.nil?
|
|||
|
|
ok = false
|
|||
|
|
begin
|
|||
|
|
sent = send_line(built[0])
|
|||
|
|
ok = !sent.nil? && sent.to_i >= 0
|
|||
|
|
rescue
|
|||
|
|
ok = false
|
|||
|
|
end
|
|||
|
|
if ok
|
|||
|
|
now = _live_sync_now
|
|||
|
|
@live_sync_last_sig = built[1]
|
|||
|
|
@live_sync_last_at = now
|
|||
|
|
@live_sync_last_force_at = now
|
|||
|
|
@live_sync_last_probe_at = now
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.clear_deferred_if_map_sync(reason) if defined?(MPImmediateLiveSync) && MPImmediateLiveSync.respond_to?(:clear_deferred_if_map_sync)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
live_sync_position_now(reason, false) if with_position
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
if ok && with_playersync && respond_to?(:send_playersync_full)
|
|||
|
|
send_playersync_full(reason || 'live_sync_send_now', true)
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
ok
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.live_sync_tick(force=false)
|
|||
|
|
return unless @connected
|
|||
|
|
return if respond_to?(:bootstrap_sync_unlocked?) && !bootstrap_sync_unlocked?
|
|||
|
|
if respond_to?(:gameplay_scene_active?)
|
|||
|
|
return unless gameplay_scene_active?
|
|||
|
|
else
|
|||
|
|
return unless SceneManager.scene_is?(Scene_Map)
|
|||
|
|
end
|
|||
|
|
return unless force
|
|||
|
|
|
|||
|
|
now = _live_sync_now
|
|||
|
|
|
|||
|
|
last_probe = (@live_sync_last_probe_at.nil? ? 0.0 : @live_sync_last_probe_at)
|
|||
|
|
if !force && (now - last_probe) < LIVE_SYNC_PROBE_INTERVAL
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
@live_sync_last_probe_at = now
|
|||
|
|
|
|||
|
|
built = _live_sync_build_packet
|
|||
|
|
return if built.nil?
|
|||
|
|
|
|||
|
|
packet = built[0]
|
|||
|
|
sig = built[1]
|
|||
|
|
|
|||
|
|
if !force && sig == @live_sync_last_sig
|
|||
|
|
return if (now - @live_sync_last_force_at) < LIVE_SYNC_FORCE_INTERVAL
|
|||
|
|
@live_sync_last_force_at = now
|
|||
|
|
else
|
|||
|
|
return if !force && (now - @live_sync_last_at) < LIVE_SYNC_INTERVAL
|
|||
|
|
@live_sync_last_force_at = now if force
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
send_line(packet)
|
|||
|
|
@live_sync_last_sig = sig
|
|||
|
|
@live_sync_last_at = now
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
# Force one final sync packet regardless of current scene/tick throttles.
|
|||
|
|
# Used before disconnect / return-to-title to avoid losing the latest loot.
|
|||
|
|
def self.live_sync_flush_final(reason=nil)
|
|||
|
|
return false unless @connected
|
|||
|
|
built = _live_sync_build_packet
|
|||
|
|
return false if built.nil?
|
|||
|
|
|
|||
|
|
packet = built[0]
|
|||
|
|
sig = built[1]
|
|||
|
|
res = send_line(packet)
|
|||
|
|
ok = !res.nil? && res.to_i >= 0
|
|||
|
|
|
|||
|
|
if ok
|
|||
|
|
now = _live_sync_now
|
|||
|
|
@live_sync_last_sig = sig
|
|||
|
|
@live_sync_last_at = now
|
|||
|
|
@live_sync_last_force_at = now
|
|||
|
|
@live_sync_last_probe_at = now
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
ok
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
module WebSocket
|
|||
|
|
class << self
|
|||
|
|
alias mp_live_sync_update update
|
|||
|
|
def update
|
|||
|
|
mp_live_sync_update
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_disconnect)
|
|||
|
|
alias mp_live_sync_disconnect disconnect
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def disconnect(*args, &block)
|
|||
|
|
begin
|
|||
|
|
live_sync_flush_final("disconnect")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
mp_live_sync_disconnect(*args, &block)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
module MPImmediateLiveSync
|
|||
|
|
INVENTORY_NOOP_FILTER_VERSION = "1.2" unless const_defined?(:INVENTORY_NOOP_FILTER_VERSION)
|
|||
|
|
EVENT_FULL_SYNC_ENABLED = false unless const_defined?(:EVENT_FULL_SYNC_ENABLED)
|
|||
|
|
DEFERRED_REASON_LIMIT = 24 unless const_defined?(:DEFERRED_REASON_LIMIT)
|
|||
|
|
|
|||
|
|
@deferred_full_sync = false
|
|||
|
|
@deferred_reasons = []
|
|||
|
|
|
|||
|
|
def self.event_full_sync_allowed?(reason=nil)
|
|||
|
|
return true if EVENT_FULL_SYNC_ENABLED
|
|||
|
|
text = reason.to_s
|
|||
|
|
text == "map_enter" ||
|
|||
|
|
text == "setup_new_game" ||
|
|||
|
|
text == "new_game" ||
|
|||
|
|
text == "disconnect" ||
|
|||
|
|
text.start_with?("cloud_map_enter") ||
|
|||
|
|
text.start_with?("cloud_bootstrap") ||
|
|||
|
|
text.start_with?("cloud_manual")
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.defer(reason=nil)
|
|||
|
|
@deferred_full_sync = true
|
|||
|
|
@deferred_reasons ||= []
|
|||
|
|
text = reason.to_s.strip
|
|||
|
|
text = "event" if text == ""
|
|||
|
|
@deferred_reasons << text unless @deferred_reasons.include?(text)
|
|||
|
|
@deferred_reasons = @deferred_reasons.last(DEFERRED_REASON_LIMIT)
|
|||
|
|
true
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.deferred?
|
|||
|
|
!!@deferred_full_sync
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.clear_deferred
|
|||
|
|
@deferred_full_sync = false
|
|||
|
|
@deferred_reasons = []
|
|||
|
|
true
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.map_sync_reason?(reason=nil)
|
|||
|
|
text = reason.to_s
|
|||
|
|
text == "map_enter" ||
|
|||
|
|
text.start_with?("map_enter") ||
|
|||
|
|
text.start_with?("cloud_map_enter") ||
|
|||
|
|
text.start_with?("cloud_bootstrap")
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.clear_deferred_if_map_sync(reason=nil)
|
|||
|
|
clear_deferred if map_sync_reason?(reason)
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.player_actor
|
|||
|
|
begin
|
|||
|
|
return $game_player.actor if $game_player && $game_player.respond_to?(:actor)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
nil
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.player_actor?(actor)
|
|||
|
|
pa = player_actor
|
|||
|
|
!pa.nil? && !actor.nil? && pa.equal?(actor)
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.player_act_stat?(stat_obj)
|
|||
|
|
actor = player_actor
|
|||
|
|
return false if actor.nil? || stat_obj.nil?
|
|||
|
|
begin
|
|||
|
|
act_stat = actor.instance_variable_get(:@actStat)
|
|||
|
|
return !act_stat.nil? && act_stat.equal?(stat_obj)
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.trigger(reason=nil, with_playersync=true, with_position=false)
|
|||
|
|
return unless defined?(WebSocket)
|
|||
|
|
return unless WebSocket.respond_to?(:live_sync_send_now)
|
|||
|
|
unless event_full_sync_allowed?(reason)
|
|||
|
|
position(reason, false) if with_position
|
|||
|
|
return defer(reason)
|
|||
|
|
end
|
|||
|
|
ok = WebSocket.live_sync_send_now(reason, with_playersync, with_position)
|
|||
|
|
clear_deferred_if_map_sync(reason) if ok
|
|||
|
|
ok
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.position(reason=nil, force=false)
|
|||
|
|
return unless defined?(WebSocket)
|
|||
|
|
return unless WebSocket.respond_to?(:live_sync_position_now)
|
|||
|
|
WebSocket.live_sync_position_now(reason, force)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.hotkey_summary
|
|||
|
|
return "player=nil" unless $game_player
|
|||
|
|
names = %w[slot_skill_normal slot_skill_heavy slot_skill_control slot_hotkey_0 slot_hotkey_1 slot_hotkey_2 slot_hotkey_3 slot_hotkey_4 slot_hotkey_other]
|
|||
|
|
out = []
|
|||
|
|
begin
|
|||
|
|
roster = $game_player.respond_to?(:slot_RosterArray) ? $game_player.slot_RosterArray : $game_player.instance_variable_get(:@slot_RosterArray)
|
|||
|
|
cur = $game_player.respond_to?(:slot_RosterCurrent) ? $game_player.slot_RosterCurrent.to_i : $game_player.instance_variable_get(:@slot_RosterCurrent).to_i
|
|||
|
|
row = roster[cur] rescue nil
|
|||
|
|
out << "roster_len=#{roster.respond_to?(:length) ? roster.length : 0}"
|
|||
|
|
out << "cur=#{cur}"
|
|||
|
|
out << "row=#{row.inspect}"
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
names.each do |name|
|
|||
|
|
begin
|
|||
|
|
value = $game_player.respond_to?(name) ? $game_player.send(name) : $game_player.instance_variable_get(("@" + name).to_sym)
|
|||
|
|
out << "#{name}=#{value.inspect}"
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
out.join(" ")
|
|||
|
|
rescue
|
|||
|
|
"hotkey_summary_error"
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.trait_summary
|
|||
|
|
actor = player_actor
|
|||
|
|
return "actor=nil" if actor.nil?
|
|||
|
|
out = []
|
|||
|
|
begin
|
|||
|
|
out << "tp=#{actor.respond_to?(:trait_point) ? actor.trait_point.inspect : actor.instance_variable_get(:@trait_point).inspect}"
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
%w[combat_trait scoutcraft_trait wisdom_trait survival_trait constitution_trait].each do |name|
|
|||
|
|
begin
|
|||
|
|
value = actor.respond_to?(name) ? actor.send(name) : nil
|
|||
|
|
out << "#{name}=#{value.inspect}"
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
out.join(" ")
|
|||
|
|
rescue
|
|||
|
|
"trait_summary_error"
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.hotkey(reason=nil)
|
|||
|
|
return defer(reason || "cloud_hotkey") unless event_full_sync_allowed?(reason || "cloud_hotkey")
|
|||
|
|
begin
|
|||
|
|
MPStateInfra.log_line("cloud_hotkey_save", "#{reason} #{hotkey_summary}") if defined?(MPStateInfra)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
cloud_reason = "cloud_hotkey"
|
|||
|
|
if defined?(MPCloudOnlySave)
|
|||
|
|
ok = MPCloudOnlySave.send_tracked_now(cloud_reason, true)
|
|||
|
|
MPCloudOnlySave.request(cloud_reason, 1) unless ok
|
|||
|
|
return ok || MPCloudOnlySave.pending?
|
|||
|
|
end
|
|||
|
|
trigger(reason || cloud_reason, true, true)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.progress(reason=nil)
|
|||
|
|
return defer(reason || "cloud_actor_progress") unless event_full_sync_allowed?(reason || "cloud_actor_progress")
|
|||
|
|
cloud_reason = "cloud_actor_progress"
|
|||
|
|
begin
|
|||
|
|
MPStateInfra.log_line("cloud_actor_progress", "#{reason} #{trait_summary}") if defined?(MPStateInfra)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
if defined?(MPCloudOnlySave)
|
|||
|
|
ok = MPCloudOnlySave.send_tracked_now(cloud_reason, true)
|
|||
|
|
delay = (reason.to_s == "accept_traits" ? 1 : MPCloudOnlySave::MIN_DELAY_FR)
|
|||
|
|
MPCloudOnlySave.request(cloud_reason, delay) unless ok
|
|||
|
|
return ok || MPCloudOnlySave.pending?
|
|||
|
|
end
|
|||
|
|
trigger(reason || cloud_reason, true, true)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def self.overmap_position(reason=nil)
|
|||
|
|
# IMPORTANT: this method is called from every player step/moveto.
|
|||
|
|
# Only the world/overmap (map_id == 2) is allowed to dirty the durable
|
|||
|
|
# overmap snapshot. The old order called defer("increase_steps") first,
|
|||
|
|
# so Save14 treated every ordinary-map step as a full cloud-save event.
|
|||
|
|
begin
|
|||
|
|
return false unless defined?($game_map) && $game_map && $game_map.map_id.to_i == 2
|
|||
|
|
rescue
|
|||
|
|
return false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
sync_reason = reason || "cloud_overmap_position"
|
|||
|
|
return defer(sync_reason) unless event_full_sync_allowed?(sync_reason)
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
MPStateInfra.log_line("cloud_overmap_position", reason.to_s) if defined?(MPStateInfra)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
if defined?(MPCloudOnlySave)
|
|||
|
|
return MPCloudOnlySave.request("cloud_overmap_position", MPCloudOnlySave::MIN_DELAY_FR)
|
|||
|
|
end
|
|||
|
|
trigger("cloud_overmap_position", true, true)
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
class Scene_ItemStorage
|
|||
|
|
unless method_defined?(:mp_live_sync_bank_move_item)
|
|||
|
|
alias mp_live_sync_bank_move_item move_item
|
|||
|
|
def move_item(val=nil)
|
|||
|
|
result = mp_live_sync_bank_move_item(val)
|
|||
|
|
begin
|
|||
|
|
bank_id = WebSocket._live_sync_bank_storage_id if defined?(WebSocket) && WebSocket.respond_to?(:_live_sync_bank_storage_id)
|
|||
|
|
if !bank_id.nil? && @box_id.to_i == bank_id.to_i
|
|||
|
|
WebSocket.bootstrap_remember_current_bank if defined?(WebSocket) && WebSocket.respond_to?(:bootstrap_remember_current_bank)
|
|||
|
|
if defined?(MPCloudOnlySave)
|
|||
|
|
ok = MPCloudOnlySave.send_tracked_now("cloud_bank_storage", true)
|
|||
|
|
MPCloudOnlySave.request("cloud_bank_storage", 1) unless ok
|
|||
|
|
elsif defined?(MPImmediateLiveSync)
|
|||
|
|
MPImmediateLiveSync.trigger("bank_storage", true, false)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
class Game_Party
|
|||
|
|
# 21_sync must react to a REAL inventory/equipment mutation, not merely to a
|
|||
|
|
# call of gain_item/lose_item. LonaRPG periodically runs actor.refresh;
|
|||
|
|
# release_unequippable_items can reach trade_item_with_party(nil, nil), which
|
|||
|
|
# in turn calls gain_item(nil, +/-1). Those calls are intentional no-ops and
|
|||
|
|
# must not dirty cloud state.
|
|||
|
|
unless method_defined?(:mp_live_sync_inventory_snapshot)
|
|||
|
|
def mp_live_sync_normalize_inventory_item(item)
|
|||
|
|
begin
|
|||
|
|
if respond_to?(:normalize_party_item, true)
|
|||
|
|
return send(:normalize_party_item, item)
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
item
|
|||
|
|
rescue
|
|||
|
|
nil
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def mp_live_sync_same_inventory_item?(left, right)
|
|||
|
|
return true if left.equal?(right)
|
|||
|
|
return false if left.nil? || right.nil?
|
|||
|
|
begin
|
|||
|
|
return false unless left.class == right.class
|
|||
|
|
return left.id.to_i == right.id.to_i if left.respond_to?(:id) && right.respond_to?(:id)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
false
|
|||
|
|
rescue
|
|||
|
|
false
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def mp_live_sync_equipped_item_count(item)
|
|||
|
|
count = 0
|
|||
|
|
begin
|
|||
|
|
members.each do |actor|
|
|||
|
|
next if actor.nil? || !actor.respond_to?(:equips)
|
|||
|
|
actor.equips.each do |eq|
|
|||
|
|
count += 1 if mp_live_sync_same_inventory_item?(eq, item)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
count
|
|||
|
|
rescue
|
|||
|
|
0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def mp_live_sync_inventory_snapshot(item, include_equip=false)
|
|||
|
|
object = mp_live_sync_normalize_inventory_item(item)
|
|||
|
|
return nil if object.nil?
|
|||
|
|
|
|||
|
|
# Invalid objects/strings that the party cannot actually store are also
|
|||
|
|
# no-ops. Checking the real container avoids false dirty events.
|
|||
|
|
begin
|
|||
|
|
if respond_to?(:item_container_for_object, true)
|
|||
|
|
return nil if send(:item_container_for_object, object).nil?
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
count = 0
|
|||
|
|
begin
|
|||
|
|
count = item_number(object).to_i
|
|||
|
|
rescue
|
|||
|
|
count = 0
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
equipped = nil
|
|||
|
|
equipped = mp_live_sync_equipped_item_count(object) if include_equip
|
|||
|
|
|
|||
|
|
klass = begin object.class.name.to_s rescue object.class.to_s end
|
|||
|
|
id = begin object.id.to_i rescue 0 end
|
|||
|
|
[klass, id, count, equipped]
|
|||
|
|
rescue
|
|||
|
|
nil
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_gain_item)
|
|||
|
|
alias mp_live_sync_gain_item gain_item
|
|||
|
|
def gain_item(item, amount=1, include_equip=false)
|
|||
|
|
# lose_item in the base game is implemented through gain_item(item,-n).
|
|||
|
|
# Keep a small nesting guard so one real loss produces ONE event instead
|
|||
|
|
# of both gain_item and lose_item events.
|
|||
|
|
top_level = @mp_live_sync_inventory_hook_depth.to_i == 0
|
|||
|
|
before = top_level ? mp_live_sync_inventory_snapshot(item, include_equip) : nil
|
|||
|
|
|
|||
|
|
@mp_live_sync_inventory_hook_depth = @mp_live_sync_inventory_hook_depth.to_i + 1
|
|||
|
|
begin
|
|||
|
|
result = mp_live_sync_gain_item(item, amount, include_equip)
|
|||
|
|
ensure
|
|||
|
|
@mp_live_sync_inventory_hook_depth = [@mp_live_sync_inventory_hook_depth.to_i - 1, 0].max
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if top_level && !before.nil?
|
|||
|
|
after = mp_live_sync_inventory_snapshot(item, include_equip)
|
|||
|
|
if !after.nil? && before != after
|
|||
|
|
MPImmediateLiveSync.trigger("gain_item", true, false)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_lose_item)
|
|||
|
|
alias mp_live_sync_lose_item lose_item
|
|||
|
|
def lose_item(item, amount=1, include_equip=false)
|
|||
|
|
top_level = @mp_live_sync_inventory_hook_depth.to_i == 0
|
|||
|
|
before = top_level ? mp_live_sync_inventory_snapshot(item, include_equip) : nil
|
|||
|
|
|
|||
|
|
@mp_live_sync_inventory_hook_depth = @mp_live_sync_inventory_hook_depth.to_i + 1
|
|||
|
|
begin
|
|||
|
|
result = mp_live_sync_lose_item(item, amount, include_equip)
|
|||
|
|
ensure
|
|||
|
|
@mp_live_sync_inventory_hook_depth = [@mp_live_sync_inventory_hook_depth.to_i - 1, 0].max
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if top_level && !before.nil?
|
|||
|
|
after = mp_live_sync_inventory_snapshot(item, include_equip)
|
|||
|
|
if !after.nil? && before != after
|
|||
|
|
MPImmediateLiveSync.trigger("lose_item", true, false)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_gain_gold)
|
|||
|
|
alias mp_live_sync_gain_gold gain_gold
|
|||
|
|
def gain_gold(amount)
|
|||
|
|
result = mp_live_sync_gain_gold(amount)
|
|||
|
|
MPImmediateLiveSync.trigger("gain_gold", true, false) if amount.to_i != 0
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_set_gold)
|
|||
|
|
alias mp_live_sync_set_gold set_gold
|
|||
|
|
def set_gold(amount)
|
|||
|
|
result = mp_live_sync_set_gold(amount)
|
|||
|
|
MPImmediateLiveSync.trigger("set_gold", true, false)
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
class Game_Actor
|
|||
|
|
unless method_defined?(:mp_live_sync_change_equip)
|
|||
|
|
alias mp_live_sync_change_equip change_equip
|
|||
|
|
def change_equip(slot_id, item)
|
|||
|
|
result = mp_live_sync_change_equip(slot_id, item)
|
|||
|
|
MPImmediateLiveSync.trigger("change_equip", true, false) if MPImmediateLiveSync.player_actor?(self)
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_force_change_equip)
|
|||
|
|
alias mp_live_sync_force_change_equip force_change_equip
|
|||
|
|
def force_change_equip(slot_id, item)
|
|||
|
|
result = mp_live_sync_force_change_equip(slot_id, item)
|
|||
|
|
MPImmediateLiveSync.trigger("force_change_equip", true, false) if MPImmediateLiveSync.player_actor?(self)
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_learn_skill)
|
|||
|
|
alias mp_live_sync_learn_skill learn_skill
|
|||
|
|
def learn_skill(skill_id)
|
|||
|
|
result = mp_live_sync_learn_skill(skill_id)
|
|||
|
|
if MPImmediateLiveSync.player_actor?(self)
|
|||
|
|
MPImmediateLiveSync.trigger("learn_skill", true, false)
|
|||
|
|
MPImmediateLiveSync.progress("learn_skill")
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_forget_skill)
|
|||
|
|
alias mp_live_sync_forget_skill forget_skill
|
|||
|
|
def forget_skill(skill_id)
|
|||
|
|
result = mp_live_sync_forget_skill(skill_id)
|
|||
|
|
if MPImmediateLiveSync.player_actor?(self)
|
|||
|
|
MPImmediateLiveSync.trigger("forget_skill", true, false)
|
|||
|
|
MPImmediateLiveSync.progress("forget_skill")
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_add_state)
|
|||
|
|
alias mp_live_sync_add_state add_state
|
|||
|
|
def add_state(state_id)
|
|||
|
|
result = mp_live_sync_add_state(state_id)
|
|||
|
|
if MPImmediateLiveSync.player_actor?(self)
|
|||
|
|
MPImmediateLiveSync.trigger("add_state", true, false)
|
|||
|
|
MPImmediateLiveSync.progress("add_state")
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if method_defined?(:change_exp)
|
|||
|
|
unless method_defined?(:mp_live_sync_change_exp)
|
|||
|
|
alias mp_live_sync_change_exp change_exp
|
|||
|
|
def change_exp(exp, show)
|
|||
|
|
old_exp = nil
|
|||
|
|
old_level = nil
|
|||
|
|
begin
|
|||
|
|
old_exp = self.exp if respond_to?(:exp)
|
|||
|
|
old_level = @level
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result = mp_live_sync_change_exp(exp, show)
|
|||
|
|
begin
|
|||
|
|
new_exp = (respond_to?(:exp) ? self.exp : old_exp)
|
|||
|
|
if MPImmediateLiveSync.player_actor?(self) && (old_exp != new_exp || old_level != @level)
|
|||
|
|
MPImmediateLiveSync.progress("change_exp")
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_change_level)
|
|||
|
|
alias mp_live_sync_change_level change_level
|
|||
|
|
def change_level(level, show)
|
|||
|
|
result = mp_live_sync_change_level(level, show)
|
|||
|
|
if MPImmediateLiveSync.player_actor?(self)
|
|||
|
|
MPImmediateLiveSync.trigger("change_level", true, false)
|
|||
|
|
MPImmediateLiveSync.progress("change_level")
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
class Game_BattlerBase
|
|||
|
|
unless method_defined?(:mp_live_sync_hp_set)
|
|||
|
|
alias mp_live_sync_hp_set hp=
|
|||
|
|
def hp=(hp)
|
|||
|
|
old_hp = nil
|
|||
|
|
begin
|
|||
|
|
old_hp = self.hp if respond_to?(:hp)
|
|||
|
|
rescue
|
|||
|
|
old_hp = nil
|
|||
|
|
end
|
|||
|
|
result = self.mp_live_sync_hp_set(hp)
|
|||
|
|
begin
|
|||
|
|
new_hp = self.hp if respond_to?(:hp)
|
|||
|
|
MPImmediateLiveSync.trigger("hp_set", true, false) if MPImmediateLiveSync.player_actor?(self) && old_hp != new_hp
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
class Game_Battler
|
|||
|
|
unless method_defined?(:mp_live_sync_remove_state)
|
|||
|
|
alias mp_live_sync_remove_state remove_state
|
|||
|
|
def remove_state(state_id)
|
|||
|
|
result = mp_live_sync_remove_state(state_id)
|
|||
|
|
MPImmediateLiveSync.trigger("remove_state", true, false) if MPImmediateLiveSync.player_actor?(self)
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
class ActorStat
|
|||
|
|
unless method_defined?(:mp_live_sync_set_stat)
|
|||
|
|
alias mp_live_sync_set_stat set_stat
|
|||
|
|
def set_stat(stat_name, value, type=CURRENT_STAT)
|
|||
|
|
old_value = nil
|
|||
|
|
begin
|
|||
|
|
old_value = get_stat(stat_name, type)
|
|||
|
|
rescue
|
|||
|
|
old_value = nil
|
|||
|
|
end
|
|||
|
|
result = mp_live_sync_set_stat(stat_name, value, type)
|
|||
|
|
begin
|
|||
|
|
new_value = get_stat(stat_name, type)
|
|||
|
|
if type == CURRENT_STAT && MPImmediateLiveSync.player_act_stat?(self) && old_value != new_value
|
|||
|
|
# Health, stamina and similar meters tick on their own. A full cloud
|
|||
|
|
# snapshot for each tick is what kept the diskette on screen.
|
|||
|
|
unless defined?(MP_Save14) && MP_Save14.respond_to?(:volatile_actor_stat?) && MP_Save14.volatile_actor_stat?(stat_name)
|
|||
|
|
MPImmediateLiveSync.trigger("set_stat:#{stat_name}", true, false)
|
|||
|
|
MPImmediateLiveSync.progress("set_stat:#{stat_name}")
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
# The player writes stats through LonaActorStat#set_stat, which does not call
|
|||
|
|
# ActorStat#set_stat. Only the permanent reputation counter schedules a save.
|
|||
|
|
# morality and morality_plus move whenever a temporary mark or piece of gear
|
|||
|
|
# is refreshed, and refresh rebuilds both from the stored counter.
|
|||
|
|
if defined?(LonaActorStat)
|
|||
|
|
class LonaActorStat
|
|||
|
|
unless method_defined?(:mp_live_sync_lona_set_stat)
|
|||
|
|
alias mp_live_sync_lona_set_stat set_stat
|
|||
|
|
def set_stat(stat_name, value, type=CURRENT_STAT)
|
|||
|
|
watch = type == CURRENT_STAT && stat_name.to_s == "morality_lona"
|
|||
|
|
old_value = nil
|
|||
|
|
begin
|
|||
|
|
old_value = get_stat(stat_name, type) if watch
|
|||
|
|
rescue
|
|||
|
|
old_value = nil
|
|||
|
|
end
|
|||
|
|
result = mp_live_sync_lona_set_stat(stat_name, value, type)
|
|||
|
|
begin
|
|||
|
|
if watch && defined?(MPImmediateLiveSync) && MPImmediateLiveSync.player_act_stat?(self)
|
|||
|
|
new_value = get_stat(stat_name, type)
|
|||
|
|
if old_value != new_value
|
|||
|
|
MPImmediateLiveSync.trigger("set_stat:morality_lona", true, false)
|
|||
|
|
MPImmediateLiveSync.progress("set_stat:morality_lona") if MPImmediateLiveSync.respond_to?(:progress)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
# Титул меняется через attr_accessor, а не через actStat — ловим запись,
|
|||
|
|
# чтобы cloud save не откладывал смену до следующего полного синка.
|
|||
|
|
if defined?(Game_Actor)
|
|||
|
|
class Game_Actor
|
|||
|
|
unless method_defined?(:mp_live_sync_record_lona_title_writer)
|
|||
|
|
if method_defined?(:record_lona_title=)
|
|||
|
|
alias mp_live_sync_record_lona_title_writer record_lona_title=
|
|||
|
|
def record_lona_title=(value)
|
|||
|
|
old_value = nil
|
|||
|
|
begin
|
|||
|
|
old_value = record_lona_title
|
|||
|
|
rescue
|
|||
|
|
old_value = nil
|
|||
|
|
end
|
|||
|
|
result = mp_live_sync_record_lona_title_writer(value)
|
|||
|
|
begin
|
|||
|
|
if defined?(MPImmediateLiveSync) && MPImmediateLiveSync.respond_to?(:player_actor?) && MPImmediateLiveSync.player_actor?(self)
|
|||
|
|
if old_value.to_s != value.to_s
|
|||
|
|
MPImmediateLiveSync.trigger("record_lona_title", true, false)
|
|||
|
|
MPImmediateLiveSync.progress("record_lona_title") if MPImmediateLiveSync.respond_to?(:progress)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
class Game_CharacterBase
|
|||
|
|
unless method_defined?(:mp_live_sync_increase_steps)
|
|||
|
|
alias mp_live_sync_increase_steps increase_steps
|
|||
|
|
def increase_steps
|
|||
|
|
result = mp_live_sync_increase_steps
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.position("increase_steps", false) if self.equal?($game_player)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.overmap_position("increase_steps") if self.equal?($game_player)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
unless method_defined?(:mp_live_sync_moveto)
|
|||
|
|
alias mp_live_sync_moveto moveto
|
|||
|
|
def moveto(x, y)
|
|||
|
|
result = mp_live_sync_moveto(x, y)
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.position("moveto", true) if self.equal?($game_player)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.overmap_position("moveto") if self.equal?($game_player)
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
class Game_Player
|
|||
|
|
if method_defined?(:setup_SkillRoster)
|
|||
|
|
unless method_defined?(:mp_live_sync_setup_skill_roster)
|
|||
|
|
alias mp_live_sync_setup_skill_roster setup_SkillRoster
|
|||
|
|
def setup_SkillRoster(*args, &block)
|
|||
|
|
result = mp_live_sync_setup_skill_roster(*args, &block)
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.hotkey("setup_SkillRoster")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if method_defined?(:update_GetNextSkillRoster)
|
|||
|
|
unless method_defined?(:mp_live_sync_next_skill_roster)
|
|||
|
|
alias mp_live_sync_next_skill_roster update_GetNextSkillRoster
|
|||
|
|
def update_GetNextSkillRoster(*args, &block)
|
|||
|
|
result = mp_live_sync_next_skill_roster(*args, &block)
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.hotkey("update_GetNextSkillRoster")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if method_defined?(:update_GetPrevSkillRoster)
|
|||
|
|
unless method_defined?(:mp_live_sync_prev_skill_roster)
|
|||
|
|
alias mp_live_sync_prev_skill_roster update_GetPrevSkillRoster
|
|||
|
|
def update_GetPrevSkillRoster(*args, &block)
|
|||
|
|
result = mp_live_sync_prev_skill_roster(*args, &block)
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.hotkey("update_GetPrevSkillRoster")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if defined?(Menu_Traits) && Menu_Traits.method_defined?(:accept_handler)
|
|||
|
|
class Menu_Traits
|
|||
|
|
unless method_defined?(:mp_live_sync_accept_traits_without_cloud)
|
|||
|
|
alias mp_live_sync_accept_traits_without_cloud accept_handler
|
|||
|
|
def accept_handler(*args, &block)
|
|||
|
|
result = mp_live_sync_accept_traits_without_cloud(*args, &block)
|
|||
|
|
begin
|
|||
|
|
MPImmediateLiveSync.progress("accept_traits")
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if defined?(Menu_System) && Menu_System.method_defined?(:hotkeyRoster_opt_handler)
|
|||
|
|
class Menu_System
|
|||
|
|
unless method_defined?(:mp_live_sync_hotkey_roster_opt_handler)
|
|||
|
|
alias mp_live_sync_hotkey_roster_opt_handler hotkeyRoster_opt_handler
|
|||
|
|
def hotkeyRoster_opt_handler(*args, &block)
|
|||
|
|
before = nil
|
|||
|
|
begin
|
|||
|
|
before = Marshal.dump($game_player.slot_RosterArray) if $game_player && $game_player.respond_to?(:slot_RosterArray)
|
|||
|
|
rescue
|
|||
|
|
before = nil
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
result = mp_live_sync_hotkey_roster_opt_handler(*args, &block)
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
after = Marshal.dump($game_player.slot_RosterArray) if $game_player && $game_player.respond_to?(:slot_RosterArray)
|
|||
|
|
MPImmediateLiveSync.hotkey("hotkeyRoster_opt_handler") if before != after
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
module DataManager
|
|||
|
|
class << self
|
|||
|
|
unless method_defined?(:mp_live_sync_setup_new_game)
|
|||
|
|
alias mp_live_sync_setup_new_game setup_new_game
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
def setup_new_game(*args)
|
|||
|
|
result = mp_live_sync_setup_new_game(*args)
|
|||
|
|
begin
|
|||
|
|
if defined?(WebSocket) && WebSocket.respond_to?(:live_sync_send_now)
|
|||
|
|
WebSocket.live_sync_send_now("setup_new_game", true, true)
|
|||
|
|
end
|
|||
|
|
rescue
|
|||
|
|
end
|
|||
|
|
result
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|