diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 7bda537c..1fdd2089 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -1993,7 +1993,7 @@ bool PlayerbotAI::HasAura(std::string const name, Unit* unit, bool maxStack, boo { SpellInfo const* spellInfo = aurEff->GetSpellInfo(); - std::string const auraName = spellInfo->SpellName[0]; + std::string_view const auraName = spellInfo->SpellName[0]; if (auraName.empty() || auraName.length() != wnamepart.length() || !Utf8FitTo(auraName, wnamepart)) continue; diff --git a/src/strategy/NamedObjectContext.h b/src/strategy/NamedObjectContext.h index d621ca93..7f4509e7 100644 --- a/src/strategy/NamedObjectContext.h +++ b/src/strategy/NamedObjectContext.h @@ -265,7 +265,7 @@ class NamedObjectFactoryList factories.push_front(context); } - T* GetContextObject(std::string const name, PlayerbotAI* botAI) + T* GetContextObject(std::string const &name, PlayerbotAI* botAI) { for (typename std::list*>::iterator i = factories.begin(); i != factories.end(); i++) { diff --git a/src/strategy/values/HasTotemValue.cpp b/src/strategy/values/HasTotemValue.cpp index 3c31fc40..bba4b069 100644 --- a/src/strategy/values/HasTotemValue.cpp +++ b/src/strategy/values/HasTotemValue.cpp @@ -9,7 +9,7 @@ char* strstri(char const* str1, char const* str2); bool HasTotemValue::Calculate() { - GuidVector units = *context->GetValue("nearest npcs"); + GuidVector units = *context->GetValue("nearest totems"); for (ObjectGuid const guid : units) { Unit* unit = botAI->GetUnit(guid); @@ -17,14 +17,12 @@ bool HasTotemValue::Calculate() continue; Creature* creature = dynamic_cast(unit); - if (!creature || !creature->IsTotem()) - continue; if (creature->GetOwner() != bot) { continue; } - if (strstri(creature->GetName().c_str(), qualifier.c_str()) && bot->GetDistance(creature) <= botAI->GetRange("spell")) + if (strstri(creature->GetName().c_str(), qualifier.c_str())) return true; } diff --git a/src/strategy/values/NearestNpcsValue.cpp b/src/strategy/values/NearestNpcsValue.cpp index 0bae5942..efc73bb0 100644 --- a/src/strategy/values/NearestNpcsValue.cpp +++ b/src/strategy/values/NearestNpcsValue.cpp @@ -50,4 +50,16 @@ void NearestTriggersValue::FindUnits(std::list& targets) bool NearestTriggersValue::AcceptUnit(Unit* unit) { return !unit->IsPlayer(); +} + +void NearestTotemsValue::FindUnits(std::list& targets) +{ + Acore::AnyUnitInObjectRangeCheck u_check(bot, range); + Acore::UnitListSearcher searcher(bot, targets, u_check); + Cell::VisitAllObjects(bot, searcher, range); +} + +bool NearestTotemsValue::AcceptUnit(Unit* unit) +{ + return unit->IsTotem(); } \ No newline at end of file diff --git a/src/strategy/values/NearestNpcsValue.h b/src/strategy/values/NearestNpcsValue.h index 4ae4a3af..e23fc822 100644 --- a/src/strategy/values/NearestNpcsValue.h +++ b/src/strategy/values/NearestNpcsValue.h @@ -39,4 +39,15 @@ class NearestTriggersValue : public NearestUnitsValue void FindUnits(std::list& targets) override; bool AcceptUnit(Unit* unit) override; }; + +class NearestTotemsValue : public NearestUnitsValue +{ + public: + NearestTotemsValue(PlayerbotAI* botAI, float range = 30.0f) : NearestUnitsValue(botAI, "nearest npcs", range, true) { } + + protected: + void FindUnits(std::list& targets) override; + bool AcceptUnit(Unit* unit) override; +}; + #endif diff --git a/src/strategy/values/ValueContext.h b/src/strategy/values/ValueContext.h index 46d126ea..38f37840 100644 --- a/src/strategy/values/ValueContext.h +++ b/src/strategy/values/ValueContext.h @@ -103,6 +103,7 @@ class ValueContext : public NamedObjectContext creators["nearest game objects no los"] = &ValueContext::nearest_game_objects_no_los; creators["closest game objects"] = &ValueContext::closest_game_objects; creators["nearest npcs"] = &ValueContext::nearest_npcs; + creators["nearest totems"] = &ValueContext::nearest_totems; creators["nearest vehicles"] = &ValueContext::nearest_vehicles; creators["nearest friendly players"] = &ValueContext::nearest_friendly_players; creators["closest friendly players"] = &ValueContext::closest_friendly_players; @@ -367,6 +368,7 @@ class ValueContext : public NamedObjectContext static UntypedValue* closest_game_objects(PlayerbotAI* botAI) { return new NearestGameObjects(botAI, INTERACTION_DISTANCE); } static UntypedValue* log_level(PlayerbotAI* botAI) { return new LogLevelValue(botAI); } static UntypedValue* nearest_npcs(PlayerbotAI* botAI) { return new NearestNpcsValue(botAI); } + static UntypedValue* nearest_totems(PlayerbotAI* botAI) { return new NearestTotemsValue(botAI); } static UntypedValue* nearest_vehicles(PlayerbotAI* botAI) { return new NearestVehiclesValue(botAI); } static UntypedValue* nearest_friendly_players(PlayerbotAI* botAI) { return new NearestFriendlyPlayersValue(botAI); } static UntypedValue* closest_friendly_players(PlayerbotAI* botAI) { return new NearestFriendlyPlayersValue(botAI, INTERACTION_DISTANCE); }