Skip to content

Commit

Permalink
feat: Implement mobile leash behavior for AI to return home when out …
Browse files Browse the repository at this point in the history
…of range, Restore health to full
  • Loading branch information
Bohicatv committed Jan 25, 2025
1 parent a950073 commit cb14ff8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Projects/UOContent/Mobiles/AI/BaseAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,11 @@ public virtual bool Think()
return false;
}

if (CheckLeashed())
{
return true;
}

if (CheckFlee())
{
return true;
Expand Down Expand Up @@ -3449,4 +3454,39 @@ protected override void OnTick()
}
}
}

public virtual bool CheckLeashed()
{
if (m_Mobile.Deleted || !m_Mobile.Alive || m_Mobile.Controlled)
{
return false;
}

if (m_Mobile.GetDistanceToSqrt(m_Mobile.Home) > 16)
{
if (m_Mobile.Debug)
{
m_Mobile.DebugSay("I am too far from home! Returning home...");
}

m_Mobile.Combatant = null;
m_Mobile.FocusMob = null;
m_Mobile.Warmode = false;

if (m_Mobile.Hits < m_Mobile.HitsMax)
{
m_Mobile.Hits = m_Mobile.HitsMax;

if (m_Mobile.Debug)
{
m_Mobile.DebugSay("My health has been restored!");
}
}

WalkRandomInHome(3, 2, 1);
return true;
}

return false;
}
}

0 comments on commit cb14ff8

Please sign in to comment.