mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-12-01 21:12:50 +08:00
[Avoid aoe] Crash fix and cover more spell
This commit is contained in:
@@ -14,8 +14,6 @@
|
|||||||
#include "PlayerbotAIConfig.h"
|
#include "PlayerbotAIConfig.h"
|
||||||
#include "Random.h"
|
#include "Random.h"
|
||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
#include "SpellAuraEffects.h"
|
|
||||||
#include "SpellAuraEffects.h"
|
|
||||||
#include "SpellInfo.h"
|
#include "SpellInfo.h"
|
||||||
#include "TargetedMovementGenerator.h"
|
#include "TargetedMovementGenerator.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
@@ -1415,13 +1413,13 @@ const Movement::PointsArray MovementAction::SearchForBestPath(float x, float y,
|
|||||||
PathGenerator gen(bot);
|
PathGenerator gen(bot);
|
||||||
gen.CalculatePath(x, y, tempZ);
|
gen.CalculatePath(x, y, tempZ);
|
||||||
Movement::PointsArray result = gen.GetPath();
|
Movement::PointsArray result = gen.GetPath();
|
||||||
modified_z = tempZ;
|
|
||||||
float min_length = gen.getPathLength();
|
float min_length = gen.getPathLength();
|
||||||
if (gen.GetPathType() == PATHFIND_NORMAL && abs(tempZ - z) < 0.5f) {
|
if (gen.GetPathType() == PATHFIND_NORMAL && abs(tempZ - z) < 0.5f) {
|
||||||
|
modified_z = tempZ;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// Start searching
|
// Start searching
|
||||||
if (gen.GetPathType() == PATHFIND_NORMAL) {
|
if (gen.GetPathType() & PATHFIND_NORMAL) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
int count = 1;
|
int count = 1;
|
||||||
@@ -1432,7 +1430,7 @@ const Movement::PointsArray MovementAction::SearchForBestPath(float x, float y,
|
|||||||
}
|
}
|
||||||
PathGenerator gen(bot);
|
PathGenerator gen(bot);
|
||||||
gen.CalculatePath(x, y, tempZ);
|
gen.CalculatePath(x, y, tempZ);
|
||||||
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
|
if (gen.GetPathType() & PATHFIND_NORMAL && gen.getPathLength() < min_length) {
|
||||||
found = true;
|
found = true;
|
||||||
min_length = gen.getPathLength();
|
min_length = gen.getPathLength();
|
||||||
result = gen.GetPath();
|
result = gen.GetPath();
|
||||||
@@ -1446,7 +1444,7 @@ const Movement::PointsArray MovementAction::SearchForBestPath(float x, float y,
|
|||||||
}
|
}
|
||||||
PathGenerator gen(bot);
|
PathGenerator gen(bot);
|
||||||
gen.CalculatePath(x, y, tempZ);
|
gen.CalculatePath(x, y, tempZ);
|
||||||
if (gen.GetPathType() == PATHFIND_NORMAL && gen.getPathLength() < min_length) {
|
if (gen.GetPathType() & PATHFIND_NORMAL && gen.getPathLength() < min_length) {
|
||||||
found = true;
|
found = true;
|
||||||
min_length = gen.getPathLength();
|
min_length = gen.getPathLength();
|
||||||
result = gen.GetPath();
|
result = gen.GetPath();
|
||||||
@@ -1520,16 +1518,17 @@ bool AvoidAoeAction::Execute(Event event)
|
|||||||
bool AvoidAoeAction::AvoidAuraWithDynamicObj()
|
bool AvoidAoeAction::AvoidAuraWithDynamicObj()
|
||||||
{
|
{
|
||||||
Aura* aura = AI_VALUE(Aura*, "area debuff");
|
Aura* aura = AI_VALUE(Aura*, "area debuff");
|
||||||
if (!aura) {
|
if (!aura || aura->IsRemoved() || aura->IsExpired()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Crash fix: maybe change owner due to check interval
|
||||||
|
if (aura->GetType() != DYNOBJ_AURA_TYPE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const SpellInfo* spellInfo = aura->GetSpellInfo();
|
const SpellInfo* spellInfo = aura->GetSpellInfo();
|
||||||
if (!spellInfo) {
|
if (!spellInfo) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!bot->HasAura(spellInfo->Id)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
DynamicObject* dynOwner = aura->GetDynobjOwner();
|
DynamicObject* dynOwner = aura->GetDynobjOwner();
|
||||||
if (!dynOwner || !dynOwner->IsInWorld()) {
|
if (!dynOwner || !dynOwner->IsInWorld()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1599,84 +1598,12 @@ bool AvoidAoeAction::AvoidGameObjectWithDamage()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AvoidAoeAction::AvoidUnitWithDamageAura()
|
|
||||||
{
|
|
||||||
GuidVector traps = AI_VALUE(GuidVector, "possible triggers");
|
|
||||||
if (traps.empty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (ObjectGuid &guid : traps) {
|
|
||||||
Unit* unit = botAI->GetUnit(guid);
|
|
||||||
if (!unit || !unit->IsInWorld()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
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) {
|
|
||||||
float radius = triggerSpellInfo->Effects[j].CalcRadius();
|
|
||||||
if (bot->GetDistance(unit) > radius) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::ostringstream name;
|
|
||||||
name << "[" << triggerSpellInfo->SpellName[0] << "] (unit)";
|
|
||||||
if (FleePostion(unit->GetPosition(), radius, name.str())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Unit::AuraApplicationMap& map = unit->GetAppliedAuras();
|
|
||||||
// for (Unit::AuraApplicationMap::iterator i = map.begin(); i != map.end(); ++i)
|
|
||||||
// {
|
|
||||||
// Aura *aura = i->second->GetBase();
|
|
||||||
// if (!aura)
|
|
||||||
// continue;
|
|
||||||
// const SpellInfo* spellInfo = aura->GetSpellInfo();
|
|
||||||
// if (!spellInfo)
|
|
||||||
// continue;
|
|
||||||
// for (int i = 0; i < MAX_SPELL_EFFECTS; i++) {
|
|
||||||
// if (spellInfo->Effects[i].Effect == SPELL_EFFECT_APPLY_AURA &&
|
|
||||||
// spellInfo->Effects[i].ApplyAuraName == SPELL_AURA_PERIODIC_TRIGGER_SPELL) {
|
|
||||||
// const SpellInfo* triggerSpellInfo = sSpellMgr->GetSpellInfo(spellInfo->Effects[i].TriggerSpell);
|
|
||||||
// if (!triggerSpellInfo)
|
|
||||||
// continue;
|
|
||||||
// for (int j = 0; j < MAX_SPELL_EFFECTS; j++) {
|
|
||||||
// if (triggerSpellInfo->Effects[j].Effect == SPELL_EFFECT_SCHOOL_DAMAGE) {
|
|
||||||
// float radius = triggerSpellInfo->Effects[j].CalcRadius();
|
|
||||||
// if (bot->GetDistance(unit) > radius) {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// std::ostringstream name;
|
|
||||||
// name << "[" << triggerSpellInfo->SpellName[0] << "] (unit)";
|
|
||||||
// if (FleePostion(unit->GetPosition(), radius, name.str())) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AvoidAoeAction::FleePostion(Position pos, float radius, std::string name)
|
bool AvoidAoeAction::FleePostion(Position pos, float radius, std::string name)
|
||||||
{
|
{
|
||||||
Unit* currentTarget = AI_VALUE(Unit*, "current target");
|
Unit* currentTarget = AI_VALUE(Unit*, "current target");
|
||||||
std::vector<float> possibleAngles;
|
std::vector<float> possibleAngles;
|
||||||
if (currentTarget) {
|
if (currentTarget) {
|
||||||
|
// Normally, move to left or right is the best position
|
||||||
float angleLeft = bot->GetAngle(currentTarget) + M_PI / 2;
|
float angleLeft = bot->GetAngle(currentTarget) + M_PI / 2;
|
||||||
float angleRight = bot->GetAngle(currentTarget) - M_PI / 2;
|
float angleRight = bot->GetAngle(currentTarget) - M_PI / 2;
|
||||||
possibleAngles.push_back(angleLeft);
|
possibleAngles.push_back(angleLeft);
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ bool TellAuraAction::Execute(Event event)
|
|||||||
Aura * aura = i->second->GetBase();
|
Aura * aura = i->second->GetBase();
|
||||||
if (!aura)
|
if (!aura)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string auraName = aura->GetSpellInfo()->SpellName[0];
|
const std::string auraName = aura->GetSpellInfo()->SpellName[0];
|
||||||
sLog->outMessage("playerbot", LOG_LEVEL_DEBUG, "Info of Aura - name: " + auraName);
|
sLog->outMessage("playerbot", LOG_LEVEL_DEBUG, "Info of Aura - name: " + auraName);
|
||||||
AuraObjectType type = aura->GetType();
|
AuraObjectType type = aura->GetType();
|
||||||
|
|||||||
@@ -120,15 +120,13 @@ bool HasAreaDebuffValue::Calculate()
|
|||||||
|
|
||||||
Aura* AreaDebuffValue::Calculate()
|
Aura* AreaDebuffValue::Calculate()
|
||||||
{
|
{
|
||||||
Unit::AuraApplicationMap& map = bot->GetAppliedAuras();
|
// Unit::AuraApplicationMap& map = bot->GetAppliedAuras();
|
||||||
for (Unit::AuraApplicationMap::iterator i = map.begin(); i != map.end(); ++i)
|
Unit::AuraEffectList const& auras = bot->GetAuraEffectsByType(SPELL_AURA_PERIODIC_DAMAGE);
|
||||||
|
for (auto i = auras.begin(); i != auras.end(); ++i)
|
||||||
{
|
{
|
||||||
Aura *aura = i->second->GetBase();
|
AuraEffect* aurEff = *i;
|
||||||
if (!aura)
|
Aura *aura = aurEff->GetBase();
|
||||||
continue;
|
|
||||||
|
|
||||||
AuraObjectType type = aura->GetType();
|
AuraObjectType type = aura->GetType();
|
||||||
// bool is_area = aura->IsArea();
|
|
||||||
bool isPositive = aura->GetSpellInfo()->IsPositive();
|
bool isPositive = aura->GetSpellInfo()->IsPositive();
|
||||||
if (type == DYNOBJ_AURA_TYPE && !isPositive) {
|
if (type == DYNOBJ_AURA_TYPE && !isPositive) {
|
||||||
DynamicObject* dynOwner = aura->GetDynobjOwner();
|
DynamicObject* dynOwner = aura->GetDynobjOwner();
|
||||||
@@ -138,5 +136,22 @@ Aura* AreaDebuffValue::Calculate()
|
|||||||
return aura;
|
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;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ class NearestGameObjects : public ObjectGuidListCalculatedValue
|
|||||||
class NearestTrapWithDamageValue : public ObjectGuidListCalculatedValue
|
class NearestTrapWithDamageValue : public ObjectGuidListCalculatedValue
|
||||||
{
|
{
|
||||||
public:
|
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) { }
|
ObjectGuidListCalculatedValue(botAI, "nearest trap with damage", 1 * 1000), range(range) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ class PlayerbotAI;
|
|||||||
class NearestUnitsValue : public ObjectGuidListCalculatedValue
|
class NearestUnitsValue : public ObjectGuidListCalculatedValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NearestUnitsValue(PlayerbotAI* botAI, std::string const name = "nearest units", float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = false) :
|
NearestUnitsValue(PlayerbotAI* botAI, std::string const name = "nearest units", float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = false, uint32 checkInterval = 1) :
|
||||||
ObjectGuidListCalculatedValue(botAI, name, 1), range(range), ignoreLos(ignoreLos) { }
|
ObjectGuidListCalculatedValue(botAI, name, checkInterval), range(range), ignoreLos(ignoreLos) { }
|
||||||
|
|
||||||
GuidVector Calculate() override;
|
GuidVector Calculate() override;
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,14 @@
|
|||||||
#include "PossibleTargetsValue.h"
|
#include "PossibleTargetsValue.h"
|
||||||
#include "AttackersValue.h"
|
#include "AttackersValue.h"
|
||||||
#include "CellImpl.h"
|
#include "CellImpl.h"
|
||||||
|
#include "DBCStructure.h"
|
||||||
#include "GridNotifiers.h"
|
#include "GridNotifiers.h"
|
||||||
#include "GridNotifiersImpl.h"
|
#include "GridNotifiersImpl.h"
|
||||||
#include "Playerbots.h"
|
#include "Playerbots.h"
|
||||||
|
#include "SharedDefines.h"
|
||||||
|
#include "SpellAuraDefines.h"
|
||||||
|
#include "SpellAuraEffects.h"
|
||||||
|
#include "SpellMgr.h"
|
||||||
#include "Unit.h"
|
#include "Unit.h"
|
||||||
|
|
||||||
void PossibleTargetsValue::FindUnits(std::list<Unit*>& targets)
|
void PossibleTargetsValue::FindUnits(std::list<Unit*>& targets)
|
||||||
@@ -31,7 +36,26 @@ void PossibleTriggersValue::FindUnits(std::list<Unit*>& targets)
|
|||||||
|
|
||||||
bool PossibleTriggersValue::AcceptUnit(Unit* unit)
|
bool PossibleTriggersValue::AcceptUnit(Unit* unit)
|
||||||
{
|
{
|
||||||
return unit->HasUnitFlag(UNIT_FLAG_NON_ATTACKABLE) && unit->HasUnitFlag(UNIT_FLAG_NOT_SELECTABLE);
|
if (!unit->HasUnitFlag(UNIT_FLAG_NOT_SELECTABLE)) {
|
||||||
return true; // AttackersValue::IsPossibleTarget(unit, bot, range);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ class AllTargetsValue : public PossibleTargetsValue
|
|||||||
class PossibleTriggersValue : public NearestUnitsValue
|
class PossibleTriggersValue : public NearestUnitsValue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PossibleTriggersValue(PlayerbotAI* botAI, std::string const name = "possible targets", float range = sPlayerbotAIConfig->sightDistance, bool ignoreLos = true):
|
PossibleTriggersValue(PlayerbotAI* botAI, std::string const name = "possible triggers", float range = 15.0f, bool ignoreLos = true):
|
||||||
NearestUnitsValue(botAI, name, range, ignoreLos) { }
|
NearestUnitsValue(botAI, name, range, ignoreLos, 1 * 1000) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void FindUnits(std::list<Unit*>& targets) override;
|
void FindUnits(std::list<Unit*>& targets) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user