fix: Attempts to fix IsEnemy with NPC summons again again. (#2052)

This commit is contained in:
Kamron Batman 2025-01-03 19:58:37 -08:00 • committed by GitHub
parent 5d53825c21
commit 9f50ae431a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -278,7 +278,7 @@ namespace Server.Mobiles
private bool m_bTamable; private bool m_bTamable;
private int m_ColdResistance; private int m_ColdResistance;
private bool m_Controlled; // Is controlled private bool _controlled; // Is controlled
private Mobile m_ControlMaster; // My master private Mobile m_ControlMaster; // My master
private OrderType m_ControlOrder; // My order private OrderType m_ControlOrder; // My order
@ -370,7 +370,7 @@ namespace Server.Mobiles
Debug = false; Debug = false;
m_Controlled = false; _controlled = false;
m_ControlMaster = null; m_ControlMaster = null;
ControlTarget = null; ControlTarget = null;
m_ControlOrder = OrderType.None; m_ControlOrder = OrderType.None;
@ -749,15 +749,15 @@ namespace Server.Mobiles
[CommandProperty(AccessLevel.GameMaster)] [CommandProperty(AccessLevel.GameMaster)]
public bool Controlled public bool Controlled
{ {
get => m_Controlled; get => _controlled;
set set
{ {
if (m_Controlled == value) if (_controlled == value)
{ {
return; return;
} }
m_Controlled = value; _controlled = value;
Delta(MobileDelta.Noto); Delta(MobileDelta.Noto);
InvalidateProperties(); InvalidateProperties();
@ -1353,24 +1353,23 @@ namespace Server.Mobiles
return false; return false;
} }
if (FightMode == FightMode.Evil && m.Karma < 0 || c.FightMode == FightMode.Evil && Karma < 0) if (m_Team != c.Team || FightMode == FightMode.Evil && m.Karma < 0 || c.FightMode == FightMode.Evil && Karma < 0)
{ {
return true; return true;
} }
if (m_Team != c.Team) var master = GetMaster();
var cMaster = c.GetMaster();
if (master == null)
{ {
return true; // Non-summons will attack summons of non-NPCs
return cMaster != null && cMaster is not BaseCreature;
} }
var targetControlled = c._summoned || c.m_Controlled; // Summons will attack others summons, if they are enemies with their master
// Pets will attack non-summons, but not other summons (legacy logic)
if (_summoned || m_Controlled) return (master as BaseCreature)?.IsEnemy(cMaster ?? m) ?? cMaster == null;
{
return targetControlled || c.IsEnemy(GetMaster());
}
return targetControlled && IsEnemy(c.GetMaster());
} }
public override string ApplyNameSuffix(string suffix) public override string ApplyNameSuffix(string suffix)
@ -1871,7 +1870,7 @@ namespace Server.Mobiles
// Version 2 // Version 2
writer.Write((int)FightMode); writer.Write((int)FightMode);
writer.Write(m_Controlled); writer.Write(_controlled);
writer.Write(m_ControlMaster); writer.Write(m_ControlMaster);
writer.Write(ControlTarget); writer.Write(ControlTarget);
writer.Write(ControlDest); writer.Write(ControlDest);
@ -2021,7 +2020,7 @@ namespace Server.Mobiles
{ {
FightMode = (FightMode)reader.ReadInt(); FightMode = (FightMode)reader.ReadInt();
m_Controlled = reader.ReadBool(); _controlled = reader.ReadBool();
m_ControlMaster = reader.ReadEntity<Mobile>(); m_ControlMaster = reader.ReadEntity<Mobile>();
ControlTarget = reader.ReadEntity<Mobile>(); ControlTarget = reader.ReadEntity<Mobile>();
ControlDest = reader.ReadPoint3D(); ControlDest = reader.ReadPoint3D();
@ -2049,7 +2048,7 @@ namespace Server.Mobiles
{ {
FightMode = FightMode.Closest; FightMode = FightMode.Closest;
m_Controlled = false; _controlled = false;
m_ControlMaster = null; m_ControlMaster = null;
ControlTarget = null; ControlTarget = null;
m_ControlOrder = OrderType.None; m_ControlOrder = OrderType.None;
@ -2517,7 +2516,7 @@ namespace Server.Mobiles
} }
} }
if (aggressor.ChangingCombatant && (m_Controlled || _summoned) && if (aggressor.ChangingCombatant && (_controlled || _summoned) &&
(ct == OrderType.Come || !Core.ML && ct == OrderType.Stay || ct is OrderType.Stop or OrderType.None or OrderType.Follow)) (ct == OrderType.Come || !Core.ML && ct == OrderType.Stay || ct is OrderType.Stop or OrderType.None or OrderType.Follow))
{ {
ControlTarget = aggressor; ControlTarget = aggressor;
@ -2561,7 +2560,7 @@ namespace Server.Mobiles
AIObject?.GetContextMenuEntries(from, ref list); AIObject?.GetContextMenuEntries(from, ref list);
} }
if (m_bTamable && !m_Controlled && from.Alive) if (m_bTamable && !_controlled && from.Alive)
{ {
list.Add(new TameEntry(from.Female ? AllowFemaleTamer : AllowMaleTamer)); list.Add(new TameEntry(from.Female ? AllowFemaleTamer : AllowMaleTamer));
} }
@ -3748,7 +3747,7 @@ namespace Server.Mobiles
return BardMaster; return BardMaster;
} }
if (m_Controlled && m_ControlMaster != null) if (_controlled && m_ControlMaster != null)
{ {
return m_ControlMaster; return m_ControlMaster;
} }
@ -4117,7 +4116,7 @@ namespace Server.Mobiles
public virtual bool IsFriend(Mobile m) => public virtual bool IsFriend(Mobile m) =>
OppositionGroup?.IsEnemy(this, m) != true && m is BaseCreature c && m_Team == c.m_Team OppositionGroup?.IsEnemy(this, m) != true && m is BaseCreature c && m_Team == c.m_Team
&& (_summoned || m_Controlled) == (c._summoned || c.m_Controlled); && (_summoned || _controlled) == (c._summoned || c._controlled);
public virtual Allegiance GetFactionAllegiance(Mobile mob) public virtual Allegiance GetFactionAllegiance(Mobile mob)
{ {