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

@@ -990,7 +990,7 @@ void GameObject::Update(uint32 diff)
if (Unit* owner = GetOwner())
{
// Hunter trap: Search units which are unfriendly to the trap's owner
Trinity::NearestAttackableNoTotemUnitInObjectRangeCheck checker(this, owner, radius);
Trinity::NearestAttackableNoTotemUnitInObjectRangeCheck checker(this, radius);
Trinity::UnitLastSearcher<Trinity::NearestAttackableNoTotemUnitInObjectRangeCheck> searcher(this, target, checker);
Cell::VisitAllObjects(this, searcher, radius);
}
+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;
@@ -910,7 +910,7 @@ namespace Trinity
class NearestAttackableNoTotemUnitInObjectRangeCheck
{
public:
NearestAttackableNoTotemUnitInObjectRangeCheck(WorldObject const* obj, Unit const* funit, float range) : i_obj(obj), i_funit(funit), i_range(range) { }
NearestAttackableNoTotemUnitInObjectRangeCheck(WorldObject const* obj, float range) : i_obj(obj), i_range(range) { }
bool operator()(Unit* u)
{
@@ -926,7 +926,7 @@ namespace Trinity
if (!u->isTargetableForAttack(false))
return false;
if (!i_obj->IsWithinDistInMap(u, i_range) || !i_funit->IsValidAttackTarget(u))
if (!i_obj->IsWithinDistInMap(u, i_range) || !i_obj->IsValidAttackTarget(u))
return false;
i_range = i_obj->GetDistance(*u);
@@ -934,7 +934,6 @@ namespace Trinity
}
private:
WorldObject const* i_obj;
Unit const* i_funit;
float i_range;
};
+3 -1
View File
@@ -5727,7 +5727,9 @@ SpellCastResult Spell::CheckCast(bool strict, uint32* param1 /*= nullptr*/, uint
{
// Check explicit target for m_originalCaster - todo: get rid of such workarounds
WorldObject* caster = m_caster;
if (m_originalCaster)
// in case of gameobjects like traps, we need the gameobject itself to check target validity
// otherwise, if originalCaster is far away and cannot detect the target, the trap would not hit the target
if (m_originalCaster && !caster->ToGameObject())
caster = m_originalCaster;
SpellCastResult castResult = m_spellInfo->CheckExplicitTarget(caster, m_targets.GetObjectTarget(), m_targets.GetItemTarget());