From 8d7766662415af8b77823073fa684eb54c8e214d Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 5 Aug 2024 15:45:37 +0800 Subject: [PATCH 1/3] Improve party member to heal and has aura to dispel check performance --- src/PlayerbotAI.cpp | 35 ++++++++++++----------- src/strategy/triggers/CureTriggers.cpp | 6 ++++ src/strategy/triggers/CureTriggers.h | 1 + src/strategy/values/PartyMemberToHeal.cpp | 32 ++++++++++++++++----- src/strategy/values/PartyMemberValue.cpp | 4 +-- 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 1b8b7314..20f10ac5 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -3285,28 +3285,29 @@ bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType) return false; } bool isFriend = bot->IsFriendlyTo(target); - for (uint32 type = SPELL_AURA_NONE; type < TOTAL_AURAS; ++type) + Unit::VisibleAuraMap const* visibleAuras = target->GetVisibleAuras(); + for (Unit::VisibleAuraMap::const_iterator itr = visibleAuras->begin(); itr != visibleAuras->end(); ++itr) { - Unit::AuraEffectList const& auras = target->GetAuraEffectsByType((AuraType)type); - for (AuraEffect const* aurEff : auras) - { - Aura const* aura = aurEff->GetBase(); - SpellInfo const* spellInfo = aura->GetSpellInfo(); + Aura* aura = itr->second->GetBase(); - bool isPositiveSpell = spellInfo->IsPositive(); - if (isPositiveSpell && isFriend) - continue; + if (aura->IsPassive()) + continue; - if (!isPositiveSpell && !isFriend) - continue; + if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() && + aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration) + continue; - if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() && - aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration) - continue; + SpellInfo const* spellInfo = aura->GetSpellInfo(); - if (canDispel(spellInfo, dispelType)) - return true; - } + bool isPositiveSpell = spellInfo->IsPositive(); + if (isPositiveSpell && isFriend) + continue; + + if (!isPositiveSpell && !isFriend) + continue; + + if (canDispel(spellInfo, dispelType)) + return true; } return false; } diff --git a/src/strategy/triggers/CureTriggers.cpp b/src/strategy/triggers/CureTriggers.cpp index 9c7369d4..abd23022 100644 --- a/src/strategy/triggers/CureTriggers.cpp +++ b/src/strategy/triggers/CureTriggers.cpp @@ -19,4 +19,10 @@ Value* PartyMemberNeedCureTrigger::GetTargetValue() return context->GetValue("party member to dispel", dispelType); } +bool PartyMemberNeedCureTrigger::IsActive() +{ + Unit* target = GetTarget(); + return target && target->IsInWorld(); +} + bool NeedWorldBuffTrigger::IsActive() { return !WorldBuffAction::NeedWorldBuffs(bot).empty(); } diff --git a/src/strategy/triggers/CureTriggers.h b/src/strategy/triggers/CureTriggers.h index a18f8a10..63e5d339 100644 --- a/src/strategy/triggers/CureTriggers.h +++ b/src/strategy/triggers/CureTriggers.h @@ -46,6 +46,7 @@ public: } Value* GetTargetValue() override; + bool IsActive() override; }; class NeedWorldBuffTrigger : public Trigger diff --git a/src/strategy/values/PartyMemberToHeal.cpp b/src/strategy/values/PartyMemberToHeal.cpp index 5c158428..e16d63d0 100644 --- a/src/strategy/values/PartyMemberToHeal.cpp +++ b/src/strategy/values/PartyMemberToHeal.cpp @@ -41,36 +41,54 @@ Unit* PartyMemberToHeal::Calculate() for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next()) { Player* player = gref->GetSource(); - if (player && Check(player) && player->IsAlive()) + if (player && player->IsAlive()) { uint8 health = player->GetHealthPct(); if (isRaid || health < sPlayerbotAIConfig->mediumHealth || !IsTargetOfSpellCast(player, predicate)) { + uint32 probeValue = 100; if (player->GetDistance2d(bot) > sPlayerbotAIConfig->healDistance) { - calc.probe(health + 30, player); + probeValue = health + 30; } else { - calc.probe(health + player->GetDistance2d(bot) / 10, player); + probeValue = health + player->GetDistance2d(bot) / 10; + } + // delay Check player to here for better performance + if (probeValue < calc.minValue && Check(player)) + { + calc.probe(probeValue, player); } } } Pet* pet = player->GetPet(); - if (pet && Check(pet) && pet->IsAlive()) + if (pet && pet->IsAlive()) { uint8 health = ((Unit*)pet)->GetHealthPct(); + uint32 probeValue = 100; if (isRaid || health < sPlayerbotAIConfig->mediumHealth) - calc.probe(health + 30, pet); + probeValue = health + 30; + // delay Check pet to here for better performance + if (probeValue < calc.minValue && Check(pet)) + { + calc.probe(probeValue, pet); + } } Unit* charm = player->GetCharm(); - if (charm && Check(charm) && charm->IsAlive()) + if (charm && charm->IsAlive()) { uint8 health = charm->GetHealthPct(); + uint32 probeValue = 100; if (isRaid || health < sPlayerbotAIConfig->mediumHealth) - calc.probe(health, charm); + probeValue = health + 30; + // delay Check charm to here for better performance + if (probeValue < calc.minValue && Check(charm)) + { + calc.probe(probeValue, charm); + } } } return (Unit*)calc.param; diff --git a/src/strategy/values/PartyMemberValue.cpp b/src/strategy/values/PartyMemberValue.cpp index 36f79e2e..023eeefd 100644 --- a/src/strategy/values/PartyMemberValue.cpp +++ b/src/strategy/values/PartyMemberValue.cpp @@ -12,11 +12,11 @@ Unit* PartyMemberValue::FindPartyMember(std::vector* party, FindPlayerP { for (Player* player : *party) { - if (Check(player) && predicate.Check(player)) + if (predicate.Check(player) && Check(player)) return player; if (Pet* pet = player->GetPet()) - if (Check(pet) && predicate.Check(pet)) + if (predicate.Check(pet) && Check(pet)) return pet; } From 085b2e7f193f07be95df11599f27b215baf73f8f Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 5 Aug 2024 17:04:21 +0800 Subject: [PATCH 2/3] Improve containsstrategy performance --- src/PlayerbotAI.cpp | 2 +- src/strategy/Engine.cpp | 2 ++ src/strategy/Engine.h | 3 ++- src/strategy/hunter/GenericHunterStrategy.cpp | 4 +++- src/strategy/hunter/HunterAiObjectContext.cpp | 4 +++- src/strategy/hunter/HunterTriggers.cpp | 6 ------ src/strategy/hunter/HunterTriggers.h | 7 ++++++- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 20f10ac5..0b4db3ef 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -1379,7 +1379,7 @@ bool PlayerbotAI::ContainsStrategy(StrategyType type) { for (uint8 i = 0; i < BOT_STATE_MAX; i++) { - if (engines[i]->ContainsStrategy(type)) + if (engines[i]->HasStrategyType(type)) return true; } diff --git a/src/strategy/Engine.cpp b/src/strategy/Engine.cpp index d6960a68..a4e3845d 100644 --- a/src/strategy/Engine.cpp +++ b/src/strategy/Engine.cpp @@ -86,6 +86,7 @@ Engine::~Engine(void) void Engine::Reset() { + strategyTypeMask = 0; ActionNode* action = nullptr; do { @@ -120,6 +121,7 @@ void Engine::Init() for (std::map::iterator i = strategies.begin(); i != strategies.end(); i++) { Strategy* strategy = i->second; + strategyTypeMask |= strategy->GetType(); strategy->InitMultipliers(multipliers); strategy->InitTriggers(triggers); diff --git a/src/strategy/Engine.h b/src/strategy/Engine.h index f25f97b3..bd51c16b 100644 --- a/src/strategy/Engine.h +++ b/src/strategy/Engine.h @@ -83,7 +83,7 @@ public: void AddActionExecutionListener(ActionExecutionListener* listener) { actionExecutionListeners.Add(listener); } void removeActionExecutionListener(ActionExecutionListener* listener) { actionExecutionListeners.Remove(listener); } - + bool HasStrategyType(StrategyType type) { return strategyTypeMask & type; } virtual ~Engine(void); bool testMode; @@ -112,6 +112,7 @@ protected: std::map strategies; float lastRelevance; std::string lastAction; + uint32 strategyTypeMask; }; #endif diff --git a/src/strategy/hunter/GenericHunterStrategy.cpp b/src/strategy/hunter/GenericHunterStrategy.cpp index d245400a..ff124fb8 100644 --- a/src/strategy/hunter/GenericHunterStrategy.cpp +++ b/src/strategy/hunter/GenericHunterStrategy.cpp @@ -98,7 +98,9 @@ void GenericHunterStrategy::InitTriggers(std::vector& triggers) new TriggerNode("misdirection on main tank", NextAction::array(0, new NextAction("misdirection on main tank", ACTION_HIGH + 7), NULL))); triggers.push_back( - new TriggerNode("tranquilizing shot", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL))); + new TriggerNode("tranquilizing shot enrage", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL))); + triggers.push_back( + new TriggerNode("tranquilizing shot magic", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL))); } NextAction** HunterBoostStrategy::getDefaultActions() diff --git a/src/strategy/hunter/HunterAiObjectContext.cpp b/src/strategy/hunter/HunterAiObjectContext.cpp index 1a4e855f..588888a9 100644 --- a/src/strategy/hunter/HunterAiObjectContext.cpp +++ b/src/strategy/hunter/HunterAiObjectContext.cpp @@ -85,7 +85,8 @@ public: creators["switch to melee"] = &HunterTriggerFactoryInternal::switch_to_melee; creators["switch to ranged"] = &HunterTriggerFactoryInternal::switch_to_ranged; creators["misdirection on main tank"] = &HunterTriggerFactoryInternal::misdirection_on_main_tank; - creators["tranquilizing shot"] = &HunterTriggerFactoryInternal::remove_enrage; + creators["tranquilizing shot enrage"] = &HunterTriggerFactoryInternal::remove_enrage; + creators["tranquilizing shot magic"] = &HunterTriggerFactoryInternal::remove_magic; } private: @@ -118,6 +119,7 @@ private: static Trigger* switch_to_ranged(PlayerbotAI* botAI) { return new SwitchToRangedTrigger(botAI); } static Trigger* misdirection_on_main_tank(PlayerbotAI* ai) { return new MisdirectionOnMainTankTrigger(ai); } static Trigger* remove_enrage(PlayerbotAI* ai) { return new TargetRemoveEnrageTrigger(ai); } + static Trigger* remove_magic(PlayerbotAI* ai) { return new TargetRemoveMagicTrigger(ai); } }; class HunterAiObjectContextInternal : public NamedObjectContext diff --git a/src/strategy/hunter/HunterTriggers.cpp b/src/strategy/hunter/HunterTriggers.cpp index d581955d..941ce755 100644 --- a/src/strategy/hunter/HunterTriggers.cpp +++ b/src/strategy/hunter/HunterTriggers.cpp @@ -88,9 +88,3 @@ bool SwitchToMeleeTrigger::IsActive() (target->GetVictim() == bot && sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "current target"), 8.0f)); } - -bool TargetRemoveEnrageTrigger::IsActive() -{ - Unit* target = GetTarget(); - return target && (botAI->HasAuraToDispel(target, DISPEL_ENRAGE) || botAI->HasAuraToDispel(target, DISPEL_MAGIC)); -} \ No newline at end of file diff --git a/src/strategy/hunter/HunterTriggers.h b/src/strategy/hunter/HunterTriggers.h index 4b5a7078..2ff44fe3 100644 --- a/src/strategy/hunter/HunterTriggers.h +++ b/src/strategy/hunter/HunterTriggers.h @@ -170,6 +170,11 @@ class TargetRemoveEnrageTrigger : public TargetAuraDispelTrigger { public: TargetRemoveEnrageTrigger(PlayerbotAI* ai) : TargetAuraDispelTrigger(ai, "tranquilizing shot", DISPEL_ENRAGE) {} - bool IsActive() override; +}; + +class TargetRemoveMagicTrigger : public TargetAuraDispelTrigger +{ +public: + TargetRemoveMagicTrigger(PlayerbotAI* ai) : TargetAuraDispelTrigger(ai, "tranquilizing shot", DISPEL_MAGIC) {} }; #endif From 0e2234846e7ae7395a0ad4b3dc95ba9eb888a734 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 5 Aug 2024 22:14:19 +0800 Subject: [PATCH 3/3] Disable macos CI --- .github/workflows/macos_build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/macos_build.yml b/.github/workflows/macos_build.yml index 5ea55963..a0827729 100644 --- a/.github/workflows/macos_build.yml +++ b/.github/workflows/macos_build.yml @@ -1,9 +1,9 @@ name: macos-build on: push: - branches: [ "master" ] + branches: [never-match-this-branch] pull_request: - branches: [ "master" ] + branches: [never-match-this-branch] # concurrency: # group: ${{ github.head_ref }} || concat(${{ github.ref }}, ${{ github.workflow }})