Files
LonaRPG-Online-Games/ModScripts/99999_OnlineUniqueNpcFixes.rb
T
2026-10-29 21:59:06 +04:00

307 lines
7.2 KiB
Ruby

# encoding: UTF-8
return if defined?($mp_online_unique_npc_fixes_loaded) && $mp_online_unique_npc_fixes_loaded
$mp_online_unique_npc_fixes_loaded = true
module MPOnlineUniqueNpcFixes
UNIQUE_STORY_KEYS = {
"UniqueCecily" => "UniqueCharUniqueCecily",
"UniqueGrayRat" => "UniqueCharUniqueGrayRat"
}
UNIQUE_DEATH_EVENTS = [
"EffectUniqueCecilyDed",
"EffectUniqueGrayRatDed"
]
def self.story_key_for_npc(npc_name)
UNIQUE_STORY_KEYS[npc_name.to_s]
end
def self.unique_death_event?(event_name)
UNIQUE_DEATH_EVENTS.include?(event_name.to_s)
end
def self.unique_npc?(npc_name)
UNIQUE_STORY_KEYS.has_key?(npc_name.to_s)
end
def self.unique_dead?(npc_name)
key = story_key_for_npc(npc_name)
return false if key.nil?
begin
return $story_stats[key] == -1
rescue
return false
end
end
def self.mark_unique_dead(npc_name)
key = story_key_for_npc(npc_name)
return if key.nil?
begin
$story_stats[key] = -1 if $story_stats && $story_stats.respond_to?(:[]=)
rescue
end
begin
WebSocket.net_set_story(key, -1, "int") if defined?(WebSocket)
rescue
end
begin
cleanup_current_map_unique(npc_name)
rescue
end
end
def self.cleanup_current_map_unique(npc_name)
return unless $game_map && $game_map.respond_to?(:events)
events = $game_map.events
return unless events && events.respond_to?(:each_value)
events.each_value do |ev|
next if ev.nil?
begin
next if ev.deleted?
rescue
end
event_npc_name = nil
begin
event_npc_name = ev.npc.npc_name if ev.respond_to?(:npc?) && ev.npc?
rescue
event_npc_name = nil
end
begin
event_npc_name = ev.instance_variable_get(:@npc_name) if event_npc_name.nil?
rescue
end
next unless event_npc_name.to_s == npc_name.to_s
begin
ev.delete
rescue
begin
ev.instance_variable_set(:@deleted, true)
rescue
end
end
end
begin
$game_map.need_refresh = true
rescue
end
end
def self.cleanup_all_dead_uniques
UNIQUE_STORY_KEYS.keys.each do |npc_name|
cleanup_current_map_unique(npc_name) if unique_dead?(npc_name)
end
end
def self.safe_delete_broken_unique_death_event(ev)
begin
ev.instance_variable_set(:@deleted, true)
ev.instance_variable_set(:@initialized, true)
rescue
end
nil
end
end
if defined?(Game_NonPlayerCharacter)
class Game_NonPlayerCharacter
unless method_defined?(:mp_unique_fix_summon_death_event__orig)
alias mp_unique_fix_summon_death_event__orig summon_death_event
end
def summon_death_event(*args)
begin
MPOnlineUniqueNpcFixes.mark_unique_dead(npc_name)
rescue
end
mp_unique_fix_summon_death_event__orig(*args)
end
end
end
if defined?(Game_Event)
class Game_Event
def mp_unique_fix_broken_death_event?
event_name = nil
begin
event_name = @event.name
rescue
event_name = nil
end
return false unless MPOnlineUniqueNpcFixes.unique_death_event?(event_name)
data = nil
begin
data = @summon_data
rescue
data = nil
end
return true if data.nil?
return true unless data.respond_to?(:[])
user = nil
begin
user = data[:user]
rescue
user = nil
end
return true if user.nil?
false
end
unless method_defined?(:mp_unique_fix_find_proper_page__orig)
alias mp_unique_fix_find_proper_page__orig find_proper_page
end
def find_proper_page(*args)
if mp_unique_fix_broken_death_event?
begin
prp "skip broken unique death event #{@event.name} x=#{@event.x} y=#{@event.y}", 5
rescue
end
return MPOnlineUniqueNpcFixes.safe_delete_broken_unique_death_event(self)
end
mp_unique_fix_find_proper_page__orig(*args)
rescue RuntimeError, NoMethodError => e
event_name = nil
begin
event_name = @event.name
rescue
event_name = nil
end
if MPOnlineUniqueNpcFixes.unique_death_event?(event_name)
begin
prp "recover broken unique death event #{event_name}: #{e.class}: #{e.message}", 5
rescue
end
return MPOnlineUniqueNpcFixes.safe_delete_broken_unique_death_event(self)
end
raise
end
unless method_defined?(:mp_unique_fix_set_npc__orig)
alias mp_unique_fix_set_npc__orig set_npc
end
def set_npc(npc)
result = mp_unique_fix_set_npc__orig(npc)
begin
if MPOnlineUniqueNpcFixes.unique_dead?(npc)
delete
end
rescue
end
result
end
end
end
if defined?(Sex)
module Sex
def mp_unique_fix_safe_chs_configuration
cfg = nil
begin
cfg = @chs_configuration
rescue
cfg = nil
end
unless cfg.is_a?(Hash)
cfg = {}
begin
@chs_configuration = cfg
rescue
end
end
cfg
end
def set_chs_sex(pose, position)
p "set_chs_sex(#{pose},#{position})"
set_chs_sex_prev_zoomXY
actor.remove_stun_verbs if actor
cfg = mp_unique_fix_safe_chs_configuration
cfg["sex_pos"] = pose
cfg["sex_position"] = position
@sex_state = 1
@tile_id = 0
@chs_need_update = true
end
def unset_chs_sex(release=false)
set_chs_sex_recover_zoomXY
self.animation = nil
cfg = mp_unique_fix_safe_chs_configuration
cfg["sex_pos"] = -1
cfg["sex_position"] = -1
@chs_need_update = true
@story_mode_sex = nil
@eventSexMode = nil
@prev_action_state = nil
if actor
actor.fucker_target.quit_sex_gang(self) if !actor.fucker_target.nil?
actor.fucker_target = nil
actor.set_action_state(:none, true)
end
@sex_state = -1
@grabber = nil
actor.refresh if actor
end
def set_event_chs_sex(pose, position)
set_chs_sex_prev_zoomXY
cfg = mp_unique_fix_safe_chs_configuration
cfg["sex_pos"] = pose
cfg["sex_position"] = position
@chs_need_update = true
end
def unset_event_chs_sex
set_chs_sex_recover_zoomXY
cfg = mp_unique_fix_safe_chs_configuration
cfg["sex_pos"] = -1
cfg["sex_position"] = -1
@chs_need_update = true
@story_mode_sex = nil
end
end
end
if defined?(WebSocket)
module WebSocket
class << self
unless method_defined?(:mp_unique_fix_apply_sync_var__orig)
alias mp_unique_fix_apply_sync_var__orig apply_sync_var
end
def apply_sync_var(name, vtype, val)
mp_unique_fix_apply_sync_var__orig(name, vtype, val)
begin
case name.to_s
when "UniqueCharUniqueCecily"
MPOnlineUniqueNpcFixes.cleanup_current_map_unique("UniqueCecily") if $story_stats && $story_stats[name] == -1
when "UniqueCharUniqueGrayRat"
MPOnlineUniqueNpcFixes.cleanup_current_map_unique("UniqueGrayRat") if $story_stats && $story_stats[name] == -1
end
rescue
end
end
end
end
end
begin
MPOnlineUniqueNpcFixes.cleanup_all_dead_uniques
rescue
end