доработка игровых режимов
This commit is contained in:
@@ -1,86 +1,7 @@
|
|||||||
local AIO = AIO or require("AIO")
|
-- Game-mode UI synchronization is client-native since MoonWellClient 2.0.
|
||||||
|
--
|
||||||
local ADDON_NAME = "MoonWellClient"
|
-- The authoritative mode still comes from the server in SMSG_CHAR_ENUM as
|
||||||
local HANDLER_NAME = "Init"
|
-- CHARACTER_FLAG_UNK31 (0x40000000). WarcraftXL retains that bit while WoW
|
||||||
local GAME_MODE_NORMAL = 0
|
-- switches from GlueXML to the in-world FrameXML Lua state. Keeping this file
|
||||||
local GAME_MODE_TRAITOR = 1
|
-- as a no-op avoids stale deployment scripts failing on a missing path while
|
||||||
local PLAYER_EVENT_ON_LOGIN = 3
|
-- removing the timing-sensitive AIO login event completely.
|
||||||
local AIO_INIT_SEND_DELAY_MS = 1000
|
|
||||||
|
|
||||||
local MoonWellAIO = rawget(_G, "MoonWellAIO") or {}
|
|
||||||
_G.MoonWellAIO = MoonWellAIO
|
|
||||||
local PendingSyncEvents = {}
|
|
||||||
|
|
||||||
local function GetPlayerGameMode(player)
|
|
||||||
if not player then
|
|
||||||
return GAME_MODE_NORMAL
|
|
||||||
end
|
|
||||||
|
|
||||||
local query = CharDBQuery(
|
|
||||||
"SELECT game_mode FROM mod_gamemodes_characters WHERE guid = " .. player:GetGUIDLow() .. " LIMIT 1"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not query or query:IsNull(0) then
|
|
||||||
return GAME_MODE_NORMAL
|
|
||||||
end
|
|
||||||
|
|
||||||
local gameMode = query:GetUInt8(0)
|
|
||||||
if gameMode == GAME_MODE_TRAITOR then
|
|
||||||
return GAME_MODE_TRAITOR
|
|
||||||
end
|
|
||||||
|
|
||||||
return GAME_MODE_NORMAL
|
|
||||||
end
|
|
||||||
|
|
||||||
function MoonWellAIO.GetPlayerGameMode(player)
|
|
||||||
return GetPlayerGameMode(player)
|
|
||||||
end
|
|
||||||
|
|
||||||
function MoonWellAIO.SendPlayerGameMode(player)
|
|
||||||
if not player then
|
|
||||||
return GAME_MODE_NORMAL
|
|
||||||
end
|
|
||||||
|
|
||||||
local gameMode = GetPlayerGameMode(player)
|
|
||||||
AIO.Handle(player, ADDON_NAME, HANDLER_NAME, gameMode)
|
|
||||||
return gameMode
|
|
||||||
end
|
|
||||||
|
|
||||||
local function CancelPendingSync(playerGuidLow)
|
|
||||||
local eventId = PendingSyncEvents[playerGuidLow]
|
|
||||||
if eventId then
|
|
||||||
RemoveEventById(eventId)
|
|
||||||
PendingSyncEvents[playerGuidLow] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function MoonWellAIO.SchedulePlayerGameMode(player, delayMs)
|
|
||||||
if not player then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local playerGuidLow = player:GetGUIDLow()
|
|
||||||
local playerGuid = player:GetGUID()
|
|
||||||
|
|
||||||
CancelPendingSync(playerGuidLow)
|
|
||||||
|
|
||||||
PendingSyncEvents[playerGuidLow] = CreateLuaEvent(function()
|
|
||||||
PendingSyncEvents[playerGuidLow] = nil
|
|
||||||
|
|
||||||
local onlinePlayer = GetPlayerByGUID(playerGuid)
|
|
||||||
if onlinePlayer then
|
|
||||||
MoonWellAIO.SendPlayerGameMode(onlinePlayer)
|
|
||||||
end
|
|
||||||
end, delayMs or AIO_INIT_SEND_DELAY_MS, 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Do not append MoonWellClient blocks directly into the AIO init packet:
|
|
||||||
-- the client addon may register its handlers slightly later than AIO itself.
|
|
||||||
AIO.AddOnInit(function(msg, player)
|
|
||||||
MoonWellAIO.SchedulePlayerGameMode(player, AIO_INIT_SEND_DELAY_MS)
|
|
||||||
return msg
|
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterPlayerEvent(PLAYER_EVENT_ON_LOGIN, function(_, player)
|
|
||||||
MoonWellAIO.SchedulePlayerGameMode(player, AIO_INIT_SEND_DELAY_MS)
|
|
||||||
end)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user