Update ObjectVariables.ext

Added proper support for mangos
Removed map specific variables
This commit is contained in:
Rochet2
2015-08-15 22:24:03 +03:00
parent b6740496bf
commit a0e5e623c3

View File

@@ -7,74 +7,64 @@
-- filename.ext files are loaded before normal .lua files
local variableStores = {
Map = {},
Player = {},
Creature = {},
GameObject = {},
}
local function DestroyData(event, obj)
if (event == 18) then
local mapid = obj:GetMapId()
local instid = obj:GetInstanceId()
if (variableStores.Map[mapid]) then
variableStores.Map[mapid][instid] = nil
if event == 18 or event == 17 then
local map = obj:GetMapId()
local inst = obj:GetInstanceId()
for k,v in pairs(variableStores) do
if inst == 0 then
v[map] = nil
else
local mapdata = v[map]
if mapdata then
mapdata[inst] = nil
end
end
end
return
end
local mapdata = variableStores[obj:GetObjectType()][obj:GetMapId()]
if mapdata then
local instancedata = mapdata[obj:GetInstanceId()]
if instancedata then
instancedata[obj:GetGUIDLow()] = nil
end
else
variableStores[obj:GetObjectType()][obj:GetGUIDLow()] = nil
end
end
local function GetData(self, field)
local Type = self:GetObjectType()
local varStore = variableStores[Type]
local id
if (Type == "Map") then
local mapid = self:GetMapId()
varStore = varStore[mapid]
if (not varStore) then
return nil
end
id = self:GetInstanceId()
else
id = self:GetGUIDLow()
end
local varStore = variableStores[self:GetObjectType()]
local guid = self:GetGUIDLow()
local map = self:GetMapId()
local inst = self:GetInstanceId()
if (not varStore[id]) then
return nil
end
varStore[map] = varStore[map] or {}
varStore[map][inst] = varStore[map][inst] or {}
varStore[map][inst][guid] = varStore[map][inst][guid] or {}
if (field == nil) then
return varStore[id]
if field then
return varStore[map][inst][guid][field]
else
return varStore[id][field]
return varStore[map][inst][guid]
end
end
local function SetData(self, field, val)
assert(field ~= nil, "field was nil", 2)
local varStore = variableStores[self:GetObjectType()]
local guid = self:GetGUIDLow()
local map = self:GetMapId()
local inst = self:GetInstanceId()
local Type = self:GetObjectType()
local varStore = variableStores[Type]
local id
if (Type == "Map") then
local mapid = self:GetMapId()
varStore[map] = varStore[map] or {}
varStore[map][inst] = varStore[map][inst] or {}
varStore[map][inst][guid] = varStore[map][inst][guid] or {}
if (not varStore[mapid]) then
varStore[mapid] = {}
end
varStore = varStore[mapid]
id = self:GetInstanceId()
else
id = self:GetGUIDLow()
end
if (not varStore[id]) then
varStore[id] = {}
end
varStore[id][field] = val
varStore[map][inst][guid][field] = val
end
for k,v in pairs(variableStores) do
@@ -82,7 +72,9 @@ for k,v in pairs(variableStores) do
_G[k].SetData = SetData
end
RegisterPlayerEvent(4, DestroyData)
RegisterServerEvent(31, DestroyData)
RegisterServerEvent(32, DestroyData)
RegisterServerEvent(18, DestroyData)
RegisterPlayerEvent(3, DestroyData) -- login
RegisterPlayerEvent(4, DestroyData) -- logout
RegisterServerEvent(31, DestroyData) -- creature delete
RegisterServerEvent(32, DestroyData) -- gameobject delete
RegisterServerEvent(17, DestroyData) -- map create
RegisterServerEvent(18, DestroyData) -- map destroy