Aetheria/Assets/Scripts/ServerShared/Agents/Tasks/PatrolOrbits.cs
Meta Vens c8c544f489 PatrolOrbitsState: compare the task by reference
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-08 14:35:00 +02:00

33 lines
No EOL
1 KiB
C#

using GameCult.Caching;
using System;
public class PatrolOrbitsTask : AgentTask
{
public override TaskType Type => TaskType.Defend;
public CultRecordKey[] Circuit;
}
public class PatrolOrbitsState : BaseState
{
public PatrolOrbitsTask Task;
public CultRecordKey CurrentTarget
{
get => Task.Circuit[_currentTargetIndex];
}
private int _currentTargetIndex;
public void NextTarget()
{
_currentTargetIndex++;
_currentTargetIndex %= Task.Circuit.Length;
}
public PatrolOrbitsState(Agent agent) : base(agent)
{
var patrolMoveState = new MoveToOrbitState(agent);
Transitions.Add(new StateTransition(patrolMoveState,
() => true,
() => patrolMoveState.Orbit = CurrentTarget));
// Arrival advances the circuit only while the pilot is still on this task: a task change leaves the patrol first.
patrolMoveState.Transitions.Add(new StateTransition(this, () => patrolMoveState.Distance < 10 && ReferenceEquals(agent.Task, Task), NextTarget));
}
}