From f6df73e4bc024ffa446e8533f40d55392e61f953 Mon Sep 17 00:00:00 2001 From: WinterSolstice8 <60417494+wintersolstice8@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:31:16 -0700 Subject: [PATCH] [core] Add CBattleEntity hasEnmity function --- src/map/entities/battleentity.cpp | 29 +++++++++++++++++++++++++++++ src/map/entities/battleentity.h | 2 ++ src/map/lua/lua_baseentity.cpp | 4 ++-- src/map/packet_system.cpp | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/map/entities/battleentity.cpp b/src/map/entities/battleentity.cpp index a729faa193b..62cf583cca6 100644 --- a/src/map/entities/battleentity.cpp +++ b/src/map/entities/battleentity.cpp @@ -2691,3 +2691,32 @@ uint16 CBattleEntity::GetBattleTargetID() const { return m_battleTarget; } + +bool CBattleEntity::hasEnmityEXPENSIVE() const +{ + // TODO: This check seems to always fail for pets? + if (PNotorietyContainer->hasEnmity()) + { + return true; + } + + bool isTargeted = false; + + // TODO: this is bad but because of how super tanking is implemented there's not much we can do without a larger refactor + if (loc.zone) + { + // clang-format off + loc.zone->ForEachMob([&](CMobEntity* PMob) + { + // Account for charmed mobs attacking normal mobs, etc + if (PMob->GetBattleTargetID() == targid && PMob->allegiance != allegiance) + { + isTargeted = true; + return; + } + }); + // clang-format on + } + + return isTargeted; +} diff --git a/src/map/entities/battleentity.h b/src/map/entities/battleentity.h index 73d9c388e12..3a6be58bb81 100644 --- a/src/map/entities/battleentity.h +++ b/src/map/entities/battleentity.h @@ -703,6 +703,8 @@ class CBattleEntity : public CBaseEntity } CBattleEntity* GetBattleTarget(); + bool hasEnmityEXPENSIVE() const; // Returns true if own notoriety container is not empty or mob in zone has entity listed as battle target + /* State callbacks */ /* Auto attack */ virtual bool OnAttack(CAttackState&, action_t&); diff --git a/src/map/lua/lua_baseentity.cpp b/src/map/lua/lua_baseentity.cpp index 717f798896f..35140597870 100644 --- a/src/map/lua/lua_baseentity.cpp +++ b/src/map/lua/lua_baseentity.cpp @@ -12869,7 +12869,7 @@ void CLuaBaseEntity::updateClaim(sol::object const& entity) /************************************************************************ * Function: hasEnmity() - * Purpose : Check if a an entity is on any mob's enmity list + * Purpose : Check if a an entity is on any mob's enmity list or is supertanked by * Example : if player:hasEnmity() then * Notes : ************************************************************************/ @@ -12882,7 +12882,7 @@ bool CLuaBaseEntity::hasEnmity() return false; } - return static_cast(m_PBaseEntity)->PNotorietyContainer->hasEnmity(); + return static_cast(m_PBaseEntity)->hasEnmityEXPENSIVE(); } /************************************************************************ diff --git a/src/map/packet_system.cpp b/src/map/packet_system.cpp index 9385896beac..5d47e3dc9b0 100644 --- a/src/map/packet_system.cpp +++ b/src/map/packet_system.cpp @@ -1155,7 +1155,7 @@ void SmallPacket0x01A(map_session_data_t* const PSession, CCharEntity* const PCh return; } - if (PChar->PNotorietyContainer->hasEnmity()) + if (PChar->hasEnmityEXPENSIVE()) { PChar->pushPacket(PChar, PChar, 0, 0, MSGBASIC_YOUR_MOUNT_REFUSES); return;