fix: Fixes pet guard order (#2287)
This commit is contained in:
parent
771cb50919
commit
0d25f83de5
1 changed files with 47 additions and 10 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue