режим предателя
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
local AIO = AIO or require("AIO")
|
||||
|
||||
local ADDON_NAME = "MoonWellClient"
|
||||
local HANDLER_NAME = "Init"
|
||||
local GAME_MODE_NORMAL = 0
|
||||
local GAME_MODE_TRAITOR = 1
|
||||
local PLAYER_EVENT_ON_LOGIN = 3
|
||||
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