2015-03-14 16:18:39 -04:00
|
|
|
function NPC:ForeachHateList(func, cond)
|
|
|
|
|
cond = cond or function(ent, hate, damage, frenzy) return true end;
|
|
|
|
|
local lst = self:GetHateList();
|
|
|
|
|
for ent in lst.entries do
|
|
|
|
|
local cv = cond(ent.ent, ent.hate, ent.damage, ent.frenzy);
|
|
|
|
|
if(cv) then
|
|
|
|
|
func(ent.ent, ent.hate, ent.damage, ent.frenzy);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NPC:CountHateList(cond)
|
|
|
|
|
cond = cond or function(ent, hate, damage, frenzy) return true end;
|
|
|
|
|
local lst = self:GetHateList();
|
|
|
|
|
local ret = 0;
|
|
|
|
|
for ent in lst.entries do
|
|
|
|
|
local cv = cond(ent.ent, ent.hate, ent.damage, ent.frenzy);
|
|
|
|
|
if(cv) then
|
|
|
|
|
ret = ret + 1;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function NPC:RandomRoam(maxx,maxy,maxz,los)
|
|
|
|
|
maxz = maxz or 15;
|
|
|
|
|
los = los or 5;
|
|
|
|
|
|
2023-08-06 22:39:24 -04:00
|
|
|
if not self:IsEngaged() then
|
2015-03-14 16:18:39 -04:00
|
|
|
local curx = self:GetX();
|
|
|
|
|
local cury = self:GetY();
|
2023-08-06 22:39:24 -04:00
|
|
|
local origx = self:GetSpawnPointX() or 0;
|
|
|
|
|
local origy = self:GetSpawnPointY() or 0;
|
|
|
|
|
local origz = self:GetSpawnPointZ() or 0;
|
|
|
|
|
local guardx = self:GetGuardPointX() or 0;
|
|
|
|
|
local guardy = self:GetGuardPointY() or 0;
|
2015-03-14 16:18:39 -04:00
|
|
|
|
2023-08-06 22:39:24 -04:00
|
|
|
if curx == guardx and cury == guardy then
|
2023-08-11 20:51:04 -04:00
|
|
|
local randomx = math.random(maxx) + 1;
|
|
|
|
|
local randomy = math.random(maxy) + 1;
|
2015-03-14 16:18:39 -04:00
|
|
|
local posx = origx + randomx;
|
|
|
|
|
local posy = origy + randomy;
|
|
|
|
|
local negx = origx - randomx;
|
|
|
|
|
local negy = origy - randomy;
|
2023-08-11 20:52:03 -04:00
|
|
|
local newx, newy = 0;
|
2023-08-11 20:51:04 -04:00
|
|
|
if posx > negx then -- Flip order
|
|
|
|
|
newx = math.random(negx, posx);
|
|
|
|
|
else
|
|
|
|
|
newx = math.random(posx,negx);
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if posy > negy then -- Flip order
|
|
|
|
|
newy = math.random(negy, posy);
|
|
|
|
|
else
|
|
|
|
|
newy = math.random(posy,negy);
|
|
|
|
|
end
|
2015-03-14 16:18:39 -04:00
|
|
|
local newz = self:FindGroundZ(newx,newy, 5) + 1;
|
|
|
|
|
|
2023-08-06 22:39:24 -04:00
|
|
|
if newz > -999999 and origz > (newz - maxz + 1) and origz < (newz + maxz - 1) then
|
2015-03-14 16:18:39 -04:00
|
|
|
local loscheck = self:CheckLoSToLoc(newx, newy, newz, los);
|
2023-08-06 22:39:24 -04:00
|
|
|
if loscheck then
|
2015-03-14 16:18:39 -04:00
|
|
|
self:MoveTo(newx,newy,newz,-1,true);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-04-10 17:36:01 -04:00
|
|
|
|
|
|
|
|
function NPC:CastedSpellFinished(spell_id, target) -- note, we do have a server side function (not exported) called this too ...
|
|
|
|
|
self:SendBeginCast(spell_id, 0);
|
|
|
|
|
self:SpellFinished(spell_id, target);
|
|
|
|
|
end
|
|
|
|
|
|
2020-09-13 18:33:49 -04:00
|
|
|
function NPC:GetClientsInProximity(distance)
|
|
|
|
|
local clients = {}
|
|
|
|
|
local client_list = eq.get_entity_list():GetClientList()
|
|
|
|
|
for client in client_list.entries do
|
|
|
|
|
if client.valid and self:CalculateDistance(client:GetX(), client:GetY(), client:GetZ()) <= distance then
|
|
|
|
|
clients[#clients+1] = client
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return clients
|
|
|
|
|
end
|