Skip to content

Commit

Permalink
fix: Attempts to fix IsEnemy with NPC summons again again.
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Jan 4, 2025
1 parent 5d53825 commit e916269
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public override void Trigger(MonsterAbilityTrigger trigger, BaseCreature source,
summon.Combatant = target;
summon.Home = source.Home;
summon.RangeHome = source.RangeHome;
summon.ControlOrder = OrderType.Guard;
}

summon.MoveToWorld(loc, source.Map);
Expand Down
40 changes: 18 additions & 22 deletions Projects/UOContent/Mobiles/BaseCreature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public enum TeachResult
private bool m_bTamable;
private int m_ColdResistance;

private bool m_Controlled; // Is controlled
private bool _controlled; // Is controlled
private Mobile m_ControlMaster; // My master
private OrderType m_ControlOrder; // My order

Expand Down Expand Up @@ -370,7 +370,7 @@ public BaseCreature(

Debug = false;

m_Controlled = false;
_controlled = false;
m_ControlMaster = null;
ControlTarget = null;
m_ControlOrder = OrderType.None;
Expand Down Expand Up @@ -749,15 +749,15 @@ public Point3D Home
[CommandProperty(AccessLevel.GameMaster)]
public bool Controlled
{
get => m_Controlled;
get => _controlled;
set
{
if (m_Controlled == value)
if (_controlled == value)
{
return;
}

m_Controlled = value;
_controlled = value;
Delta(MobileDelta.Noto);

InvalidateProperties();
Expand Down Expand Up @@ -1353,24 +1353,20 @@ public virtual bool IsEnemy(Mobile m)
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;
}

if (m_Team != c.Team)
{
return true;
}
var master = GetMaster() as BaseCreature;
var cMaster = c.GetMaster() as BaseCreature;

var targetControlled = c._summoned || c.m_Controlled;

if (_summoned || m_Controlled)
if (master == null && cMaster == null)
{
return targetControlled || c.IsEnemy(GetMaster());
return false;
}

return targetControlled && IsEnemy(c.GetMaster());
return master?.IsEnemy(cMaster ?? c) ?? cMaster.IsEnemy(this);
}

public override string ApplyNameSuffix(string suffix)
Expand Down Expand Up @@ -1871,7 +1867,7 @@ public override void Serialize(IGenericWriter writer)
// Version 2
writer.Write((int)FightMode);

writer.Write(m_Controlled);
writer.Write(_controlled);
writer.Write(m_ControlMaster);
writer.Write(ControlTarget);
writer.Write(ControlDest);
Expand Down Expand Up @@ -2021,7 +2017,7 @@ public override void Deserialize(IGenericReader reader)
{
FightMode = (FightMode)reader.ReadInt();

m_Controlled = reader.ReadBool();
_controlled = reader.ReadBool();
m_ControlMaster = reader.ReadEntity<Mobile>();
ControlTarget = reader.ReadEntity<Mobile>();
ControlDest = reader.ReadPoint3D();
Expand Down Expand Up @@ -2049,7 +2045,7 @@ public override void Deserialize(IGenericReader reader)
{
FightMode = FightMode.Closest;

m_Controlled = false;
_controlled = false;
m_ControlMaster = null;
ControlTarget = null;
m_ControlOrder = OrderType.None;
Expand Down Expand Up @@ -2517,7 +2513,7 @@ public override void AggressiveAction(Mobile aggressor, bool criminal)
}
}

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))
{
ControlTarget = aggressor;
Expand Down Expand Up @@ -2561,7 +2557,7 @@ public override void GetContextMenuEntries(Mobile from, ref PooledRefList<Contex
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));
}
Expand Down Expand Up @@ -3748,7 +3744,7 @@ public override Mobile GetDamageMaster(Mobile damagee)
return BardMaster;
}

if (m_Controlled && m_ControlMaster != null)
if (_controlled && m_ControlMaster != null)
{
return m_ControlMaster;
}
Expand Down Expand Up @@ -4117,7 +4113,7 @@ public virtual void AddPetFriend(Mobile m)

public virtual bool IsFriend(Mobile m) =>
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)
{
Expand Down

0 comments on commit e916269

Please sign in to comment.