diff --git a/Assets/_Project/Develop/Runtime/Infrastructure/EntryPoint/ProjectContextRegistrations.cs b/Assets/_Project/Develop/Runtime/Infrastructure/EntryPoint/ProjectContextRegistrations.cs index a4fd9bb..f24f1a1 100644 --- a/Assets/_Project/Develop/Runtime/Infrastructure/EntryPoint/ProjectContextRegistrations.cs +++ b/Assets/_Project/Develop/Runtime/Infrastructure/EntryPoint/ProjectContextRegistrations.cs @@ -32,6 +32,7 @@ namespace Assets._Project.Develop.Runtime.Infrastructure.EntryPoint container.RegisterAsSingle(CreateSceneSwitcherService); container.RegisterAsSingle(CreateInputFactory); + container.RegisterAsSingle(CreateInputStateMachine); container.RegisterAsSingle(CreatePlayerInput); container.RegisterAsSingle(CreateUIInput); @@ -65,6 +66,7 @@ namespace Assets._Project.Develop.Runtime.Infrastructure.EntryPoint private static ResourcesAssetsLoader CreateResourcesAssetsLoader(DIContainer c) => new(); private static InputFactory CreateInputFactory(DIContainer c) => new(); + private static InputStateMachine CreateInputStateMachine(DIContainer c) => new(c); private static TimerServiceFactory CreateTimerServiceFactory(DIContainer c) => new (c); diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs index 7c39bba..a289a9e 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs @@ -210,7 +210,7 @@ namespace _Project.Develop.Runtime.Entities .AddMaxHealth(new ReactiveVariable(150)) .AddCurrentHealth(new ReactiveVariable(150)) - .AddTeleportTarget(entity.Transform) + .AddTeleportSource(entity.Transform) .AddTeleportToPoint(entity.Transform) .AddStartTeleportEvent() .AddStartTeleportRequest() @@ -225,6 +225,10 @@ namespace _Project.Develop.Runtime.Entities .AddTeleportEnergyCost(new ReactiveVariable(20)) .AddTeleportSearchRadius(new ReactiveVariable(6)) + + .AddTeleportCooldownInitialTime(new ReactiveVariable(3)) + .AddTeleportCooldownCurrentTime() + .AddInTeleportCooldown() .AddCurrentEnergy(new ReactiveVariable(60)) .AddMaxEnergy(new ReactiveVariable(60)) @@ -253,6 +257,7 @@ namespace _Project.Develop.Runtime.Entities ICompositeCondition canStartTeleport = new CompositeCondition() .Add(new FuncCondition(() => entity.IsDead.Value == false)) + .Add(new FuncCondition(() => entity.InTeleportCooldown.Value == false)) .Add(new FuncCondition(() => entity.CurrentEnergy.Value >= entity.TeleportEnergyCost.Value)); ICompositeCondition mustDie = new CompositeCondition() @@ -286,6 +291,7 @@ namespace _Project.Develop.Runtime.Entities .AddSystem(new FindRandomPointForTeleportSystem()) .AddSystem(new EndTeleportSystem()) .AddSystem(new InstantTeleportSystem()) + .AddSystem(new TeleportCooldownTimerSystem()) .AddSystem(new DealDamageAfterTeleportSystem(_collidersRegistryService)) .AddSystem(new BodyContactsDetectingSystem()) diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs index 11bcd0b..9e19832 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs @@ -78,13 +78,13 @@ namespace _Project.Develop.Runtime.Entities return AddComponent(new Assets._Project.Develop.Runtime.Gameplay.Common.NavMeshAgentComponent() {Value = value}); } - public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportTarget TeleportTargetC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportTarget>(); + public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSource TeleportSourceC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSource>(); - public UnityEngine.Transform TeleportTarget => TeleportTargetC.Value; + public UnityEngine.Transform TeleportSource => TeleportSourceC.Value; - public bool TryGetTeleportTarget(out UnityEngine.Transform value) + public bool TryGetTeleportSource(out UnityEngine.Transform value) { - bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportTarget component); + bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSource component); if(result) value = component.Value; else @@ -92,9 +92,9 @@ namespace _Project.Develop.Runtime.Entities return result; } - public _Project.Develop.Runtime.Entities.Entity AddTeleportTarget(UnityEngine.Transform value) + public _Project.Develop.Runtime.Entities.Entity AddTeleportSource(UnityEngine.Transform value) { - return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportTarget() {Value = value}); + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportSource() {Value = value}); } public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportToPoint TeleportToPointC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportToPoint>(); @@ -327,6 +327,78 @@ namespace _Project.Develop.Runtime.Entities return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportEnergyCost() {Value = value}); } + public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownInitialTime TeleportCooldownInitialTimeC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownInitialTime>(); + + public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable TeleportCooldownInitialTime => TeleportCooldownInitialTimeC.Value; + + public bool TryGetTeleportCooldownInitialTime(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + { + bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownInitialTime component); + if(result) + value = component.Value; + else + value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable); + return result; + } + + public _Project.Develop.Runtime.Entities.Entity AddTeleportCooldownInitialTime() + { + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownInitialTime() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable() }); + } + + public _Project.Develop.Runtime.Entities.Entity AddTeleportCooldownInitialTime(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + { + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownInitialTime() {Value = value}); + } + + public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownCurrentTime TeleportCooldownCurrentTimeC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownCurrentTime>(); + + public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable TeleportCooldownCurrentTime => TeleportCooldownCurrentTimeC.Value; + + public bool TryGetTeleportCooldownCurrentTime(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + { + bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownCurrentTime component); + if(result) + value = component.Value; + else + value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable); + return result; + } + + public _Project.Develop.Runtime.Entities.Entity AddTeleportCooldownCurrentTime() + { + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownCurrentTime() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable() }); + } + + public _Project.Develop.Runtime.Entities.Entity AddTeleportCooldownCurrentTime(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + { + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportCooldownCurrentTime() {Value = value}); + } + + public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportCooldown InTeleportCooldownC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportCooldown>(); + + public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable InTeleportCooldown => InTeleportCooldownC.Value; + + public bool TryGetInTeleportCooldown(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + { + bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportCooldown component); + if(result) + value = component.Value; + else + value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable); + return result; + } + + public _Project.Develop.Runtime.Entities.Entity AddInTeleportCooldown() + { + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportCooldown() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable() }); + } + + public _Project.Develop.Runtime.Entities.Entity AddInTeleportCooldown(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + { + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.InTeleportCooldown() {Value = value}); + } + public _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportDamage TeleportDamageC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Teleport.TeleportDamage>(); public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable TeleportDamage => TeleportDamageC.Value; diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/BrainsFactory.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/BrainsFactory.cs index 8b16b6f..8cd1ec4 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/BrainsFactory.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/BrainsFactory.cs @@ -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(); - _aiBrainsContext = _container.Resolve(); - _timerServiceFactory = _container.Resolve(); - _entitiesLifeContext = _container.Resolve(); + _playerInput = container.Resolve(); + _aiBrainsContext = container.Resolve(); + _timerServiceFactory = container.Resolve(); + _entitiesLifeContext = container.Resolve(); } 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; + } } } \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/AttackTriggerState.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/AttackTriggerState.cs index 0089f54..b93b19c 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/AttackTriggerState.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/AttackTriggerState.cs @@ -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) diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/TeleportTriggerState.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/TeleportTriggerState.cs new file mode 100644 index 0000000..759f290 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/TeleportTriggerState.cs @@ -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) + { } + } +} \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/TeleportTriggerState.cs.meta b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/TeleportTriggerState.cs.meta new file mode 100644 index 0000000..f4a2e23 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/AI/States/TeleportTriggerState.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 399ae3c830b94229a8b94350eca901d2 +timeCreated: 1772543966 \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/FindRandomPointForTeleportSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/FindRandomPointForTeleportSystem.cs index 6b83542..850445d 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/FindRandomPointForTeleportSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/FindRandomPointForTeleportSystem.cs @@ -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(); } diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/InstantTeleportSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/InstantTeleportSystem.cs index 5235145..1dc4cdf 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/InstantTeleportSystem.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/InstantTeleportSystem.cs @@ -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; diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportCooldownTimerSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportCooldownTimerSystem.cs new file mode 100644 index 0000000..815d9f4 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportCooldownTimerSystem.cs @@ -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 _currentTime; + private ReactiveVariable _initialTime; + private ReactiveVariable _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(); + } + } +} \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportCooldownTimerSystem.cs.meta b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportCooldownTimerSystem.cs.meta new file mode 100644 index 0000000..aeb136b --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/Systems/TeleportCooldownTimerSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 203bcf3a28764fb7bfac1482c48bad2f +timeCreated: 1772546509 \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/TeleportComponents.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/TeleportComponents.cs index 1a33f2b..6a75a5d 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/TeleportComponents.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Teleport/TeleportComponents.cs @@ -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 Value; } @@ -23,6 +23,10 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Teleport public class TeleportEnergyCost : IEntityComponent { public ReactiveVariable Value; } + public class TeleportCooldownInitialTime : IEntityComponent { public ReactiveVariable Value; } + public class TeleportCooldownCurrentTime : IEntityComponent { public ReactiveVariable Value; } + public class InTeleportCooldown : IEntityComponent { public ReactiveVariable Value; } + public class TeleportDamage : IEntityComponent { public ReactiveVariable Value; } public class TeleportDamageRadius : IEntityComponent { public ReactiveVariable Value; } public class TeleportDamageMask : IEntityComponent { public LayerMask Value; } diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Infrastructure/TestGameplay.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Infrastructure/TestGameplay.cs index 1a614c4..18a58ad 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Infrastructure/TestGameplay.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Infrastructure/TestGameplay.cs @@ -15,7 +15,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features private BrainsFactory _brainsFactory; private Entity _hero; - private Entity _ghost; + private Entity _enemy; private bool _isRunning; @@ -34,8 +34,8 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features _hero.AddCurrentTarget(); _brainsFactory.CreateMainHeroBrain(_hero, new NearestDamageableTargetSelector(_hero)); - _ghost = _entitiesFactory.CreateGhost(Vector3.zero + Vector3.forward * 5); - _brainsFactory.CreateGhostBrain(_ghost); + _enemy = _entitiesFactory.CreateTeleportWizard(Vector3.zero + Vector3.forward * 5); + _brainsFactory.CreateWizardBrain(_enemy); _isRunning = true; } @@ -48,11 +48,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features private void OnGUI() { - if (_hero == null) + if (_hero == null || _enemy == null) return; GUI.Label(new Rect(10, 20, 200, 50), $"Health: {_hero.CurrentHealth.Value}/{_hero.MaxHealth.Value}"); - // GUI.Label(new Rect(10, 40, 200, 50), $"Energy: {_hero.CurrentEnergy.Value}/{_hero.MaxEnergy.Value}"); + GUI.Label(new Rect(10, 40, 200, 50), $"Energy: {_enemy.CurrentEnergy.Value}/{_enemy.MaxEnergy.Value}"); } } } \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Utilities/InputManagement/InputStateMachine.cs b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/InputStateMachine.cs new file mode 100644 index 0000000..490a719 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/InputStateMachine.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using _Project.Develop.Runtime.Utilities.Conditions; +using _Project.Develop.Runtime.Utils.InputManagement.States; +using Assets._Project.Develop.Runtime.Infrastructure.DI; +using Assets._Project.Develop.Runtime.Utilities.StateMachineCore; + +namespace _Project.Develop.Runtime.Utils.InputManagement +{ + public class InputStateMachine : StateMachine, IInitializable, IDisposable + { + private readonly IPlayerInput _playerInput; + private readonly IUIInput _uiInput; + + public InputStateMachine(List disposables) : base(disposables) + { } + + public InputStateMachine(DIContainer container) : base(new List()) + { + _playerInput = container.Resolve(); + _uiInput = container.Resolve(); + } + + public void Initialize() + { + PlayerInputState playerInputState = new(_playerInput); + UIInputState uiInputState = new(_uiInput); + + ICompositeCondition playerToUiStateCondition = new CompositeCondition(LogicOperationsUtils.Or) + .Add(new FuncCondition(() => _uiInput.IsEnabled)); + // .Add(new FuncCondition(() => _playerHorseInput.IsEnabled)); + + ICompositeCondition uiToPlayerStateCondition = new CompositeCondition(LogicOperationsUtils.Or) + .Add(new FuncCondition(() => _playerInput.IsEnabled)); + // .Add(new FuncCondition(() => _playerHorseInput.IsEnabled)); + + AddState(playerInputState); + AddState(uiInputState); + + AddTransition(playerInputState, uiInputState, playerToUiStateCondition); + AddTransition(uiInputState, playerInputState, uiToPlayerStateCondition); + + Enter(); + } + + public void Dispose() + { + Exit(); + } + } +} \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Utilities/InputManagement/InputStateMachine.cs.meta b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/InputStateMachine.cs.meta new file mode 100644 index 0000000..e40e417 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/InputStateMachine.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b1a3543621b74566aa3f737018932731 +timeCreated: 1772547242 \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States.meta b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States.meta new file mode 100644 index 0000000..6ab172d --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 60ce6781167b4204a72055d939441a5b +timeCreated: 1772547589 \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/PlayerInputState.cs b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/PlayerInputState.cs new file mode 100644 index 0000000..78abe7b --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/PlayerInputState.cs @@ -0,0 +1,26 @@ +using Assets._Project.Develop.Runtime.Utilities.StateMachineCore; + +namespace _Project.Develop.Runtime.Utils.InputManagement.States +{ + public class PlayerInputState : State + { + private readonly IPlayerInput _playerInput; + + public PlayerInputState(IPlayerInput playerInput) + { + _playerInput = playerInput; + } + + public override void Enter() + { + base.Enter(); + _playerInput.Enable(); + } + + public override void Exit() + { + _playerInput.Disable(); + base.Exit(); + } + } +} \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/PlayerInputState.cs.meta b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/PlayerInputState.cs.meta new file mode 100644 index 0000000..9064001 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/PlayerInputState.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0efa0cca886c45e295d4adcb82d59f8b +timeCreated: 1770556305 \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/UIInputState.cs b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/UIInputState.cs new file mode 100644 index 0000000..aa32025 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/UIInputState.cs @@ -0,0 +1,26 @@ +using Assets._Project.Develop.Runtime.Utilities.StateMachineCore; + +namespace _Project.Develop.Runtime.Utils.InputManagement.States +{ + public class UIInputState : State + { + private readonly IUIInput _uiInput; + + public UIInputState(IUIInput uiInput) + { + _uiInput = uiInput; + } + + public override void Enter() + { + base.Enter(); + _uiInput.Enable(); + } + + public override void Exit() + { + _uiInput.Disable(); + base.Exit(); + } + } +} \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/UIInputState.cs.meta b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/UIInputState.cs.meta new file mode 100644 index 0000000..7264232 --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Utilities/InputManagement/States/UIInputState.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2cac35b3aedd43b1959f82e36c30ac47 +timeCreated: 1770556297 \ No newline at end of file