mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Make player data accessible regardless of map
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
-- local val = obj:GetData(key)
|
-- local val = obj:GetData(key)
|
||||||
--
|
--
|
||||||
|
|
||||||
|
local pairs = pairs
|
||||||
|
|
||||||
local variableStores = {
|
local variableStores = {
|
||||||
Map = {},
|
Map = {},
|
||||||
Player = {},
|
Player = {},
|
||||||
@@ -37,10 +39,16 @@ local function DestroyMapData(event, obj)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function DestroyObjData(event, obj)
|
local function DestroyObjData(event, obj)
|
||||||
local map = obj:GetMapId()
|
|
||||||
local inst = obj:GetInstanceId()
|
|
||||||
local otype = obj:GetObjectType()
|
local otype = obj:GetObjectType()
|
||||||
local guid = otype == "Map" and 1 or obj:GetGUIDLow()
|
local guid = otype == "Map" and 1 or obj:GetGUIDLow()
|
||||||
|
|
||||||
|
if otype == "Player" then
|
||||||
|
varStore[guid] = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local map = obj:GetMapId()
|
||||||
|
local inst = obj:GetInstanceId()
|
||||||
local mapdata = variableStores[otype][map]
|
local mapdata = variableStores[otype][map]
|
||||||
if mapdata then
|
if mapdata then
|
||||||
local instancedata = mapdata[inst]
|
local instancedata = mapdata[inst]
|
||||||
@@ -51,30 +59,43 @@ local function DestroyObjData(event, obj)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function GetData(self, field)
|
local function GetData(self, field)
|
||||||
local map = self:GetMapId()
|
|
||||||
local inst = self:GetInstanceId()
|
|
||||||
local otype = self:GetObjectType()
|
local otype = self:GetObjectType()
|
||||||
local guid = otype == "Map" and 1 or self:GetGUIDLow()
|
local guid = otype == "Map" and 1 or self:GetGUIDLow()
|
||||||
local varStore = variableStores[otype]
|
local varStore = variableStores[otype]
|
||||||
|
|
||||||
|
if otype == "Player" then
|
||||||
|
varStore[guid] = varStore[guid] or {}
|
||||||
|
if field ~= nil then
|
||||||
|
return varStore[guid][field]
|
||||||
|
end
|
||||||
|
return varStore[guid]
|
||||||
|
end
|
||||||
|
|
||||||
|
local map = self:GetMapId()
|
||||||
|
local inst = self:GetInstanceId()
|
||||||
varStore[map] = varStore[map] or {}
|
varStore[map] = varStore[map] or {}
|
||||||
varStore[map][inst] = varStore[map][inst] or {}
|
varStore[map][inst] = varStore[map][inst] or {}
|
||||||
varStore[map][inst][guid] = varStore[map][inst][guid] or {}
|
varStore[map][inst][guid] = varStore[map][inst][guid] or {}
|
||||||
|
|
||||||
if field ~= nil then
|
if field ~= nil then
|
||||||
return varStore[map][inst][guid][field]
|
return varStore[map][inst][guid][field]
|
||||||
else
|
|
||||||
return varStore[map][inst][guid]
|
|
||||||
end
|
end
|
||||||
|
return varStore[map][inst][guid]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function SetData(self, field, val)
|
local function SetData(self, field, val)
|
||||||
local map = self:GetMapId()
|
|
||||||
local inst = self:GetInstanceId()
|
|
||||||
local otype = self:GetObjectType()
|
local otype = self:GetObjectType()
|
||||||
local guid = otype == "Map" and 1 or self:GetGUIDLow()
|
local guid = otype == "Map" and 1 or self:GetGUIDLow()
|
||||||
local varStore = variableStores[otype]
|
local varStore = variableStores[otype]
|
||||||
|
|
||||||
|
if otype == "Player" then
|
||||||
|
varStore[guid] = varStore[guid] or {}
|
||||||
|
varStore[guid][field] = val
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local map = self:GetMapId()
|
||||||
|
local inst = self:GetInstanceId()
|
||||||
varStore[map] = varStore[map] or {}
|
varStore[map] = varStore[map] or {}
|
||||||
varStore[map][inst] = varStore[map][inst] or {}
|
varStore[map][inst] = varStore[map][inst] or {}
|
||||||
varStore[map][inst][guid] = varStore[map][inst][guid] or {}
|
varStore[map][inst][guid] = varStore[map][inst][guid] or {}
|
||||||
|
|||||||
Reference in New Issue
Block a user