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)
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user