Core/Gameobjects: Improve stealth detection (#24417)

* Core/Gameobjects: Improve stealth detection

* fix warning: private field 'i_funit' is not used

* Code cleanup

* add comment

Co-authored-by: jackpoz <[email protected]>
(cherry picked from commit 862097a63351e957fd4aa6cb82fe7d9edf4d3926)
This commit is contained in:
Gildor
2022-01-01 15:05:01 +01:00
committed by Shauren
parent 2aa5f4e1b2
commit 60e66621da
4 changed files with 20 additions and 13 deletions
+14 -8
View File
@@ -1548,9 +1548,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)
{
@@ -2457,8 +2463,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->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED))
{
if (targetUnit && targetUnit->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED))
@@ -2813,7 +2819,7 @@ bool WorldObject::IsValidAttackTarget(WorldObject const* target, SpellInfo const
if (IsFriendlyTo(target) || target->IsFriendlyTo(this))
return false;
Player const* playerAffectingAttacker = unit && unit->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED) ? GetAffectingPlayer() : nullptr;
Player const* playerAffectingAttacker = unit && unit->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED) ? GetAffectingPlayer() : ToGameObject() ? GetAffectingPlayer() : nullptr;
Player const* playerAffectingTarget = unitTarget && unitTarget->HasUnitFlag(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)
@@ -2854,14 +2860,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->HasPvpFlag(UNIT_BYTE2_FLAG_UNK1) ||
unitTarget->HasPvpFlag(UNIT_BYTE2_FLAG_UNK1);
return playerAffectingAttacker->HasPvpFlag(UNIT_BYTE2_FLAG_UNK1) ||
playerAffectingTarget->HasPvpFlag(UNIT_BYTE2_FLAG_UNK1);
}
return true;