mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-27 15:36:22 +00:00
Added some additional defense checks around isHostile and unit/target (#2056)
Needs second pair of eyes, they appear in crash logs here and there. Its merely a patch on a open wound. ---- As in aslong there multithreads in mapupdate, which we need for decent performance and core calls are not done correctly due various reasons. These type of issues remain. Although i am planning to experiment a little with threadsafe execution of our strategies vs performance. The most effective thing we could do is check every single action and check its stateless and where it does effect the state or read the state of a core object its done in the safest way. flags, worldthread where possible and/ot simply taking into account the state might be invalid.
This commit is contained in:
@@ -28,7 +28,7 @@ bool TravelAction::Execute(Event event)
|
|||||||
for (Unit* unit : targets)
|
for (Unit* unit : targets)
|
||||||
{
|
{
|
||||||
newTarget = unit;
|
newTarget = unit;
|
||||||
if (!newTarget)
|
if (!newTarget || !newTarget->IsInWorld() || newTarget->IsDuringRemoveFromWorld())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (newTarget->GetMapId() != bot->GetMapId())
|
if (newTarget->GetMapId() != bot->GetMapId())
|
||||||
|
|||||||
@@ -245,8 +245,10 @@ bool UseItemAction::UseItem(Item* item, ObjectGuid goGuid, Item* itemTarget, Uni
|
|||||||
{
|
{
|
||||||
packet << unitTarget->GetGUID();
|
packet << unitTarget->GetGUID();
|
||||||
targetSelected = true;
|
targetSelected = true;
|
||||||
// If the target is bot or is an enemy, say "on self"
|
|
||||||
if (unitTarget == bot || (unitTarget->IsHostileTo(bot)))
|
if (unitTarget == bot || !unitTarget->IsInWorld() || unitTarget->IsDuringRemoveFromWorld())
|
||||||
|
out << " on self";
|
||||||
|
else if (unitTarget->IsHostileTo(bot))
|
||||||
out << " on self";
|
out << " on self";
|
||||||
else
|
else
|
||||||
out << " on " << unitTarget->GetName();
|
out << " on " << unitTarget->GetName();
|
||||||
|
|||||||
@@ -258,6 +258,9 @@ bool PossibleAddsValue::Calculate()
|
|||||||
|
|
||||||
if (Unit* add = botAI->GetUnit(guid))
|
if (Unit* add = botAI->GetUnit(guid))
|
||||||
{
|
{
|
||||||
|
if (!add->IsInWorld() || add->IsDuringRemoveFromWorld())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!add->GetTarget() && !add->GetThreatMgr().getCurrentVictim() && add->IsHostileTo(bot))
|
if (!add->GetTarget() && !add->GetThreatMgr().getCurrentVictim() && add->IsHostileTo(bot))
|
||||||
{
|
{
|
||||||
for (ObjectGuid const attackerGUID : attackers)
|
for (ObjectGuid const attackerGUID : attackers)
|
||||||
|
|||||||
@@ -59,26 +59,22 @@ Unit* GrindTargetValue::FindTargetForGrinding(uint32 assistCount)
|
|||||||
for (ObjectGuid const guid : targets)
|
for (ObjectGuid const guid : targets)
|
||||||
{
|
{
|
||||||
Unit* unit = botAI->GetUnit(guid);
|
Unit* unit = botAI->GetUnit(guid);
|
||||||
|
|
||||||
if (!unit)
|
if (!unit)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!unit->IsInWorld() || unit->IsDuringRemoveFromWorld())
|
||||||
|
continue;
|
||||||
|
|
||||||
auto& rep = bot->ToPlayer()->GetReputationMgr();
|
auto& rep = bot->ToPlayer()->GetReputationMgr();
|
||||||
if (unit->ToCreature() && !unit->ToCreature()->GetCreatureTemplate()->lootid &&
|
if (unit->ToCreature() && !unit->ToCreature()->GetCreatureTemplate()->lootid &&
|
||||||
bot->GetReactionTo(unit) >= REP_NEUTRAL)
|
bot->GetReactionTo(unit) >= REP_NEUTRAL)
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!bot->IsHostileTo(unit) && unit->GetNpcFlags() != UNIT_NPC_FLAG_NONE)
|
if (!bot->IsHostileTo(unit) && unit->GetNpcFlags() != UNIT_NPC_FLAG_NONE)
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!bot->isHonorOrXPTarget(unit))
|
if (!bot->isHonorOrXPTarget(unit))
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (abs(bot->GetPositionZ() - unit->GetPositionZ()) > INTERACTION_DISTANCE)
|
if (abs(bot->GetPositionZ() - unit->GetPositionZ()) > INTERACTION_DISTANCE)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -27,7 +27,16 @@ void NearestHostileNpcsValue::FindUnits(std::list<Unit*>& targets)
|
|||||||
Cell::VisitObjects(bot, searcher, range);
|
Cell::VisitObjects(bot, searcher, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NearestHostileNpcsValue::AcceptUnit(Unit* unit) { return unit->IsHostileTo(bot) && !unit->IsPlayer(); }
|
bool NearestHostileNpcsValue::AcceptUnit(Unit* unit)
|
||||||
|
{
|
||||||
|
if (!unit || !unit->IsInWorld() || unit->IsDuringRemoveFromWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (unit->IsPlayer())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return unit->IsHostileTo(bot);
|
||||||
|
}
|
||||||
|
|
||||||
void NearestVehiclesValue::FindUnits(std::list<Unit*>& targets)
|
void NearestVehiclesValue::FindUnits(std::list<Unit*>& targets)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ void PossibleRpgTargetsValue::FindUnits(std::list<Unit*>& targets)
|
|||||||
|
|
||||||
bool PossibleRpgTargetsValue::AcceptUnit(Unit* unit)
|
bool PossibleRpgTargetsValue::AcceptUnit(Unit* unit)
|
||||||
{
|
{
|
||||||
|
if (!unit || !unit->IsInWorld() || unit->IsDuringRemoveFromWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (unit->IsHostileTo(bot) || unit->IsPlayer())
|
if (unit->IsHostileTo(bot) || unit->IsPlayer())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -70,7 +73,8 @@ bool PossibleRpgTargetsValue::AcceptUnit(Unit* unit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TravelTarget* travelTarget = context->GetValue<TravelTarget*>("travel target")->Get();
|
TravelTarget* travelTarget = context->GetValue<TravelTarget*>("travel target")->Get();
|
||||||
if (travelTarget->getDestination() && travelTarget->getDestination()->getEntry() == unit->GetEntry())
|
if (travelTarget && travelTarget->getDestination() &&
|
||||||
|
travelTarget->getDestination()->getEntry() == unit->GetEntry())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (urand(1, 100) < 25 && unit->IsFriendlyTo(bot))
|
if (urand(1, 100) < 25 && unit->IsFriendlyTo(bot))
|
||||||
@@ -145,6 +149,9 @@ void PossibleNewRpgTargetsValue::FindUnits(std::list<Unit*>& targets)
|
|||||||
|
|
||||||
bool PossibleNewRpgTargetsValue::AcceptUnit(Unit* unit)
|
bool PossibleNewRpgTargetsValue::AcceptUnit(Unit* unit)
|
||||||
{
|
{
|
||||||
|
if (!unit || !unit->IsInWorld() || unit->IsDuringRemoveFromWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (unit->IsHostileTo(bot) || unit->IsPlayer())
|
if (unit->IsHostileTo(bot) || unit->IsPlayer())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,10 @@ bool IccGunshipCannonNearTrigger::IsActive()
|
|||||||
bool IccGunshipTeleportAllyTrigger::IsActive()
|
bool IccGunshipTeleportAllyTrigger::IsActive()
|
||||||
{
|
{
|
||||||
Unit* boss = bot->FindNearestCreature(NPC_HIGH_OVERLORD_SAURFANG, 100.0f);
|
Unit* boss = bot->FindNearestCreature(NPC_HIGH_OVERLORD_SAURFANG, 100.0f);
|
||||||
if (!boss)
|
if (!boss || !boss->IsInWorld() || boss->IsDuringRemoveFromWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!boss->IsAlive())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!boss->IsHostileTo(bot))
|
if (!boss->IsHostileTo(bot))
|
||||||
@@ -111,7 +114,10 @@ bool IccGunshipTeleportAllyTrigger::IsActive()
|
|||||||
bool IccGunshipTeleportHordeTrigger::IsActive()
|
bool IccGunshipTeleportHordeTrigger::IsActive()
|
||||||
{
|
{
|
||||||
Unit* boss = bot->FindNearestCreature(NPC_MURADIN_BRONZEBEARD, 100.0f);
|
Unit* boss = bot->FindNearestCreature(NPC_MURADIN_BRONZEBEARD, 100.0f);
|
||||||
if (!boss)
|
if (!boss || !boss->IsInWorld() || boss->IsDuringRemoveFromWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!boss->IsAlive())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!boss->IsHostileTo(bot))
|
if (!boss->IsHostileTo(bot))
|
||||||
|
|||||||
@@ -765,9 +765,13 @@ bool FreyaMoveToHealingSporeTrigger::IsActive()
|
|||||||
bool ThorimUnbalancingStrikeTrigger::IsActive()
|
bool ThorimUnbalancingStrikeTrigger::IsActive()
|
||||||
{
|
{
|
||||||
Unit* boss = AI_VALUE2(Unit*, "find target", "thorim");
|
Unit* boss = AI_VALUE2(Unit*, "find target", "thorim");
|
||||||
|
if (!boss || !boss->IsInWorld() || boss->IsDuringRemoveFromWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
// Check boss and it is alive
|
if (!boss->IsAlive())
|
||||||
if (!boss || !boss->IsAlive() || !boss->IsHostileTo(bot))
|
return false;
|
||||||
|
|
||||||
|
if (!boss->IsHostileTo(bot))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return bot->HasAura(SPELL_UNBALANCING_STRIKE);
|
return bot->HasAura(SPELL_UNBALANCING_STRIKE);
|
||||||
@@ -804,8 +808,13 @@ bool ThorimMarkDpsTargetTrigger::IsActive()
|
|||||||
|
|
||||||
Unit* boss = AI_VALUE2(Unit*, "find target", "thorim");
|
Unit* boss = AI_VALUE2(Unit*, "find target", "thorim");
|
||||||
|
|
||||||
// Check boss and it is alive
|
if (!boss || !boss->IsInWorld() || boss->IsDuringRemoveFromWorld())
|
||||||
if (!boss || !boss->IsAlive() || !boss->IsHostileTo(bot))
|
return false;
|
||||||
|
|
||||||
|
if (!boss->IsAlive())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!boss->IsHostileTo(bot))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (boss->GetPositionZ() < ULDUAR_THORIM_AXIS_Z_FLOOR_THRESHOLD && (!currentSkullUnit || !currentSkullUnit->IsAlive()))
|
if (boss->GetPositionZ() < ULDUAR_THORIM_AXIS_Z_FLOOR_THRESHOLD && (!currentSkullUnit || !currentSkullUnit->IsAlive()))
|
||||||
@@ -982,9 +991,13 @@ bool ThorimGauntletPositioningTrigger::IsActive()
|
|||||||
bool ThorimArenaPositioningTrigger::IsActive()
|
bool ThorimArenaPositioningTrigger::IsActive()
|
||||||
{
|
{
|
||||||
Unit* boss = AI_VALUE2(Unit*, "find target", "thorim");
|
Unit* boss = AI_VALUE2(Unit*, "find target", "thorim");
|
||||||
|
if (!boss || !boss->IsInWorld() || boss->IsDuringRemoveFromWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
// Check boss and it is alive
|
if (!boss->IsAlive())
|
||||||
if (!boss || !boss->IsAlive() || !boss->IsHostileTo(bot))
|
return false;
|
||||||
|
|
||||||
|
if (!boss->IsHostileTo(bot))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (boss->GetPositionZ() < ULDUAR_THORIM_AXIS_Z_FLOOR_THRESHOLD)
|
if (boss->GetPositionZ() < ULDUAR_THORIM_AXIS_Z_FLOOR_THRESHOLD)
|
||||||
@@ -1080,9 +1093,13 @@ bool ThorimPhase2PositioningTrigger::IsActive()
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
Unit* boss = AI_VALUE2(Unit*, "find target", "thorim");
|
Unit* boss = AI_VALUE2(Unit*, "find target", "thorim");
|
||||||
|
if (!boss || !boss->IsInWorld() || boss->IsDuringRemoveFromWorld())
|
||||||
|
return false;
|
||||||
|
|
||||||
// Check boss and it is alive
|
if (!boss->IsAlive())
|
||||||
if (!boss || !boss->IsAlive() || !boss->IsHostileTo(bot))
|
return false;
|
||||||
|
|
||||||
|
if (!boss->IsHostileTo(bot))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (boss->GetPositionZ() > ULDUAR_THORIM_AXIS_Z_FLOOR_THRESHOLD)
|
if (boss->GetPositionZ() > ULDUAR_THORIM_AXIS_Z_FLOOR_THRESHOLD)
|
||||||
|
|||||||
Reference in New Issue
Block a user