[Avoid aoe] Crash fix and cover more spell

This commit is contained in:
Yunfan Li
2024-04-18 22:41:14 +08:00
parent 248bf6c003
commit 19ffe0227a
7 changed files with 67 additions and 102 deletions

View File

@@ -120,15 +120,13 @@ bool HasAreaDebuffValue::Calculate()
Aura* AreaDebuffValue::Calculate()
{
Unit::AuraApplicationMap& map = bot->GetAppliedAuras();
for (Unit::AuraApplicationMap::iterator i = map.begin(); i != map.end(); ++i)
{
Aura *aura = i->second->GetBase();
if (!aura)
continue;
AuraObjectType type = aura->GetType();
// bool is_area = aura->IsArea();
// Unit::AuraApplicationMap& map = bot->GetAppliedAuras();
Unit::AuraEffectList const& auras = bot->GetAuraEffectsByType(SPELL_AURA_PERIODIC_DAMAGE);
for (auto i = auras.begin(); i != auras.end(); ++i)
{
AuraEffect* aurEff = *i;
Aura *aura = aurEff->GetBase();
AuraObjectType type = aura->GetType();
bool isPositive = aura->GetSpellInfo()->IsPositive();
if (type == DYNOBJ_AURA_TYPE && !isPositive) {
DynamicObject* dynOwner = aura->GetDynobjOwner();
@@ -137,6 +135,23 @@ Aura* AreaDebuffValue::Calculate()
}
return aura;
}
}
}
// for (Unit::AuraApplicationMap::iterator i = map.begin(); i != map.end(); ++i)
// {
// Aura *aura = i->second->GetBase();
// if (!aura)
// continue;
// AuraObjectType type = aura->GetType();
// // bool is_area = aura->IsArea();
// bool isPositive = aura->GetSpellInfo()->IsPositive();
// if (type == DYNOBJ_AURA_TYPE && !isPositive) {
// DynamicObject* dynOwner = aura->GetDynobjOwner();
// if (!dynOwner) {
// continue;
// }
// return aura;
// }
// }
return nullptr;
}

View File

@@ -27,7 +27,7 @@ class NearestGameObjects : public ObjectGuidListCalculatedValue
class NearestTrapWithDamageValue : public ObjectGuidListCalculatedValue
{
public:
NearestTrapWithDamageValue(PlayerbotAI* botAI, float range = 10.0f) :
NearestTrapWithDamageValue(PlayerbotAI* botAI, float range = 15.0f) :
ObjectGuidListCalculatedValue(botAI, "nearest trap with damage", 1 * 1000), range(range) { }
protected:

View File

@@ -14,8 +14,8 @@ class PlayerbotAI;
class NearestUnitsValue : public ObjectGuidListCalculatedValue
{
public:
NearestUnitsValue(PlayerbotAI* botAI, std::string const name = "nearest units", float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = false) :
ObjectGuidListCalculatedValue(botAI, name, 1), range(range), ignoreLos(ignoreLos) { }
NearestUnitsValue(PlayerbotAI* botAI, std::string const name = "nearest units", float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = false, uint32 checkInterval = 1) :
ObjectGuidListCalculatedValue(botAI, name, checkInterval), range(range), ignoreLos(ignoreLos) { }
GuidVector Calculate() override;

View File

@@ -5,9 +5,14 @@
#include "PossibleTargetsValue.h"
#include "AttackersValue.h"
#include "CellImpl.h"
#include "DBCStructure.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Playerbots.h"
#include "SharedDefines.h"
#include "SpellAuraDefines.h"
#include "SpellAuraEffects.h"
#include "SpellMgr.h"
#include "Unit.h"
void PossibleTargetsValue::FindUnits(std::list<Unit*>& targets)
@@ -31,7 +36,26 @@ void PossibleTriggersValue::FindUnits(std::list<Unit*>& targets)
bool PossibleTriggersValue::AcceptUnit(Unit* unit)
{
return unit->HasUnitFlag(UNIT_FLAG_NON_ATTACKABLE) && unit->HasUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
return true; // AttackersValue::IsPossibleTarget(unit, bot, range);
if (!unit->HasUnitFlag(UNIT_FLAG_NOT_SELECTABLE)) {
return false;
}
Unit::AuraEffectList const& auras = unit->GetAuraEffectsByType(SPELL_AURA_PERIODIC_TRIGGER_SPELL);
for (auto i = auras.begin(); i != auras.end(); ++i)
{
AuraEffect* aurEff = *i;
const SpellInfo* spellInfo = aurEff->GetSpellInfo();
if (!spellInfo)
continue;
const SpellInfo* triggerSpellInfo = sSpellMgr->GetSpellInfo(spellInfo->Effects[aurEff->GetEffIndex()].TriggerSpell);
if (!triggerSpellInfo)
continue;
for (int j = 0; j < MAX_SPELL_EFFECTS; j++) {
if (triggerSpellInfo->Effects[j].Effect == SPELL_EFFECT_SCHOOL_DAMAGE) {
return true;
}
}
}
return false;
// return true; // AttackersValue::IsPossibleTarget(unit, bot, range);
}

View File

@@ -30,8 +30,8 @@ class AllTargetsValue : public PossibleTargetsValue
class PossibleTriggersValue : public NearestUnitsValue
{
public:
PossibleTriggersValue(PlayerbotAI* botAI, std::string const name = "possible targets", float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = true):
NearestUnitsValue(botAI, name, range, ignoreLos) { }
PossibleTriggersValue(PlayerbotAI* botAI, std::string const name = "possible triggers", float range = 15.0f, bool ignoreLos = true):
NearestUnitsValue(botAI, name, range, ignoreLos, 1 * 1000) { }
protected:
void FindUnits(std::list<Unit*>& targets) override;