Code: Select all
function _CheckState( Entity )
-- Retrieve the range of the entity compared to my own character position.
local Range = Player:GetPosition():DistanceToPosition( Entity:GetPosition());
-- Check if this routine is allowed to be ran under the current circumstances.
if Entity:IsDead() or ( not Settings.Songweaver.AllowApproach and Range > 23 ) then
return true;
end
-- Retrieve the state for the current entity to inspect.
local EntityState = Entity:GetState();
-- Loop through the states only when we are available to dispel them. We still check for removed states!
if EntityState ~= nil and ( self.StateDispelTime == nil or self.StateDispelTime < Time()) then
-- Create the state array for the global entity storage and undispellable states if it does not exist.
if self.StateArray == nil or self.StateUndispellable == nil then
self.StateArray = {};
self.StateUndispellable = {};
end
-- Create the state array for the current entity if it does not exist.
if self.StateArray[Entity:GetID()] == nil then
self.StateArray[Entity:GetID()] = {};
end
-- Loop through the states to find which need to be removed.
for ID, Skill in DictionaryIterator( EntityState:GetList()) do
-- Check if the current skill is valid and has not been marked and undispellable.
if Skill ~= nil and Skill:IsDebuff() and ( self.StateUndispellable[Skill:GetID()] == nil or self.StateUndispellable[Skill:GetID()] < Time()) then
-- Check if this entity had the current skill effect on him and hasn't been removed by either Cure Mind or Dispel.
if self.StateArray[Entity:GetID()][Skill:GetID()] ~= nil and self.StateArray[Entity:GetID()][Skill:GetID()] == 2 then
self.StateUndispellable[Skill:GetID()] = Time() + 30000;
-- Remove the state from the entity.
else
-- Retrieve the magical state the current skill.
local RemoveMagical = Skill:IsMagical();
-- Check if we are required to change the magical state for the current skill.
if self.StateArray[Entity:GetID()][Skill:GetID()] ~= nil then
RemoveMagical = not RemoveMagical;
end
-- Check if the dispel or cure mind can be executed correctly. The function might need to set the target first!
if ( RemoveMagical and Helper:CheckExecute( "Purifying Paean", Entity )) or ( not RemoveMagical and Helper:CheckExecute( "Purifying Paean", Entity )) then
-- Change the state dispel timer to prevent dispel and cure mind from being used too quickly.
self.StateDispelTime = Time() + 500;
-- Track the current state of the dispel and cure mind to find undispellable states.
if self.StateArray[Entity:GetID()][Skill:GetID()] == nil then
self.StateArray[Entity:GetID()][Skill:GetID()] = 1;
return false;
else
self.StateArray[Entity:GetID()][Skill:GetID()] = 2;
return false;
end
end
end
end
end
-- Loop through the existing states to find which have been removed correctly.
for k,v in pairs( self.StateArray[Entity:GetID()] ) do
if v ~= nil and EntityState:GetState( k ) == nil then
self.StateArray[Entity:GetID()][k] = nil;
end
end
end
-- Return true to let the caller know this function completed.
return true;
end