Advertisement
Pro_Unit

Neutral

Oct 3rd, 2022
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1.     public class Neutral : AnimalAIBehaviour
  2.     {
  3.         private readonly Infrastructure _infrastructure;
  4.         private readonly TriggersContainer _triggersContainer;
  5.  
  6.         private readonly IState _idle;
  7.         private readonly IState _patrol;
  8.         private readonly IState _chase;
  9.         private readonly IState _attack;
  10.  
  11.         public Neutral(StateFactory factory, IStateMachineOwner stateMachineOwner,
  12.             TargetProviderContainer targetProviderContainer, AnimalReferences references,
  13.             AnimalInfrastructure animalInfrastructure, Infrastructure infrastructure,
  14.             TriggersContainer triggersContainer) :
  15.             base
  16.             (
  17.                 new StateMachine(owner: stateMachineOwner, debug: animalInfrastructure.Debug.Neutral),
  18.                 references,
  19.                 targetProviderContainer
  20.             )
  21.         {
  22.             _infrastructure = infrastructure;
  23.             _triggersContainer = triggersContainer;
  24.             _idle = factory.Create(typeof(Idle));
  25.             _patrol = factory.Create(typeof(Patrol));
  26.             _chase = factory.Create(typeof(Chase));
  27.             _attack = factory.Create(typeof(Attack));
  28.         }
  29.  
  30.         protected override IState StartState => _idle;
  31.  
  32.         protected override void ConfigTransitions(StateMachine stateMachine)
  33.         {
  34.             stateMachine.AddTransition(_idle, _patrol, _triggersContainer.Get(Triggers.WaitEnded));
  35.             stateMachine.AddTransition(_idle, _chase, _triggersContainer.Get(Triggers.Damaged));
  36.             stateMachine.AddTransition(_patrol, _chase, _triggersContainer.Get(Triggers.Damaged));
  37.             stateMachine.AddTransition(_patrol, _idle, _triggersContainer.Get(Triggers.DestinationReached));
  38.             stateMachine.AddTransition(_chase, _attack, _triggersContainer.Get(Triggers.TargetArrived));
  39.             stateMachine.AddTransition(_chase, _idle, _triggersContainer.Get(Triggers.TargetLost));
  40.             stateMachine.AddTransition(_attack, _chase, _triggersContainer.Get(Triggers.TargetIsFled));
  41.             stateMachine.AddTransition(_attack, _idle, _triggersContainer.Get(Triggers.TargetDead));
  42.         }
  43.  
  44.         private Triggers Triggers => _infrastructure.Triggers;
  45.     }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement