Improve party member to heal and has aura to dispel check performance

This commit is contained in:
Yunfan Li
2024-08-05 15:45:37 +08:00
parent 72b32a1590
commit 8d77666624
5 changed files with 52 additions and 26 deletions

View File

@@ -3285,28 +3285,29 @@ bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
return false; return false;
} }
bool isFriend = bot->IsFriendlyTo(target); 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); Aura* aura = itr->second->GetBase();
for (AuraEffect const* aurEff : auras)
{
Aura const* aura = aurEff->GetBase();
SpellInfo const* spellInfo = aura->GetSpellInfo();
bool isPositiveSpell = spellInfo->IsPositive(); if (aura->IsPassive())
if (isPositiveSpell && isFriend) continue;
continue;
if (!isPositiveSpell && !isFriend) if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() &&
continue; aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration)
continue;
if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() && SpellInfo const* spellInfo = aura->GetSpellInfo();
aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration)
continue;
if (canDispel(spellInfo, dispelType)) bool isPositiveSpell = spellInfo->IsPositive();
return true; if (isPositiveSpell && isFriend)
} continue;
if (!isPositiveSpell && !isFriend)
continue;
if (canDispel(spellInfo, dispelType))
return true;
} }
return false; return false;
} }

View File

@@ -19,4 +19,10 @@ Value<Unit*>* PartyMemberNeedCureTrigger::GetTargetValue()
return context->GetValue<Unit*>("party member to dispel", dispelType); return context->GetValue<Unit*>("party member to dispel", dispelType);
} }
bool PartyMemberNeedCureTrigger::IsActive()
{
Unit* target = GetTarget();
return target && target->IsInWorld();
}
bool NeedWorldBuffTrigger::IsActive() { return !WorldBuffAction::NeedWorldBuffs(bot).empty(); } bool NeedWorldBuffTrigger::IsActive() { return !WorldBuffAction::NeedWorldBuffs(bot).empty(); }

View File

@@ -46,6 +46,7 @@ public:
} }
Value<Unit*>* GetTargetValue() override; Value<Unit*>* GetTargetValue() override;
bool IsActive() override;
}; };
class NeedWorldBuffTrigger : public Trigger class NeedWorldBuffTrigger : public Trigger

View File

@@ -41,36 +41,54 @@ Unit* PartyMemberToHeal::Calculate()
for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next()) for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next())
{ {
Player* player = gref->GetSource(); Player* player = gref->GetSource();
if (player && Check(player) && player->IsAlive()) if (player && player->IsAlive())
{ {
uint8 health = player->GetHealthPct(); uint8 health = player->GetHealthPct();
if (isRaid || health < sPlayerbotAIConfig->mediumHealth || !IsTargetOfSpellCast(player, predicate)) if (isRaid || health < sPlayerbotAIConfig->mediumHealth || !IsTargetOfSpellCast(player, predicate))
{ {
uint32 probeValue = 100;
if (player->GetDistance2d(bot) > sPlayerbotAIConfig->healDistance) if (player->GetDistance2d(bot) > sPlayerbotAIConfig->healDistance)
{ {
calc.probe(health + 30, player); probeValue = health + 30;
} }
else 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(); Pet* pet = player->GetPet();
if (pet && Check(pet) && pet->IsAlive()) if (pet && pet->IsAlive())
{ {
uint8 health = ((Unit*)pet)->GetHealthPct(); uint8 health = ((Unit*)pet)->GetHealthPct();
uint32 probeValue = 100;
if (isRaid || health < sPlayerbotAIConfig->mediumHealth) 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(); Unit* charm = player->GetCharm();
if (charm && Check(charm) && charm->IsAlive()) if (charm && charm->IsAlive())
{ {
uint8 health = charm->GetHealthPct(); uint8 health = charm->GetHealthPct();
uint32 probeValue = 100;
if (isRaid || health < sPlayerbotAIConfig->mediumHealth) 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; return (Unit*)calc.param;

View File

@@ -12,11 +12,11 @@ Unit* PartyMemberValue::FindPartyMember(std::vector<Player*>* party, FindPlayerP
{ {
for (Player* player : *party) for (Player* player : *party)
{ {
if (Check(player) && predicate.Check(player)) if (predicate.Check(player) && Check(player))
return player; return player;
if (Pet* pet = player->GetPet()) if (Pet* pet = player->GetPet())
if (Check(pet) && predicate.Check(pet)) if (predicate.Check(pet) && Check(pet))
return pet; return pet;
} }