mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 15:51:10 +00:00
feat: add random auto teleport state
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 399ae3c830b94229a8b94350eca901d2
|
||||
timeCreated: 1772543966
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 203bcf3a28764fb7bfac1482c48bad2f
|
||||
timeCreated: 1772546509
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user