You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.5 KiB

4 years ago
-- spells container file
local _detalhes = _G.Details
4 years ago
local _
local addonName, Details222 = ...
4 years ago
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--local pointers
4 years ago
local setmetatable = setmetatable --lua local
4 years ago
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--constants
4 years ago
local container_damage = _detalhes.container_type.CONTAINER_DAMAGE_CLASS
local container_heal = _detalhes.container_type.CONTAINER_HEAL_CLASS
local container_energy = _detalhes.container_type.CONTAINER_ENERGY_CLASS
local container_misc = _detalhes.container_type.CONTAINER_MISC_CLASS
local habilidade_dano = _detalhes.habilidade_dano
local habilidade_cura = _detalhes.habilidade_cura
local habilidade_e_energy = _detalhes.habilidade_e_energy
local habilidade_misc = _detalhes.habilidade_misc
local container_habilidades = _detalhes.container_habilidades
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--internals
4 years ago
function container_habilidades:NovoContainer (tipo_do_container)
local _newContainer = {
funcao_de_criacao = container_habilidades:FuncaoDeCriacao (tipo_do_container),
tipo = tipo_do_container,
_ActorTable = {}
}
setmetatable(_newContainer, container_habilidades)
4 years ago
return _newContainer
end
---get the spellTable for the passed spellId
---@param spellId number
---@return table
function container_habilidades:GetSpell(spellId)
return self._ActorTable[spellId]
4 years ago
end
---return a table containing keys as spellid and value as spelltable
---@return table<number, table>
function container_habilidades:GetRawSpellTable()
return self._ActorTable
end
---return the value of the spellTable[key] for the passed spellId
---@param spellId number
---@param key string
---@return any
function container_habilidades:GetAmount(spellId, key)
local spell = self._ActorTable[spellId]
4 years ago
if (spell) then
return spell[key]
4 years ago
end
end
---return an iterator for all spellTables in this container
---@param self spellcontainer
---@return fun(table: table<<K>, <V>>, index?: <K>):<K>, <V>
4 years ago
function container_habilidades:ListActors()
3 years ago
return pairs(self._ActorTable)
4 years ago
end
--same as the function above, just an alias
function container_habilidades:ListSpells()
return pairs(self._ActorTable)
end
4 years ago
function container_habilidades:GetOrCreateSpell(id, shouldCreate, token)
return self:PegaHabilidade (id, shouldCreate, token)
end
---return (boolean) if the container two or more spells within
---@return boolean
function container_habilidades:HasTwoOrMoreSpells()
local count = 0
for _ in pairs(self._ActorTable) do
count = count + 1
if (count >= 2) then
return true
end
end
return false
end
4 years ago
function container_habilidades:PegaHabilidade (id, criar, token)
4 years ago
local esta_habilidade = self._ActorTable [id]
4 years ago
if (esta_habilidade) then
return esta_habilidade
else
if (criar) then
4 years ago
local novo_objeto = self.funcao_de_criacao (nil, id, nil, token)
4 years ago
self._ActorTable [id] = novo_objeto
4 years ago
return novo_objeto
else
return nil
end
end
end
function container_habilidades:FuncaoDeCriacao (tipo)
if (tipo == container_damage) then
return habilidade_dano.NovaTabela
4 years ago
elseif (tipo == container_heal) then
return habilidade_cura.NovaTabela
elseif (tipo == container_energy) then
return habilidade_e_energy.NovaTabela
4 years ago
elseif (tipo == container_misc) then
return habilidade_misc.NovaTabela
4 years ago
end
end
function _detalhes.refresh:r_container_habilidades (container, shadow)
3 years ago
--reconstr�i meta e indexes
setmetatable(container, _detalhes.container_habilidades)
4 years ago
container.__index = _detalhes.container_habilidades
local func_criacao = container_habilidades:FuncaoDeCriacao (container.tipo)
container.funcao_de_criacao = func_criacao
end
function _detalhes.clear:c_container_habilidades (container)
--container.__index = {}
container.__index = nil
container.shadow = nil
container.funcao_de_criacao = nil
end