fix: Fixes pet guard order (#2287)

This commit is contained in:
Bohica 2025-12-06 16:18:26 -08:00 committed by GitHub
parent 771cb50919
commit 0d25f83de5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -266,6 +266,8 @@ public abstract partial class BaseAI
return true;
}
Action = ActionType.Guard;
FindCombatant();
if (IsValidCombatant(Mobile.Combatant))
@ -324,7 +326,8 @@ public abstract partial class BaseAI
return true;
}
private bool IsInvalidControlTarget(Mobile target) => target?.Deleted != false || target.Map != Mobile.Map || !target.Alive || target.IsDeadBondedPet;
private bool IsInvalidControlTarget(Mobile target) => target?.Deleted != false || target.Map != Mobile.Map
|| !target.Alive || target.IsDeadBondedPet;
private void HandleInvalidControlTarget()
{
@ -340,23 +343,57 @@ public abstract partial class BaseAI
private void FindCombatant()
{
var controlMaster = Mobile.ControlMaster;
foreach (var aggr in Mobile.GetMobilesInRange(Mobile.RangePerception))
{
if (!Mobile.CanSee(aggr) || aggr.Combatant != Mobile || aggr.IsDeadBondedPet || !aggr.Alive)
if (!Mobile.CanSee(aggr) || aggr.IsDeadBondedPet || !aggr.Alive)
{
continue;
}
if (Mobile.InLOS(aggr))
bool isAttackingPet = aggr.Combatant == Mobile;
bool isAttackingMaster = controlMaster != null && aggr.Combatant == controlMaster;
if (isAttackingPet || isAttackingMaster)
{
Mobile.ControlTarget = aggr;
Mobile.ControlOrder = OrderType.Attack;
Mobile.Combatant = aggr;
if (Mobile.InLOS(aggr))
{
Mobile.ControlTarget = aggr;
Mobile.ControlOrder = OrderType.Attack;
Mobile.Combatant = aggr;
this.DebugSayFormatted($"{aggr.Name} is still alive. Resuming attacks...");
var target = isAttackingMaster ? "master" : "me";
this.DebugSayFormatted($"{aggr.Name} is attacking my {target}! Engaging...");
Think();
break;
Think();
return;
}
}
}
if (controlMaster?.Aggressors != null)
{
for (var i = 0; i < controlMaster.Aggressors.Count; i++)
{
var aggressor = controlMaster.Aggressors[i].Attacker;
if (aggressor?.Deleted != false || !aggressor.Alive || aggressor.IsDeadBondedPet)
{
continue;
}
if (Mobile.InRange(aggressor, Mobile.RangePerception) && Mobile.CanSee(aggressor) && Mobile.InLOS(aggressor))
{
Mobile.ControlTarget = aggressor;
Mobile.ControlOrder = OrderType.Attack;
Mobile.Combatant = aggressor;
this.DebugSayFormatted($"{aggressor.Name} recently attacked my master! Retaliating...");
Think();
return;
}
}
}
}
@ -515,4 +552,4 @@ public abstract partial class BaseAI
from.SendLocalizedMessage(fromMessage, args);
to.SendLocalizedMessage(toMessage, args);
}
}
}