From 7f86f6ce1edc30246d33a965e24dcc2c3d5846db Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 27 Feb 2022 23:31:47 -0500 Subject: [PATCH] Core/Gameobjects: Improve IsValidAttackTarget faction check for traps that hasn't owner or have NPC owner Port From (https://github.com/TrinityCore/TrinityCore/commit/054b62be3b20270bac8e36901c3e0ab14f66e58f) --- Source/Game/Entities/Object/WorldObject.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 663fbff8d..dd1a35199 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -2451,8 +2451,7 @@ namespace Game.Entities Unit unitOrOwner = unit; GameObject go = ToGameObject(); - if (go != null) - if (go.GetGoType() == GameObjectTypes.Trap) + if (go?.GetGoType() == GameObjectTypes.Trap) unitOrOwner = go.GetOwner(); // ignore immunity flags when assisting @@ -2476,15 +2475,24 @@ namespace Game.Entities // CvC case - can attack each other only when one of them is hostile if (unit && !unit.HasUnitFlag(UnitFlags.PlayerControlled) && unitTarget != null && !unitTarget.HasUnitFlag(UnitFlags.PlayerControlled)) - 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?.GetGoType() == GameObjectTypes.Trap) + { + Unit goOwner = go.GetOwner(); + if (goOwner == null || !goOwner.HasUnitFlag(UnitFlags.PlayerControlled)) + if (unitTarget && !unitTarget.HasUnitFlag(UnitFlags.PlayerControlled)) + return IsHostileTo(unitTarget) || unitTarget.IsHostileTo(this); + } // PvP, PvC, CvP case // can't attack friendly targets if (IsFriendlyTo(target) || target.IsFriendlyTo(this)) return false; - Player playerAffectingAttacker = unit != null && unit.HasUnitFlag(UnitFlags.PlayerControlled) ? GetAffectingPlayer() : IsGameObject() ? GetAffectingPlayer() : null; - Player playerAffectingTarget = unitTarget != null && unitTarget.HasUnitFlag(UnitFlags.PlayerControlled) ? target.GetAffectingPlayer() : null; + Player playerAffectingAttacker = unit != null && unit.HasUnitFlag(UnitFlags.PlayerControlled) ? GetAffectingPlayer() : go != null ? GetAffectingPlayer() : null; + Player playerAffectingTarget = unitTarget != null && unitTarget.HasUnitFlag(UnitFlags.PlayerControlled) ? unitTarget.GetAffectingPlayer() : null; // Not all neutral creatures can be attacked (even some unfriendly faction does not react aggresive to you, like Sporaggar) if ((playerAffectingAttacker && !playerAffectingTarget) || (!playerAffectingAttacker && playerAffectingTarget))