Skip to content

Commit

Permalink
Merge pull request #5815 from 0x05010705/update-useMobAbility-to-use-…
Browse files Browse the repository at this point in the history
…range-check

[CPP] Update useMobAbility to check distance
  • Loading branch information
claywar authored Jun 1, 2024
2 parents 308c21f + 87c87ea commit d3978dc
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 @@ -16706,15 +16706,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 d3978dc

Please sign in to comment.