diff --git a/src/PlayerbotAIBase.cpp b/src/PlayerbotAIBase.cpp index 203cfec7..034015fb 100644 --- a/src/PlayerbotAIBase.cpp +++ b/src/PlayerbotAIBase.cpp @@ -48,7 +48,7 @@ void PlayerbotAIBase::IncreaseNextCheckDelay(uint32 delay) bool PlayerbotAIBase::CanUpdateAI() { - return nextAICheckDelay < 100; + return nextAICheckDelay == 0; } void PlayerbotAIBase::YieldThread(bool delay) diff --git a/src/strategy/Engine.cpp b/src/strategy/Engine.cpp index 695c62d2..5ab29cac 100644 --- a/src/strategy/Engine.cpp +++ b/src/strategy/Engine.cpp @@ -633,7 +633,7 @@ void Engine::LogAction(char const* format, ...) if (testMode) { FILE* file = fopen("test.log", "a"); - fprintf(file, "'{}'", buf); + fprintf(file, "'%s'", buf); fprintf(file, "\n"); fclose(file); } diff --git a/src/strategy/raids/naxxramas/RaidNaxxBossHelper.h b/src/strategy/raids/naxxramas/RaidNaxxBossHelper.h index 64faa078..86b6a82e 100644 --- a/src/strategy/raids/naxxramas/RaidNaxxBossHelper.h +++ b/src/strategy/raids/naxxramas/RaidNaxxBossHelper.h @@ -22,31 +22,37 @@ class GenericBossHelper : public AiObject { public: GenericBossHelper(PlayerbotAI* botAI, std::string name): AiObject(botAI), name_(name) {} virtual bool UpdateBossAI() { - Unit* unit = AI_VALUE2(Unit*, "find target", name_); - if (!unit) { - return false; + if(unit_ && !unit_->IsInWorld()) { + unit_ = nullptr; } - target_ = unit->ToCreature(); - if (!target_) { - return false; - } - ai_ = dynamic_cast(target_->GetAI()); - if (!ai_) { - return false; - } - event_map_ = &ai_->events; - if (!event_map_) { - return false; + if (!unit_) { + unit_ = AI_VALUE2(Unit*, "find target", name_); + if (!unit_) { + return false; + } + target_ = unit_->ToCreature(); + if (!target_) { + return false; + } + ai_ = dynamic_cast(target_->GetAI()); + if (!ai_) { + return false; + } + event_map_ = &ai_->events; + if (!event_map_) { + return false; + } } timer_ = event_map_->GetTimer(); return true; } protected: - Creature* target_; - std::string name_; - BossAiType *ai_; - EventMap* event_map_; - uint32 timer_; + Unit* unit_ = nullptr; + Creature* target_ = nullptr; + std::string name_ = nullptr; + BossAiType *ai_ = nullptr; + EventMap* event_map_ = nullptr; + uint32 timer_ = 0; }; class KelthuzadBossHelper: public GenericBossHelper { diff --git a/src/strategy/values/AttackersValue.h b/src/strategy/values/AttackersValue.h index 4ccf1e63..ea1e745b 100644 --- a/src/strategy/values/AttackersValue.h +++ b/src/strategy/values/AttackersValue.h @@ -16,7 +16,7 @@ class Unit; class AttackersValue : public ObjectGuidListCalculatedValue { public: - AttackersValue(PlayerbotAI* botAI) : ObjectGuidListCalculatedValue(botAI, "attackers", 1) { } + AttackersValue(PlayerbotAI* botAI) : ObjectGuidListCalculatedValue(botAI, "attackers", 2) { } GuidVector Calculate(); static bool IsPossibleTarget(Unit* attacker, Player* bot, float range = sPlayerbotAIConfig->sightDistance); diff --git a/src/strategy/values/DpsTargetValue.cpp b/src/strategy/values/DpsTargetValue.cpp index 6f3a085b..36f466f2 100644 --- a/src/strategy/values/DpsTargetValue.cpp +++ b/src/strategy/values/DpsTargetValue.cpp @@ -18,7 +18,9 @@ class FindLeastHpTargetStrategy : public FindTargetStrategy if (guid && attacker->GetGUID() == guid) return; } - + if (!attacker->IsAlive()) { + return; + } if (!result || result->GetHealth() > attacker->GetHealth()) result = attacker; } diff --git a/src/strategy/values/PartyMemberToHeal.cpp b/src/strategy/values/PartyMemberToHeal.cpp index 372bb671..8caa2077 100644 --- a/src/strategy/values/PartyMemberToHeal.cpp +++ b/src/strategy/values/PartyMemberToHeal.cpp @@ -81,6 +81,7 @@ bool PartyMemberToHeal::Check(Unit* player) Unit* PartyMemberToProtect::Calculate() { + return nullptr; Group* group = bot->GetGroup(); if (!group) return nullptr; diff --git a/src/strategy/values/PartyMemberValue.h b/src/strategy/values/PartyMemberValue.h index 3dafe35c..e3508b3d 100644 --- a/src/strategy/values/PartyMemberValue.h +++ b/src/strategy/values/PartyMemberValue.h @@ -38,7 +38,7 @@ class PartyMemberValue : public UnitCalculatedValue class PartyMemberMainTankValue : public PartyMemberValue { public: - PartyMemberMainTankValue(PlayerbotAI* botAI) : PartyMemberValue(botAI) {} + PartyMemberMainTankValue(PlayerbotAI* botAI) : PartyMemberValue(botAI, "main tank member", 2) {} virtual Unit* Calculate(); }; diff --git a/src/strategy/values/TargetValue.cpp b/src/strategy/values/TargetValue.cpp index 762e99ec..44ee831a 100644 --- a/src/strategy/values/TargetValue.cpp +++ b/src/strategy/values/TargetValue.cpp @@ -4,6 +4,7 @@ #include "TargetValue.h" #include "LastMovementValue.h" +#include "ObjectGuid.h" #include "RtiTargetValue.h" #include "Playerbots.h" #include "ScriptedCreature.h" @@ -117,31 +118,24 @@ WorldPosition HomeBindValue::Calculate() Unit* FindTargetValue::Calculate() { if (qualifier == "") { - return NULL; + return nullptr; } Group* group = bot->GetGroup(); if (!group) { - return NULL; + return nullptr; } - for (GroupReference *gref = group->GetFirstMember(); gref; gref = gref->next()) { - Player* member = gref->GetSource(); - if (!member) { - continue; - } - HostileReference *ref = member->getHostileRefMgr().getFirst(); - while (ref) - { - ThreatMgr *threatManager = ref->GetSource(); - Unit *unit = threatManager->GetOwner(); - std::wstring wnamepart; - Utf8toWStr(unit->GetName(), wnamepart); - wstrToLower(wnamepart); - if (!qualifier.empty() && qualifier.length() == wnamepart.length() && Utf8FitTo(qualifier, wnamepart)) { - return unit; - } - assert(ref); - ref = ref->next(); + HostileReference *ref = bot->getHostileRefMgr().getFirst(); + while (ref) + { + ThreatMgr *threatManager = ref->GetSource(); + Unit *unit = threatManager->GetOwner(); + std::wstring wnamepart; + Utf8toWStr(unit->GetName(), wnamepart); + wstrToLower(wnamepart); + if (!qualifier.empty() && qualifier.length() == wnamepart.length() && Utf8FitTo(qualifier, wnamepart)) { + return unit; } + ref = ref->next(); } return nullptr; } diff --git a/src/strategy/values/TargetValue.h b/src/strategy/values/TargetValue.h index 2bdc2cd2..0182354e 100644 --- a/src/strategy/values/TargetValue.h +++ b/src/strategy/values/TargetValue.h @@ -41,7 +41,7 @@ class FindNonCcTargetStrategy : public FindTargetStrategy class TargetValue : public UnitCalculatedValue { public: - TargetValue(PlayerbotAI* botAI, std::string const name = "target") : UnitCalculatedValue(botAI, name) { } + TargetValue(PlayerbotAI* botAI, std::string const name = "target", int checkInterval = 1) : UnitCalculatedValue(botAI, name, checkInterval) { } protected: Unit* FindTarget(FindTargetStrategy* strategy); @@ -101,7 +101,7 @@ class PullTargetValue : public ManualSetValue class FindTargetValue : public UnitCalculatedValue, public Qualified { public: - FindTargetValue(PlayerbotAI* ai) : UnitCalculatedValue(ai) {} + FindTargetValue(PlayerbotAI* ai) : UnitCalculatedValue(ai, "find target", 2) {} public: Unit* Calculate(); @@ -117,7 +117,7 @@ class FindBossTargetStrategy : public FindTargetStrategy class BossTargetValue : public TargetValue, public Qualified { public: - BossTargetValue(PlayerbotAI* ai) : TargetValue(ai) {} + BossTargetValue(PlayerbotAI* ai) : TargetValue(ai, "boss target", 1) {} public: Unit* Calculate();