Release 0.0.1.8.8.7
This commit is contained in:
1 parent
3c8a17aa78
commit
c7beab414c
16283 files changed
+768761
-2
No files matched your search
@@ -0,0 +1,240 @@
|
||||
# encoding: UTF-8
|
||||
# Server-authorized GOD mode. The flag is runtime-only, never stored in a save.
|
||||
module MPGodMode
|
||||
STATS = %w[health sta sat mood].freeze
|
||||
class << self
|
||||
def actor
|
||||
$game_player.actor if defined?($game_player) && $game_player && $game_player.respond_to?(:actor)
|
||||
end
|
||||
def active?
|
||||
!!@enabled && defined?(WebSocket) && WebSocket.respond_to?(:admin_owner_active?) && WebSocket.admin_owner_active? && Time.now.to_f < @expires.to_f
|
||||
end
|
||||
def protects?(target)
|
||||
active? && target && target.equal?(actor)
|
||||
end
|
||||
def maximum(table, name)
|
||||
row = table.get_stat_data(name)
|
||||
return nil unless row.is_a?(Array) && row[ActorStat::MAX_STAT].is_a?(Numeric)
|
||||
[row[ActorStat::MAX_STAT], 1].max
|
||||
end
|
||||
def reset
|
||||
@enabled = false
|
||||
@expires = 0
|
||||
@hello_at = nil
|
||||
@pending_at = nil
|
||||
end
|
||||
def set(on)
|
||||
changed = @enabled != on
|
||||
@enabled = on
|
||||
@expires = Time.now.to_f + 35
|
||||
@pending_at = nil
|
||||
refill if on
|
||||
WebSocket.chat_local_system(on ? "GOD включён: урон отключён, здоровье, выносливость, сытость и настроение полные." : "GOD выключен.") if changed && WebSocket.respond_to?(:chat_local_system)
|
||||
refresh_menu
|
||||
end
|
||||
def pending?
|
||||
@pending_at && Time.now.to_f - @pending_at < 6
|
||||
end
|
||||
def label
|
||||
return "GOD: проверка сервера..." if pending?
|
||||
active? ? "GOD: ВКЛ" : "GOD: ВЫКЛ"
|
||||
end
|
||||
def request_toggle
|
||||
return if pending? || !WebSocket.connected? || !WebSocket.admin_owner_active?
|
||||
@pending_at = Time.now.to_f
|
||||
WebSocket.send_line("god_toggle:#{active? ? 0 : 1}")
|
||||
# Never enable locally here. Only god_state from the server changes the flag.
|
||||
refresh_menu
|
||||
end
|
||||
def refresh_menu
|
||||
scene = SceneManager.scene if defined?(SceneManager)
|
||||
scene.mp_god_refresh if scene && scene.respond_to?(:mp_god_refresh)
|
||||
end
|
||||
def refill
|
||||
target = actor
|
||||
return unless protects?(target)
|
||||
table = target.battle_stat
|
||||
STATS.each do |name|
|
||||
row = table.get_stat_data(name)
|
||||
value = maximum(table, name)
|
||||
next if !row || !value || row[ActorStat::CURRENT_STAT] == value
|
||||
# Raw table writes elsewhere in the game are corrected without recursively
|
||||
# invoking health/stamina side effects or generating experience from costs.
|
||||
row[ActorStat::CURRENT_STAT] = value
|
||||
row[ActorStat::STAT_CHANGED] = true
|
||||
target.instance_variable_set(:@stat_changed, true)
|
||||
end
|
||||
target.instance_variable_set(:@hp, [target.mhp.to_i, 1].max) if target.respond_to?(:mhp)
|
||||
end
|
||||
def tick
|
||||
unless WebSocket.connected?
|
||||
reset
|
||||
return
|
||||
end
|
||||
if WebSocket.admin_owner_active? && WebSocket.bootstrap_sync_unlocked? && (!@hello_at || Time.now.to_f - @hello_at > 10)
|
||||
@hello_at = Time.now.to_f
|
||||
WebSocket.send_line("god_hello:1")
|
||||
end
|
||||
refill
|
||||
if @pending_at && !pending?
|
||||
@pending_at = nil
|
||||
refresh_menu
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Extend the existing admin menu opened by backslash (MPAdminMenu::OPEN_VK).
|
||||
# Do not replace its hotkey, style, kick, or ban handlers.
|
||||
if defined?(Scene_Map) && Scene_Map.method_defined?(:mp_admin_show_commands)
|
||||
class Scene_Map
|
||||
alias godmode_admin_show mp_admin_show_commands
|
||||
def mp_admin_show_commands(commands, state, width = 320, font = nil)
|
||||
rows = commands.dup
|
||||
# Backward compatible with older menu scripts, without duplicating
|
||||
# the GOD tile provided by the icon-grid version.
|
||||
if state == :root && WebSocket.admin_owner_active? &&
|
||||
!rows.any? { |entry| entry[1] == :god_toggle }
|
||||
rows << [MPGodMode.label, :god_toggle, !MPGodMode.pending?, nil]
|
||||
end
|
||||
godmode_admin_show(rows, state, width, font)
|
||||
@mp_admin_window.set_handler(:god_toggle, method(:mp_god_toggle)) if @mp_admin_window && state == :root
|
||||
end
|
||||
def mp_god_toggle
|
||||
MPGodMode.request_toggle
|
||||
@mp_admin_window.activate if @mp_admin_window
|
||||
end
|
||||
def mp_god_refresh
|
||||
return unless @mp_admin_state == :root && @mp_admin_window && !@mp_admin_window.disposed?
|
||||
# New icon grid stores entries in @mp_entries, not @mp_commands.
|
||||
# Update in place without losing selected cell or action handlers.
|
||||
rows = @mp_admin_window.instance_variable_get(:@mp_entries)
|
||||
if rows.is_a?(Array)
|
||||
rows.each do |row|
|
||||
next unless row[1] == :god_toggle
|
||||
row[0] = MPGodMode.label
|
||||
row[2] = !MPGodMode.pending?
|
||||
end
|
||||
@mp_admin_window.refresh
|
||||
elsif @mp_admin_window.respond_to?(:set_commands)
|
||||
rows = @mp_admin_window.instance_variable_get(:@mp_commands)
|
||||
return unless rows.is_a?(Array)
|
||||
@mp_admin_window.set_commands(rows.map { |row|
|
||||
row[1] == :god_toggle ? [MPGodMode.label, :god_toggle, !MPGodMode.pending?, nil] : row
|
||||
})
|
||||
end
|
||||
@mp_admin_window.activate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module WebSocket
|
||||
class << self
|
||||
# Invalidate GOD immediately when the server revokes OWNER privileges.
|
||||
alias godmode_admin_set_role admin_set_role
|
||||
def admin_set_role(role_name)
|
||||
result = godmode_admin_set_role(role_name)
|
||||
MPGodMode.reset unless admin_owner_active?
|
||||
result
|
||||
end
|
||||
alias godmode_parse parse
|
||||
def parse(message)
|
||||
if message == "god_state:1" || message == "god_state:0"
|
||||
MPGodMode.set(message.end_with?(":1"))
|
||||
return
|
||||
elsif message.start_with?("god_notice:")
|
||||
chat_local_system(unesc(message.split(":",2)[1])) if respond_to?(:chat_local_system)
|
||||
return
|
||||
end
|
||||
godmode_parse(message)
|
||||
end
|
||||
alias godmode_update update
|
||||
def update(*args)
|
||||
MPGodMode.refill
|
||||
result = godmode_update(*args)
|
||||
MPGodMode.tick
|
||||
result
|
||||
end
|
||||
alias godmode_disconnect disconnect
|
||||
def disconnect(*args)
|
||||
MPGodMode.reset
|
||||
godmode_disconnect(*args)
|
||||
end
|
||||
alias godmode_attacked handle_being_attacked
|
||||
def handle_being_attacked(*args)
|
||||
return if MPGodMode.active?
|
||||
godmode_attacked(*args)
|
||||
end
|
||||
if method_defined?(:_mp_pvp_apply_skill_payload)
|
||||
alias godmode_skill_payload _mp_pvp_apply_skill_payload
|
||||
def _mp_pvp_apply_skill_payload(*args)
|
||||
return true if MPGodMode.active?
|
||||
godmode_skill_payload(*args)
|
||||
end
|
||||
end
|
||||
alias godmode_remote_action handle_remote_deistvia
|
||||
def handle_remote_deistvia(player_id, action_id, phase, payload)
|
||||
return if MPGodMode.active? && action_id.to_s == "pvp_skill_hit"
|
||||
godmode_remote_action(player_id, action_id, phase, payload)
|
||||
end
|
||||
alias godmode_stats _live_sync_collect_stats
|
||||
def _live_sync_collect_stats(actor)
|
||||
MPGodMode.refill
|
||||
godmode_stats(actor)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class LonaActorStat
|
||||
alias godmode_set_stat set_stat
|
||||
def set_stat(name, value, type = CURRENT_STAT)
|
||||
if type == CURRENT_STAT && MPGodMode::STATS.include?(name) && MPGodMode.protects?(@actor)
|
||||
row = get_stat_data(name)
|
||||
row[CURRENT_STAT] = MPGodMode.maximum(self, name) if row
|
||||
row[STAT_CHANGED] = true if row
|
||||
return
|
||||
end
|
||||
godmode_set_stat(name, value, type)
|
||||
end
|
||||
alias godmode_get_stat get_stat
|
||||
def get_stat(name, type = CURRENT_STAT)
|
||||
if type == CURRENT_STAT && MPGodMode::STATS.include?(name) && MPGodMode.protects?(@actor)
|
||||
value = MPGodMode.maximum(self, name)
|
||||
return value if value
|
||||
end
|
||||
godmode_get_stat(name, type)
|
||||
end
|
||||
end
|
||||
|
||||
class Game_Actor
|
||||
alias godmode_take_damage take_damage
|
||||
def take_damage(*args)
|
||||
return 0 if MPGodMode.protects?(self)
|
||||
godmode_take_damage(*args)
|
||||
end
|
||||
alias godmode_determine_death determine_death
|
||||
def determine_death(*args)
|
||||
return if MPGodMode.protects?(self)
|
||||
godmode_determine_death(*args)
|
||||
end
|
||||
alias godmode_lona_death lonaDeath?
|
||||
def lonaDeath?
|
||||
return false if MPGodMode.protects?(self)
|
||||
godmode_lona_death
|
||||
end
|
||||
alias godmode_die die
|
||||
def die
|
||||
return if MPGodMode.protects?(self)
|
||||
godmode_die
|
||||
end
|
||||
alias godmode_action_state set_action_state
|
||||
def set_action_state(state, *args)
|
||||
return if state == :death && MPGodMode.protects?(self)
|
||||
godmode_action_state(state, *args)
|
||||
end
|
||||
alias godmode_hp_set hp=
|
||||
def hp=(value)
|
||||
value = [mhp.to_i, 1].max if MPGodMode.protects?(self)
|
||||
self.godmode_hp_set(value)
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user