Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CPP] Update useMobAbility to check distance #5815

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading