Skip to content

Commit

Permalink
update useMobAbility to check distance
Browse files Browse the repository at this point in the history
  • Loading branch information
0x05010705 committed May 22, 2024
1 parent 51b2de0 commit 87c87ea
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/map/lua/lua_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16587,15 +16587,32 @@ void CLuaBaseEntity::useMobAbility(sol::variadic_args va)
// clang-format off
m_PBaseEntity->PAI->QueueAction(queueAction_t(0ms, true, [PTarget, skillid, PMobSkill](auto PEntity)
{
if (PTarget)
auto mobObj = dynamic_cast<CMobEntity*>(PEntity);

// has both a valid target (specified by user and mob)
if (PTarget && mobObj)
{
PEntity->PAI->MobSkill(PTarget->targid, skillid);
float currentDistance = distance(mobObj->loc.p, PTarget->loc.p);
if (currentDistance <= PMobSkill->getDistance())
{
PEntity->PAI->MobSkill(PTarget->targid, skillid);
}
}
else if (dynamic_cast<CMobEntity*>(PEntity))
// does not have a specified target so default to current battle target
else if (mobObj)
{
if (PMobSkill->getValidTargets() & TARGET_ENEMY)
{
PEntity->PAI->MobSkill(static_cast<CMobEntity*>(PEntity)->GetBattleTargetID(), skillid);
auto defaultTarget = mobObj->GetBattleTarget();
if (defaultTarget)
{
// check distance from player or mob will use TP move and 'lock' itself
float currentDistance = distance(mobObj->loc.p, defaultTarget->loc.p);
if (currentDistance <= PMobSkill->getDistance())
{
PEntity->PAI->MobSkill(defaultTarget->targid, skillid);
}
}
}
else if (PMobSkill->getValidTargets() & TARGET_SELF)
{
Expand Down

0 comments on commit 87c87ea

Please sign in to comment.