feat: use the new statuses data
This commit is contained in:
parent
a53e367e01
commit
06b0fb76ba
1 changed files with 67 additions and 15 deletions
|
@ -72,17 +72,71 @@ end
|
||||||
-- STATUT HANDLING
|
-- STATUT HANDLING
|
||||||
|
|
||||||
function AbstractMobParent:addStatut(name, duration, source)
|
function AbstractMobParent:addStatut(name, duration, source)
|
||||||
local duration = duration or -1
|
local statut = self:getStatutData(name)
|
||||||
|
local duration = duration or 1
|
||||||
|
|
||||||
|
if (statut.remove ~= nil) then
|
||||||
|
duration = - self:removeStatutTurns(statut.remove, duration)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (duration > 0) then
|
||||||
|
if (statut.replaceAll == true) then
|
||||||
|
self:resetStatut()
|
||||||
|
else
|
||||||
|
self:removeStatut(name)
|
||||||
|
end
|
||||||
self.statuts[name] = {}
|
self.statuts[name] = {}
|
||||||
self.statuts[name].duration = duration
|
self.statuts[name].duration = duration
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function AbstractMobParent:getStatutKey(statutName)
|
||||||
|
local statut = self:getStatutData(statutName)
|
||||||
|
local key = ""
|
||||||
|
if (self.statuts[statutName] ~= nil) then
|
||||||
|
key = statutName
|
||||||
|
end
|
||||||
|
if (statut.alternative ~= nil) then
|
||||||
|
for _, alternative in ipairs(statut.alternative) do
|
||||||
|
if (self.statuts[alternative] ~= nil) then
|
||||||
|
key = alternative
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return key
|
||||||
end
|
end
|
||||||
|
|
||||||
function AbstractMobParent:haveStatuts(statutName)
|
function AbstractMobParent:haveStatuts(statutName)
|
||||||
return (self.statuts[statutName] ~= nil)
|
return (self.statuts[self:getStatutKey(statutName)] ~= nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
function AbstractMobParent:removeStatut(statutName)
|
function AbstractMobParent:removeStatut(statutName)
|
||||||
self.statuts[statutName] = nil
|
local key = self:getStatutKey(statutName)
|
||||||
|
if (key ~= nil) then
|
||||||
|
self.statuts[key] = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function AbstractMobParent:removeStatutTurns(statutName, turns)
|
||||||
|
local statut = self:getStatutData(statutName)
|
||||||
|
if (statut.temporary == false) then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
if (not self:haveStatuts(statutName)) then
|
||||||
|
return turns
|
||||||
|
end
|
||||||
|
local key = self:getStatutKey(statutName)
|
||||||
|
local relativeTurns = self.statuts[key].duration - turns
|
||||||
|
|
||||||
|
if (relativeTurns <= 0) then
|
||||||
|
self:removeStatut(statutName)
|
||||||
|
else
|
||||||
|
self.statuts[key].duration = relativeTurns
|
||||||
|
end
|
||||||
|
|
||||||
|
return relativeTurns
|
||||||
end
|
end
|
||||||
|
|
||||||
function AbstractMobParent:resetStatut()
|
function AbstractMobParent:resetStatut()
|
||||||
|
@ -98,22 +152,16 @@ function AbstractMobParent:isAlive()
|
||||||
end
|
end
|
||||||
|
|
||||||
function AbstractMobParent:removeOneTurnToStatut()
|
function AbstractMobParent:removeOneTurnToStatut()
|
||||||
for name, statut in pairs(self.statuts) do
|
for name, _ in pairs(self.statuts) do
|
||||||
if (statut ~= nil) then
|
self:removeStatutTurns(name, 1)
|
||||||
if (statut.duration == 1) then
|
|
||||||
self.statuts[name] = nil
|
|
||||||
else
|
|
||||||
self.statuts[name].duration = (statut.duration - 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function AbstractMobParent:getStatutsStat(statName)
|
function AbstractMobParent:getStatutsStat(statName)
|
||||||
local stat = 0
|
local stat = 0
|
||||||
for statutName, _ in pairs(self.statuts) do
|
for statutName, _ in pairs(self.statuts) do
|
||||||
local statut = statutStatList[statutName]
|
local statut = self:getStatutData(statutName)
|
||||||
if (statut ~= nil) then
|
if (statut.stats ~= nil) then
|
||||||
for _, statutStat in ipairs(statut.stats) do
|
for _, statutStat in ipairs(statut.stats) do
|
||||||
if (statutStat[1] == statName) then
|
if (statutStat[1] == statName) then
|
||||||
stat = stat + statutStat[2]
|
stat = stat + statutStat[2]
|
||||||
|
@ -124,4 +172,8 @@ function AbstractMobParent:getStatutsStat(statName)
|
||||||
return stat
|
return stat
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function AbstractMobParent:getStatutData(statutName)
|
||||||
|
return statutStatList[statutName]
|
||||||
|
end
|
||||||
|
|
||||||
return AbstractMobParent
|
return AbstractMobParent
|
||||||
|
|
Loading…
Reference in a new issue