diff --git a/src/strategy/Value.cpp b/src/strategy/Value.cpp index 76f395ab..4f64319e 100644 --- a/src/strategy/Value.cpp +++ b/src/strategy/Value.cpp @@ -113,3 +113,27 @@ std::string const ObjectGuidListCalculatedValue::Format() return out.str(); } + +Unit* UnitCalculatedValue::Get() +{ + if (checkInterval < 2) { + PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr); + value = Calculate(); + if (pmo) + pmo->finish(); + } else { + time_t now = getMSTime(); + if (!lastCheckTime || now - lastCheckTime >= checkInterval) + { + lastCheckTime = now; + PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr); + value = Calculate(); + if (pmo) + pmo->finish(); + } + } + // Prevent crashing by InWorld check + if (value && value->IsInWorld()) + return value; + return nullptr; +} \ No newline at end of file diff --git a/src/strategy/Value.h b/src/strategy/Value.h index bf29d074..25f61b59 100644 --- a/src/strategy/Value.h +++ b/src/strategy/Value.h @@ -9,6 +9,7 @@ #include "ObjectGuid.h" #include "PerformanceMonitor.h" #include "Timer.h" +#include "Unit.h" #include @@ -257,6 +258,7 @@ class UnitCalculatedValue : public CalculatedValue UnitCalculatedValue(PlayerbotAI* botAI, std::string const name = "value", int32 checkInterval = 1); std::string const Format() override; + Unit* Get() override; }; class CDPairCalculatedValue : public CalculatedValue diff --git a/src/strategy/triggers/CureTriggers.cpp b/src/strategy/triggers/CureTriggers.cpp index 3a477928..3eca5699 100644 --- a/src/strategy/triggers/CureTriggers.cpp +++ b/src/strategy/triggers/CureTriggers.cpp @@ -9,7 +9,7 @@ bool NeedCureTrigger::IsActive() { Unit* target = GetTarget(); - return target && botAI->HasAuraToDispel(target, dispelType); + return target && target->IsInWorld() && botAI->HasAuraToDispel(target, dispelType); } Value* PartyMemberNeedCureTrigger::GetTargetValue()