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

130 lines
4.3 KiB
Ruby

# encoding: UTF-8
#==============================================================================
# PvPHealSafeZoneRecv — apply Исцеление души in safe zones on the receiver.
#------------------------------------------------------------------------------
# Loads AFTER 99999999999999999996_PvPCombatUXFix.rb. Older UX builds drop ALL
# pvp_skill_hit in safe zones before 98_pvp_skill_sync can run; this wrapper
# intercepts heal packets first and applies HP/STA locally.
#
# Required on the healed client's ModScripts (whitelist this file once).
#==============================================================================
return unless defined?(WebSocket)
module WebSocket
def self._mp_heal_sz_recv_payload_heal?(payload)
return false if payload.nil?
h = payload
if payload.is_a?(String)
begin
h = respond_to?(:_deistvia_unpack) ? _deistvia_unpack(payload.to_s) : {}
rescue
h = {}
end
end
return false unless h.is_a?(Hash)
return true if h["heal"].to_s == "1"
return true if h["sup"].to_s == "1" && (
h["skill_name"].to_s.include?("NunHeal") ||
h["skill"].to_s.include?("NunHeal") ||
h["hp"].to_i < 0 || h["sta"].to_i < 0
)
sn = h["skill_name"].to_s
sn = h["skill"].to_s if sn.empty?
return true if sn == "BasicNunHeal" || sn.include?("NunHeal")
false
rescue
false
end
class << self
if method_defined?(:handle_remote_deistvia) && !method_defined?(:mp_heal_sz_recv_old_handle_remote_deistvia)
alias_method :mp_heal_sz_recv_old_handle_remote_deistvia, :handle_remote_deistvia
end
end
if respond_to?(:mp_heal_sz_recv_old_handle_remote_deistvia)
def self.handle_remote_deistvia(player_id, action_id, phase, payload)
if action_id.to_s == "pvp_skill_hit" && phase.to_s != "stop" && _mp_heal_sz_recv_payload_heal?(payload)
payload_hash = {}
begin
if payload.is_a?(Hash)
payload_hash = payload
else
payload_hash = respond_to?(:_deistvia_unpack) ? _deistvia_unpack(payload.to_s) : {}
end
rescue
payload_hash = {}
end
target_id = (payload_hash["target"] || payload_hash["tgt"] || payload_hash["target_id"]).to_i
my = (@my_id.to_i rescue 0)
if my > 0 && target_id == my
begin
_mp_heal_sz_recv_apply_local(player_id.to_i, payload_hash)
rescue
end
return
end
end
mp_heal_sz_recv_old_handle_remote_deistvia(player_id, action_id, phase, payload)
end
end
# Self-contained apply so older 98 without _mp_pvp_apply_heal_payload still works.
def self._mp_heal_sz_recv_apply_local(attacker_id, payload_hash)
if respond_to?(:_mp_pvp_apply_heal_payload)
return _mp_pvp_apply_heal_payload(attacker_id, payload_hash)
end
actor = nil
begin
actor = _mp_pvp_local_actor if respond_to?(:_mp_pvp_local_actor)
rescue
actor = nil
end
begin
actor = $game_player.actor if actor.nil? && $game_player && $game_player.respond_to?(:actor)
rescue
actor = nil
end
return false if actor.nil?
hp_heal = payload_hash["hp"].to_i.abs
sta_heal = payload_hash["sta"].to_i.abs
return false if hp_heal <= 0 && sta_heal <= 0
begin
actor.health = actor.health.to_f + hp_heal.to_f if hp_heal > 0 && actor.respond_to?(:health=)
rescue
end
begin
actor.sta = actor.sta.to_f + sta_heal.to_f if sta_heal > 0 && actor.respond_to?(:sta=)
rescue
end
begin
if actor.respond_to?(:actor_ForceUpdate)
actor.actor_ForceUpdate
else
$game_player.update rescue nil
end
rescue
end
begin
dir = ($game_player.direction rescue 2)
tx = (payload_hash["tx"] || $game_player.x).to_i
ty = (payload_hash["ty"] || $game_player.y).to_i
if defined?($game_damage_popups) && $game_damage_popups
$game_damage_popups.add(hp_heal, tx, ty, dir, 10) if hp_heal > 0
$game_damage_popups.add(sta_heal, tx, ty, dir, 11) if sta_heal > 0
end
rescue
end
true
rescue
false
end
end
puts "[PVP-HEAL-SZ] receive patch loaded" rescue nil