Skip to content

Commit

Permalink
workaround - AnyUnfriendlyUnitInObjectRangeCheck rarely returns frien…
Browse files Browse the repository at this point in the history
…dly players and even self as a hostile to the bot, remove players from calculations for now (#35)
  • Loading branch information
Redbu11dev authored Aug 2, 2024
1 parent 89e51b4 commit 11cafe6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6837,9 +6837,25 @@ std::list<Unit*> PlayerbotAI::GetAllHostileUnitsAroundWO(WorldObject* wo, float
MaNGOS::UnitListSearcher<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck> searcher(hostileUnits, u_check);
Cell::VisitAllObjects(wo, searcher, distanceAround);

//bugs out with players very rarely - returns friendly as hostile to bots

return hostileUnits;
}

std::list<Unit*> PlayerbotAI::GetAllHostileNonPlayerUnitsAroundWO(WorldObject* wo, float distanceAround)
{
std::list<Unit*> hostileUnitsNonPlayers;
for (auto hostileUnit : GetAllHostileUnitsAroundWO(wo, distanceAround))
{
if (!hostileUnit->IsPlayer())
{
hostileUnitsNonPlayers.push_back(hostileUnit);
}
}

return hostileUnitsNonPlayers;
}

std::string PlayerbotAI::InventoryParseOutfitName(std::string outfit)
{
int pos = outfit.find("=");
Expand Down
1 change: 1 addition & 0 deletions playerbot/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ class PlayerbotAI : public PlayerbotAIBase
void AccelerateRespawn(ObjectGuid guid, float accelMod = 0) { Creature* creature = GetCreature(guid); if (creature) AccelerateRespawn(creature,accelMod); }

std::list<Unit*> GetAllHostileUnitsAroundWO(WorldObject* wo, float distanceAround);
std::list<Unit*> GetAllHostileNonPlayerUnitsAroundWO(WorldObject* wo, float distanceAround);

public:
std::vector<Item*> GetInventoryAndEquippedItems();
Expand Down
4 changes: 2 additions & 2 deletions playerbot/strategy/actions/AddLootAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool AddAllLootAction::AddLoot(Player* requester, ObjectGuid guid)
if (isInGroup && !isGroupLeader)
{
float MOB_AGGRO_DISTANCE = 30.0f;
std::list<Unit*> hostiles = ai->GetAllHostileUnitsAroundWO(wo, MOB_AGGRO_DISTANCE);
std::list<Unit*> hostiles = ai->GetAllHostileNonPlayerUnitsAroundWO(wo, MOB_AGGRO_DISTANCE);

if (hostiles.size() > 0)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ bool AddGatheringLootAction::AddLoot(Player* requester, ObjectGuid guid)
//check hostile units after distance checks, to avoid unnecessary calculations

float MOB_AGGRO_DISTANCE = 30.0f;
std::list<Unit*> hostiles = ai->GetAllHostileUnitsAroundWO(wo, MOB_AGGRO_DISTANCE);
std::list<Unit*> hostiles = ai->GetAllHostileNonPlayerUnitsAroundWO(wo, MOB_AGGRO_DISTANCE);
std::list<Unit*> strongHostiles;
for (auto hostile : hostiles)
{
Expand Down

0 comments on commit 11cafe6

Please sign in to comment.