445 lines
15 KiB
Ruby
445 lines
15 KiB
Ruby
# encoding: UTF-8
|
|
# Q3.0.4-online5 (RC only; silent toggle + server preference). Ruby 3.1.0 / MKXP-Z game_online(20261009).
|
|
Ruby310Compat.json_ready? if defined?(Ruby310Compat) && Ruby310Compat.respond_to?(:json_ready?)
|
|
# Auto-detect path for the Booba mod.
|
|
BOOBA_MOD_PATH = File.dirname(__FILE__) + "/"
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Booba Online icon safety net (Q3.0.4-online2).
|
|
# A client that has the item data but lacks the PNG can still open shop/storage.
|
|
# The patch is limited to Booba's four icons. It does not change other mods.
|
|
# -----------------------------------------------------------------------------
|
|
if defined?(Cache) && Cache.respond_to?(:normal_bitmap)
|
|
module Cache
|
|
class << self
|
|
unless method_defined?(:booba_online2_normal_bitmap_without_icon_fallback)
|
|
alias_method :booba_online2_normal_bitmap_without_icon_fallback, :normal_bitmap
|
|
|
|
def normal_bitmap(path)
|
|
filename = nil
|
|
if path.is_a?(String)
|
|
normalized = path.tr('\\', '/')
|
|
found = normalized.match(%r{(?:\A|/)Lona_Booba_Graphics/[Ii]tems/icons/(AddModExpandedBooba|AidModExpandedBooba|CosmeticToggle|Mod_ExpandedBooba)\.png\z})
|
|
filename = "#{found[1]}.png" if found
|
|
end
|
|
# Other items, other mods and the game itself keep original behavior.
|
|
return booba_online2_normal_bitmap_without_icon_fallback(path) unless filename
|
|
|
|
begin
|
|
return booba_online2_normal_bitmap_without_icon_fallback(path)
|
|
rescue Errno::ENOENT
|
|
# Accommodate both capitalization variants and partial installs.
|
|
["Items/icons/#{filename}", "items/icons/#{filename}"].each do |relative|
|
|
candidate = File.join(BOOBA_MOD_PATH, relative)
|
|
next unless File.file?(candidate)
|
|
begin
|
|
return booba_online2_normal_bitmap_without_icon_fallback(candidate)
|
|
rescue Errno::ENOENT
|
|
# Try the next location.
|
|
end
|
|
end
|
|
@cache ||= {}
|
|
@cache[path] = Bitmap.new(24, 24) unless include?(path)
|
|
@cache[path]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
# ---------------------------------
|
|
# Initialize Booba Functions
|
|
# ---------------------------------
|
|
# Handles global state, configuration persistence,
|
|
# and high-level feature toggles for the Booba mod.
|
|
module BoobaMod
|
|
# Path to the mod configuration file.
|
|
BOOBA_INI_PATH = "#{BOOBA_MOD_PATH}config.ini"
|
|
|
|
# Initializes the Booba global state.
|
|
def self.init
|
|
unless File.exist?(BOOBA_INI_PATH)
|
|
write(false)
|
|
end
|
|
$lona_booba_cosmetic_mode = read
|
|
end
|
|
|
|
# Reads Cosmetic mode flag from config.ini.
|
|
def self.read
|
|
return false unless File.exist?(BOOBA_INI_PATH)
|
|
File.read(BOOBA_INI_PATH) =~ /Cosmetic\s*=\s*true/i ? true : false
|
|
end
|
|
|
|
# Writes Cosmetic mode flag to config.ini.
|
|
def self.write(val)
|
|
File.open(BOOBA_INI_PATH, "w") do |f|
|
|
f.write("[Settings]\nCosmetic=#{val ? 'true' : 'false'}\n")
|
|
end
|
|
end
|
|
|
|
# Initialize global state once.
|
|
init unless defined?($lona_booba_cosmetic_mode)
|
|
|
|
# Toggles Cosmetic/Surgery mode.
|
|
# Triggered by the CosmeticToggle item.
|
|
def self.toggle
|
|
$lona_booba_cosmetic_mode = !$lona_booba_cosmetic_mode
|
|
write($lona_booba_cosmetic_mode)
|
|
refresh_portrait
|
|
sync_online_appearance
|
|
# Silent toggle: RC state is saved and synced without a modal popup.
|
|
end
|
|
|
|
# Immediate visual update. The permanent surgery value is published only
|
|
# when ExpandedBooba itself changed, never for a Cosmetic Mode toggle.
|
|
def self.sync_online_appearance(surgery_changed = false)
|
|
return unless defined?(WebSocket) && WebSocket.respond_to?(:booba_send_snapshot)
|
|
WebSocket.booba_pref_publish if WebSocket.respond_to?(:booba_pref_publish)
|
|
if surgery_changed && !(WebSocket.respond_to?(:booba_surgery_applying?) && WebSocket.booba_surgery_applying?)
|
|
WebSocket.booba_surgery_publish if WebSocket.respond_to?(:booba_surgery_publish)
|
|
end
|
|
WebSocket.booba_send_snapshot(true)
|
|
rescue StandardError
|
|
nil
|
|
end
|
|
|
|
# Manually trigger portrait refresh.
|
|
def self.refresh_portrait
|
|
return unless $game_actors && $game_actors[1]
|
|
actor = $game_actors[1]
|
|
return unless actor.respond_to?(:portrait)
|
|
portrait = actor.portrait
|
|
return unless portrait
|
|
value = booba
|
|
portrait.set_stat("BigBooba", value)
|
|
end
|
|
|
|
# --------------------------------------------------
|
|
# Returns 1/true if BigBooba should be active.
|
|
# --------------------------------------------------
|
|
def self.booba
|
|
actor = ($game_actors && $game_actors[1]) rescue nil
|
|
return 1 if $lona_booba_cosmetic_mode
|
|
return 0 if actor.nil?
|
|
stats = actor.respond_to?(:stat) ? actor.stat : nil
|
|
stats.is_a?(Hash) && stats["ExpandedBooba"].to_i > 0 ? 1 : 0
|
|
end
|
|
end
|
|
|
|
# ---------------------------------
|
|
# Match Parts Value Override
|
|
# ---------------------------------
|
|
class Lona_Part
|
|
alias _booba_set_value set_value
|
|
|
|
def set_value(statName, value, forcedOpacity = false)
|
|
# Never substitute a remote player's nil/zero visual marker with the
|
|
# local player's preference. Local portrait refresh passes an explicit 0/1.
|
|
_booba_set_value(statName, value, forcedOpacity)
|
|
end
|
|
end
|
|
|
|
class Game_Actor
|
|
alias _booba_setup_state setup_state
|
|
|
|
def setup_state(state_name, count)
|
|
_booba_setup_state(state_name, count)
|
|
|
|
if state_name == "ExpandedBooba"
|
|
BoobaMod.refresh_portrait
|
|
BoobaMod.sync_online_appearance(true)
|
|
end
|
|
end
|
|
end
|
|
|
|
module DataManager
|
|
class << self
|
|
alias _booba_extract extract_save_contents
|
|
end
|
|
|
|
def self.extract_save_contents(contents)
|
|
_booba_extract(contents)
|
|
BoobaMod.refresh_portrait
|
|
end
|
|
end
|
|
|
|
module DataManager
|
|
class << self
|
|
alias_method :load_mod_database_Lona_Booba_Graphics, :load_mod_database
|
|
end
|
|
|
|
# ---------------------------------
|
|
# Item and State Helpers
|
|
# ---------------------------------
|
|
# Refreshes shop inventory for the gynecology vendor.
|
|
# Keep the RC visual option only; legacy R/Aid items remain registered for
|
|
# compatibility with older saves, but they are no longer sold by Elise.
|
|
def self.custom_refresh_shop
|
|
shop = $data_barters && $data_barters["NoerGynecologyEliseDay"]
|
|
return unless shop
|
|
shop["items"] ||= []
|
|
shop["items"].reject! do |entry|
|
|
["AddModExpandedBooba", "AidModExpandedBooba", "CosmeticToggle"].include?(entry["item_name"])
|
|
end
|
|
# Explicit numeric price: a fixed 2000 trading points, no shop markup.
|
|
shop["items"] << {"item_name" => "CosmeticToggle", "price" => 2000, "amount" => 2}
|
|
end
|
|
|
|
# Utility helper for injecting mod items/states.
|
|
def self.add_custom_data(arr, klass, json_path)
|
|
arr << klass.new
|
|
arr.last.id = arr.length - 1
|
|
arr.last.load_additional_data(json_path)
|
|
end
|
|
|
|
# ---------------------------------
|
|
# Item and State Setup
|
|
# ---------------------------------
|
|
def self.load_mod_database
|
|
# Load vanilla + other mods first
|
|
load_mod_database_Lona_Booba_Graphics
|
|
|
|
# Register Booba-related states and items
|
|
add_custom_data($data_states, RPG::State, "#{BOOBA_MOD_PATH}Items/states/ExpandedBooba.json")
|
|
add_custom_data($data_items, RPG::Item, "#{BOOBA_MOD_PATH}Items/AddModExpandedBooba.json")
|
|
add_custom_data($data_items, RPG::Item, "#{BOOBA_MOD_PATH}Items/AidModExpandedBooba.json")
|
|
add_custom_data($data_items, RPG::Item, "#{BOOBA_MOD_PATH}Items/CosmeticToggle.json")
|
|
|
|
# Update shop inventory if available
|
|
custom_refresh_shop if $data_barters && $data_barters["NoerGynecologyEliseDay"]
|
|
end
|
|
|
|
end
|
|
|
|
# ---------------------------------
|
|
# Existing-save shop reconciliation (online3 / RC only)
|
|
# ---------------------------------
|
|
module GIM_ADDON
|
|
unless method_defined?(:booba_online3_manual_barters_before_rc_reconcile)
|
|
alias_method :booba_online3_manual_barters_before_rc_reconcile, :manual_barters
|
|
|
|
def manual_barters(trade_id)
|
|
if trade_id == "NoerGynecologyEliseDay" && $story_stats && $data_barters
|
|
shop = $data_barters[trade_id]
|
|
if shop && shop["charStoreHashName"] == true
|
|
npc = get_character(0)
|
|
if npc && npc.respond_to?(:id)
|
|
shop_key = "#{@map_id}_#{npc.id}".to_sym
|
|
saved_shops = $story_stats.ensure_hash!("CharacterItems")
|
|
saved = saved_shops[shop_key]
|
|
if saved.is_a?(Array) && saved[0].is_a?(Hash)
|
|
stock = saved[0]
|
|
stock.delete("AddModExpandedBooba")
|
|
stock.delete("AidModExpandedBooba")
|
|
rc = stock["CosmeticToggle"]
|
|
if rc.is_a?(Hash)
|
|
rc["price"] = 2000
|
|
else
|
|
stock["CosmeticToggle"] = {"price" => 2000, "amount" => 2}
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
booba_online3_manual_barters_before_rc_reconcile(trade_id)
|
|
end
|
|
end
|
|
end
|
|
|
|
# ---------------------------------
|
|
# Palette Override
|
|
# ---------------------------------
|
|
# Extends PaletteChanger to apply palette changes
|
|
# to modded Booba portrait graphics as well.
|
|
module BitmapChanger
|
|
class << self
|
|
alias _booba_orig_load_setting load_setting
|
|
end
|
|
|
|
def self.load_setting(json_data)
|
|
names = json_data["names"]
|
|
|
|
# Duplicate palette entries for modded portrait paths
|
|
if names.is_a?(Array)
|
|
extra = []
|
|
names.each do |p|
|
|
next unless p.start_with?("Graphics/Portrait/Lona/")
|
|
modded = "Graphics/Portrait/Lona/../../../#{BOOBA_MOD_PATH}#{p}"
|
|
extra << modded if File.exist?(modded)
|
|
end
|
|
names.concat(extra) unless extra.empty?
|
|
end
|
|
|
|
_booba_orig_load_setting(json_data)
|
|
end
|
|
end
|
|
|
|
# ---------------------------------
|
|
# Booba Sex Menu Override
|
|
# ---------------------------------
|
|
# Adds Booba-related visual indicators to the sex stats UI
|
|
# when Cosmetic Mode is active or the trait is present.
|
|
class Menu_SexStats < Menu_ContentBase
|
|
alias draw_meters_Lona_Booba_Graphics draw_meters
|
|
|
|
def draw_meters
|
|
draw_meters_Lona_Booba_Graphics
|
|
# BoobaMod.booba returns 0/1; in Ruby 0 is truthy, so compare explicitly.
|
|
# Without enlargement, keep the vanilla 32px_iconset body icons only.
|
|
return unless BoobaMod.booba.to_i > 0
|
|
|
|
actor = self.instance_variable_get(:@actor)
|
|
back = self.instance_variable_get(:@back).bitmap
|
|
x, y = self.semenMeterData[:Body]
|
|
value = self.body_values[0]
|
|
|
|
# Layered icons rendered over the existing meter (enlarged breasts only)
|
|
icon_booba = Cache.system("../../#{BOOBA_MOD_PATH}Graphics/System/32px_booba_layer.png")
|
|
icon_melanin = Cache.system("../../#{BOOBA_MOD_PATH}Graphics/System/32px_melanin_layer.png")
|
|
|
|
self.draw_icon_32(icon_booba, back, x, y + 21, value)
|
|
self.draw_icon_32(icon_melanin, back, x, y + 21, value, actor.melaninNipple.to_i)
|
|
end
|
|
end
|
|
|
|
# ---------------------------------
|
|
# Booba Parts Mapping
|
|
# ---------------------------------
|
|
# Extends FileGetter to inject ExpandedBooba pose handling.
|
|
module FileGetter
|
|
class << self
|
|
alias booba_load_parts load_lona_portrait_parts_dir
|
|
end
|
|
|
|
# --------------------------------------------------
|
|
# Loads and merges a base (lona) JSON with an optional
|
|
# mod (booba) JSON, then applies ExpandedBooba remapping.
|
|
# --------------------------------------------------
|
|
def self.load_pose_json_pair(lona_file, mod_file)
|
|
lona_json = lona_file && File.exist?(lona_file) ? JSON.decode(File.read(lona_file)) : []
|
|
booba_json = mod_file && File.exist?(mod_file) ? JSON.decode(File.read(mod_file)) : []
|
|
preprocess_lona_booba_pose_json(lona_json, booba_json)
|
|
end
|
|
|
|
# --------------------------------------------------
|
|
# Main loader for Lona portrait parts.
|
|
#
|
|
# Iterates through each pose directory, merges base
|
|
# and mod JSON files, applies ExpandedBooba mappings,
|
|
# and feeds the result into handle_lona_parts_arr.
|
|
# --------------------------------------------------
|
|
def self.load_lona_portrait_parts_dir
|
|
partsHash = {} # pose_name => parts array
|
|
name_order = {} # global name_order accumulator
|
|
|
|
base_dir = "Data/Pconfig/Pconfig_lona/poses"
|
|
mod_base = "#{BOOBA_MOD_PATH}Data/Pconfig/Pconfig_lona/poses"
|
|
|
|
# Iterate over each pose folder (e.g. pose1, pose2, etc.)
|
|
Dir["#{base_dir}/*"].each do |dir|
|
|
pose_name = File.basename(dir).downcase
|
|
prp "lona pose #{pose_name}"
|
|
|
|
lona_files = getFileList("#{dir}/*.json")
|
|
mod_dir = "#{mod_base}/#{File.basename(dir)}"
|
|
mod_files = getFileList("#{mod_dir}/*.json")
|
|
|
|
# Tracks which lona files were already merged
|
|
processed = {}
|
|
|
|
# --- Base Lona JSONs (optionally merged with mod JSONs)
|
|
lona_files.each do |file|
|
|
json = load_pose_json_pair(file, "#{mod_dir}/#{File.basename(file)}")
|
|
parts_config = handle_lona_parts_arr(json, name_order)
|
|
|
|
partsHash[pose_name] ||= []
|
|
partsHash[pose_name] += parts_config[1]
|
|
name_order = parts_config[0]
|
|
|
|
processed[File.basename(file)] = true
|
|
end
|
|
|
|
# --- Mod-only JSONs (poses that don't exist in base game)
|
|
mod_files.each do |file|
|
|
next if processed[File.basename(file)]
|
|
|
|
json = load_pose_json_pair(nil, file)
|
|
parts_config = handle_lona_parts_arr(json, name_order)
|
|
|
|
partsHash[pose_name] ||= []
|
|
partsHash[pose_name] += parts_config[1]
|
|
name_order = parts_config[0]
|
|
end
|
|
end
|
|
|
|
# Load NPC layered portrait data (unchanged from vanilla behavior)
|
|
load_layered_npc_parts(partsHash, name_order)
|
|
|
|
# Persist generated parts data if enabled
|
|
save_data([name_order, partsHash], "Data/lona_pconfig.rvdata2") if WRITING_LIST
|
|
prp "Data/lona_parts.rvdata2 written" if WRITING_LIST
|
|
|
|
[name_order, partsHash]
|
|
end
|
|
|
|
# --------------------------------------------------
|
|
# Loads layered NPC portrait data.
|
|
# --------------------------------------------------
|
|
def self.load_layered_npc_parts(partsHash, name_order)
|
|
getFileList("Data/Pconfig/Pconfig_LayeredNPC/poses/*.json").each do |filename|
|
|
pose_name = filename[38..-6]
|
|
prp "load portrait json: #{filename}"
|
|
prp "NPC pose #{pose_name}"
|
|
|
|
parts_config = handle_lona_parts_arr(JSON.decode(File.read(filename)), name_order)
|
|
|
|
partsHash[pose_name] ||= []
|
|
partsHash[pose_name] += parts_config[1]
|
|
name_order.replace(parts_config[0])
|
|
end
|
|
end
|
|
|
|
# --------------------------------------------------
|
|
# Applies ExpandedBooba pose remapping.
|
|
#
|
|
# - Appends "ExpandedBooba" to name_order
|
|
# - Rewrites bmp keys to:
|
|
# ExpandedBooba00 => base Lona assets
|
|
# ExpandedBooba01 => modded assets (if present)
|
|
# --------------------------------------------------
|
|
# --- REPLACE THIS FUNCTION ENTIRELY ---
|
|
def self.preprocess_lona_booba_pose_json(lona_json, booba_json)
|
|
json = []
|
|
|
|
apply = lambda do |pose, mode|
|
|
json << pose
|
|
return unless pose["name_order"]
|
|
|
|
pose["name_order"] << "BigBooba"
|
|
|
|
old_bmps = pose["bmps"]
|
|
pose["bmps"] = {}
|
|
|
|
old_bmps.each do |k, v|
|
|
if mode == :lona
|
|
pose["bmps"]["#{k},BigBooba00"] = v
|
|
next unless booba_json.empty?
|
|
end
|
|
|
|
path = "#{BOOBA_MOD_PATH}Graphics/Portrait/Lona/#{v}"
|
|
pose["bmps"]["#{k},BigBooba01"] =
|
|
File.exist?(path) ? "../../../#{path}" : v
|
|
end
|
|
end
|
|
|
|
lona_json.each { |pose| apply.call(pose, :lona) }
|
|
booba_json.each { |pose| apply.call(pose, :booba) }
|
|
json
|
|
end
|
|
end
|
|
# Online game: visual relay through WebSocket. ModPersistencePlugin is optional
|
|
# for per-profile Cosmetic Mode persistence; other players still need this mod.
|
|
load_script("#{BOOBA_MOD_PATH}Scripts/01_OnlineSync.rb") if defined?(WebSocket) && respond_to?(:load_script, true)
|