diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index e2c073f702c..9c17f1805c6 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2818,9 +2818,9 @@ bool WorldObject::IsValidAttackTarget(WorldObject const* target, SpellInfo const return false; Unit const* unitOrOwner = unit; - if (GameObject const* go = ToGameObject()) - if (go->GetGoType() == GAMEOBJECT_TYPE_TRAP) - unitOrOwner = go->GetOwner(); + GameObject const* go = ToGameObject(); + if (go && go->GetGoType() == GAMEOBJECT_TYPE_TRAP) + unitOrOwner = go->GetOwner(); // ignore immunity flags when assisting if (unitOrOwner && unitTarget && !(isPositiveSpell && bySpell->HasAttribute(SPELL_ATTR6_ASSIST_IGNORE_IMMUNE_FLAG))) @@ -2843,15 +2843,24 @@ bool WorldObject::IsValidAttackTarget(WorldObject const* target, SpellInfo const // CvC case - can attack each other only when one of them is hostile if (unit && !unit->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED) && unitTarget && !unitTarget->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED)) - return IsHostileTo(target) || target->IsHostileTo(this); + return IsHostileTo(unitTarget) || unitTarget->IsHostileTo(this); + + // Traps without owner or with NPC owner versus Creature case - can attack to creature only when one of them is hostile + if (go && go->GetGoType() == GAMEOBJECT_TYPE_TRAP) + { + Unit const* goOwner = go->GetOwner(); + if (!goOwner || !goOwner->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED)) + if (unitTarget && !unitTarget->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED)) + return IsHostileTo(unitTarget) || unitTarget->IsHostileTo(this); + } // PvP, PvC, CvP case // can't attack friendly targets if (IsFriendlyTo(target) || target->IsFriendlyTo(this)) return false; - 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; + Player const* playerAffectingAttacker = unit && unit->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED) ? GetAffectingPlayer() : go ? GetAffectingPlayer() : nullptr; + Player const* playerAffectingTarget = unitTarget && unitTarget->HasUnitFlag(UNIT_FLAG_PLAYER_CONTROLLED) ? unitTarget->GetAffectingPlayer() : nullptr; // Not all neutral creatures can be attacked (even some unfriendly faction does not react aggresive to you, like Sporaggar) if ((playerAffectingAttacker && !playerAffectingTarget) || (!playerAffectingAttacker && playerAffectingTarget)) |