Core/Gameobjects: Improve stealth detection

This commit is contained in:
Gildor authored and Ovahlord committed 2022-09-12 09:15:27 +02:00
1 parent eeef100e08
commit eab8e4aefb
4 files changed
+20 -13

No files matched your search

+14 -8
View File
@@ -1854,9 +1854,15 @@ bool WorldObject::CanDetectStealthOf(WorldObject const* obj, bool checkAlert) co
if (distance < combatReach)
return true;
if (!HasInArc(float(M_PI), obj))
// Only check back for units, it does not make sense for gameobjects
if (unit && !HasInArc(float(M_PI), obj))
return false;
// Traps should detect stealth always
if (GameObject const* go = ToGameObject())
if (go->GetGoType() == GAMEOBJECT_TYPE_TRAP)
return true;
GameObject const* go = obj->ToGameObject();
for (uint32 i = 0; i < TOTAL_STEALTH_TYPES; ++i)
{
@@ -2754,8 +2760,8 @@ ReputationRank WorldObject::GetReactionTo(WorldObject const* target) const
return *repRank;
}
Unit const* unit = ToUnit();
Unit const* targetUnit = target->ToUnit();
Unit const* unit = Coalesce<const Unit>(ToUnit(), selfPlayerOwner);
Unit const* targetUnit = Coalesce<const Unit>(target->ToUnit(), targetPlayerOwner);
if (unit && unit->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED))
{
if (unit && unit->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED))
@@ -3012,7 +3018,7 @@ bool WorldObject::IsValidAttackTarget(WorldObject const* target, SpellInfo const
if (IsFriendlyTo(target) || target->IsFriendlyTo(this))
return false;
Player const* playerAffectingAttacker = ToUnit() && HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED) ? GetAffectingPlayer() : nullptr;
Player const* playerAffectingAttacker = unit && unit->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED) ? GetAffectingPlayer() : ToGameObject() ? GetAffectingPlayer() : nullptr;
Player const* playerAffectingTarget = target->ToUnit() && target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED) ? target->GetAffectingPlayer() : nullptr;
// Not all neutral creatures can be attacked (even some unfriendly faction does not react aggresive to you, like Sporaggar)
@@ -3052,14 +3058,14 @@ bool WorldObject::IsValidAttackTarget(WorldObject const* target, SpellInfo const
// additional checks - only PvP case
if (playerAffectingAttacker && playerAffectingTarget)
{
if (unitTarget->IsPvP())
if (playerAffectingTarget->IsPvP())
return true;
if (unit->IsFFAPvP() && unitTarget->IsFFAPvP())
if (playerAffectingAttacker->IsFFAPvP() && playerAffectingTarget->IsFFAPvP())
return true;
return unit->HasByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PVP_FLAG, UNIT_BYTE2_FLAG_UNK1)
|| unitTarget->HasByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PVP_FLAG, UNIT_BYTE2_FLAG_UNK1);
return playerAffectingAttacker->HasByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PVP_FLAG, UNIT_BYTE2_FLAG_UNK1)
|| playerAffectingTarget->HasByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PVP_FLAG, UNIT_BYTE2_FLAG_UNK1);
}
return true;