feat: add random auto teleport state

This commit is contained in:
Bragin Stepan
2026-03-03 19:28:16 +05:00
parent c04b0a259a
commit 11e28b1e09
20 changed files with 350 additions and 28 deletions

View File

@@ -13,8 +13,6 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI
{
public class BrainsFactory
{
private readonly DIContainer _container;
private readonly EntitiesLifeContext _entitiesLifeContext;
private readonly AIBrainsContext _aiBrainsContext;
private readonly TimerServiceFactory _timerServiceFactory;
@@ -22,12 +20,10 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI
public BrainsFactory(DIContainer container)
{
_container = container;
_playerInput = _container.Resolve<IPlayerInput>();
_aiBrainsContext = _container.Resolve<AIBrainsContext>();
_timerServiceFactory = _container.Resolve<TimerServiceFactory>();
_entitiesLifeContext = _container.Resolve<EntitiesLifeContext>();
_playerInput = container.Resolve<IPlayerInput>();
_aiBrainsContext = container.Resolve<AIBrainsContext>();
_timerServiceFactory = container.Resolve<TimerServiceFactory>();
_entitiesLifeContext = container.Resolve<EntitiesLifeContext>();
}
public StateMachineBrain CreateGhostBrain(Entity entity)
@@ -39,7 +35,22 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI
return brain;
}
public StateMachineBrain CreateWizardBrain(Entity entity)
{
AIStateMachine stateMachine = CreateRandomTeleportStateMachine(entity);
StateMachineBrain brain = new (stateMachine);
_aiBrainsContext.SetFor(entity, brain);
return brain;
}
public StateMachineBrain CreateDangerWizardBrain(Entity entity)
{
return null;
}
public StateMachineBrain CreateMainHeroBrain(Entity entity, ITargetSelector targetSelector)
{
AIStateMachine combatState = CreateAutoAttackStateMachine(entity);
@@ -146,5 +157,34 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI
return stateMachine;
}
private AIStateMachine CreateRandomTeleportStateMachine(Entity entity)
{
TeleportTriggerState teleportTriggerState = new (entity);
EmptyState emptyState = new ();
ICompositeCondition fromIdleToTeleportCondition = new CompositeCondition()
.Add(entity.CanStartTeleport);
ICompositeCondition fromTeleportToIdleCondition = new CompositeCondition()
.Add(new FuncCondition(() => entity.InTeleportProcess.Value == false));
AIStateMachine stateMachine = new ();
stateMachine.AddState(teleportTriggerState);
stateMachine.AddState(emptyState);
stateMachine.AddTransition(emptyState, teleportTriggerState, fromIdleToTeleportCondition);
stateMachine.AddTransition(teleportTriggerState, emptyState, fromTeleportToIdleCondition);
return stateMachine;
}
private AIStateMachine CreateToTargetTeleportStateMachine(Entity entity)
{
TeleportTriggerState teleportTriggerState = new (entity);
return null;
}
}
}

View File

@@ -6,17 +6,17 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI.States
{
public class AttackTriggerState : State, IUpdatableState
{
private ReactiveEvent _attackRequest;
private ReactiveEvent _request;
public AttackTriggerState(Entity entity)
{
_attackRequest = entity.StartAttackRequest;
_request = entity.StartAttackRequest;
}
public override void Enter()
{
base.Enter();
_attackRequest.Invoke();
_request.Invoke();
}
public void Update(float deltaTime)

View File

@@ -0,0 +1,25 @@
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
using Assets._Project.Develop.Runtime.Utilities.StateMachineCore;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.AI.States
{
public class TeleportTriggerState : State, IUpdatableState
{
private ReactiveEvent _request;
public TeleportTriggerState(Entity entity)
{
_request = entity.StartTeleportRequest;
}
public override void Enter()
{
base.Enter();
_request.Invoke();
}
public void Update(float deltaTime)
{ }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 399ae3c830b94229a8b94350eca901d2
timeCreated: 1772543966

View File

@@ -9,7 +9,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
{
public class FindRandomPointForTeleportSystem : IInitializableSystem, IDisposableSystem
{
private Transform _target;
private Transform _source;
private Transform _toPoint;
private ReactiveEvent _findPointRequest;
@@ -21,7 +21,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
public void OnInit(Entity entity)
{
_target = entity.TeleportTarget;
_source = entity.TeleportSource;
_toPoint = entity.TeleportToPoint;
_radius = entity.TeleportSearchRadius;
_findPointRequest = entity.FindTeleportPointRequest;
@@ -37,7 +37,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
private void OnFindPointRequest()
{
_toPoint.position = GetRandomPointInRadius(_target.position, _radius.Value);
_toPoint.position = GetRandomPointInRadius(_source.position, _radius.Value);
_findPointEvent.Invoke();
}

View File

@@ -16,7 +16,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
public void OnInit(Entity entity)
{
_target = entity.TeleportTarget;
_target = entity.TeleportSource;
_toPoint = entity.TeleportToPoint;
_endTeleportEvent = entity.EndTeleportEvent;

View File

@@ -0,0 +1,52 @@
using System;
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utils.ReactiveManagement;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.Systems
{
public class TeleportCooldownTimerSystem : IInitializableSystem, IUpdatableSystem, IDisposableSystem
{
private ReactiveVariable<float> _currentTime;
private ReactiveVariable<float> _initialTime;
private ReactiveVariable<bool> _inTeleportCooldown;
private ReactiveEvent _endTeleportEvent;
private IDisposable _endTeleportEventDisposable;
public void OnInit(Entity entity)
{
_currentTime = entity.TeleportCooldownCurrentTime;
_initialTime = entity.TeleportCooldownInitialTime;
_inTeleportCooldown = entity.InTeleportCooldown;
_endTeleportEvent = entity.EndTeleportEvent;
_endTeleportEventDisposable = _endTeleportEvent.Subscribe(OnEndTeleport);
}
private void OnEndTeleport()
{
_currentTime.Value = _initialTime.Value;
_inTeleportCooldown.Value = true;
}
public void OnUpdate(float deltaTime)
{
if (_inTeleportCooldown.Value == false)
return;
_currentTime.Value -= deltaTime;
if (CooldownIsOver())
_inTeleportCooldown.Value = false;
}
private bool CooldownIsOver() => _currentTime.Value <= 0;
public void OnDispose()
{
_endTeleportEventDisposable.Dispose();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 203bcf3a28764fb7bfac1482c48bad2f
timeCreated: 1772546509

View File

@@ -6,7 +6,7 @@ using UnityEngine;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport
{
public class TeleportTarget : IEntityComponent { public Transform Value; }
public class TeleportSource : IEntityComponent { public Transform Value; }
public class TeleportToPoint : IEntityComponent { public Transform Value; }
public class TeleportSearchRadius : IEntityComponent { public ReactiveVariable<float> Value; }
@@ -23,6 +23,10 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport
public class TeleportEnergyCost : IEntityComponent { public ReactiveVariable<int> Value; }
public class TeleportCooldownInitialTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class TeleportCooldownCurrentTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class InTeleportCooldown : IEntityComponent { public ReactiveVariable<bool> Value; }
public class TeleportDamage : IEntityComponent { public ReactiveVariable<float> Value; }
public class TeleportDamageRadius : IEntityComponent { public ReactiveVariable<float> Value; }
public class TeleportDamageMask : IEntityComponent { public LayerMask Value; }