Make followers get closer to the leader if too far away, even when fighting

Issue #10418 open
gewd created an issue

Add this XRL.World.AI.GoalHandlers.Kill right below this if block: if (this.ParentBrain.IsPlayerLed() && this.Target.IsPlayerLed()).

if(this.ParentBrain.IsPlayerLed())
{
    var leaderCell = this.ParentBrain.PartyLeader.CurrentCell;
    int distance = base.ParentObject.DistanceTo(leaderCell);
    int followDistance = GetPartyLeaderFollowDistanceEvent.GetFor(base.ParentObject, this.ParentBrain.PartyLeader);

    if(distance > followDistance + 2)
    {
        FindPath findPath = new FindPath(base.ParentObject.CurrentCell, leaderCell, PathGlobal: false, PathUnlimited: true, base.ParentObject, 95);
        if(findPath.Usable)
        {
            base.Think("Too far from leader");

            for(int i=0;i<findPath.Steps.Count - distance;i++)
            {
                this.PushChildGoal(new Step(findPath.Directions[i]));
            }
            return;
        }
    }
}

Comments (3)

  1. Log in to comment