From 2affd039934de94c641f85cbf071ee673ce905b2 Mon Sep 17 00:00:00 2001 From: Bragin Stepan Date: Sat, 21 Feb 2026 19:05:44 +0500 Subject: [PATCH] feat: add attack delay trigger system --- .../Gameplay/Entities/EntitiesFactory.cs | 5 +- .../Gameplay/Entities/Generated/EntityAPI.cs | 48 ++++++++-------- .../Features/Attack/AttackComponents.cs | 6 +- .../Base/AttackDelayEndTriggerSystem.cs | 56 +++++++++++++++++++ .../Base/AttackDelayEndTriggerSystem.cs.meta | 3 + 5 files changed, 90 insertions(+), 28 deletions(-) create mode 100644 Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/AttackDelayEndTriggerSystem.cs create mode 100644 Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/AttackDelayEndTriggerSystem.cs.meta diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs index 30ba371..7bdfc9a 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/EntitiesFactory.cs @@ -53,7 +53,9 @@ namespace _Project.Develop.Runtime.Entities .AddInAttackProcess() .AddStartAttackRequest() .AddStartAttackEvent() - .AddEndAttackEvent(); + .AddEndAttackEvent() + .AddAttackDelayTime(new ReactiveVariable(2)) + .AddAttackDelayEndEvent(); ICompositeCondition canMove = new CompositeCondition() .Add(new FuncCondition(() => entity.IsDead.Value == false)); @@ -92,6 +94,7 @@ namespace _Project.Develop.Runtime.Entities .AddSystem(new StartAttackSystem()) .AddSystem(new ProcessAttackTimerSystem()) + .AddSystem(new AttackDelayEndTriggerSystem()) .AddSystem(new EndAttackSystem()) .AddSystem(new ApplyDamageSystem()) 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 455af4a..1318067 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Entities/Generated/EntityAPI.cs @@ -858,6 +858,30 @@ namespace _Project.Develop.Runtime.Entities return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessCurrentTime() {Value = value}); } + public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess InAttackProcessC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess>(); + + public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable InAttackProcess => InAttackProcessC.Value; + + public bool TryGetInAttackProcess(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + { + bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess component); + if(result) + value = component.Value; + else + value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable); + return result; + } + + public _Project.Develop.Runtime.Entities.Entity AddInAttackProcess() + { + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable() }); + } + + public _Project.Develop.Runtime.Entities.Entity AddInAttackProcess(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) + { + return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess() {Value = value}); + } + public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayTime AttackDelayTimeC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayTime>(); public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable AttackDelayTime => AttackDelayTimeC.Value; @@ -906,29 +930,5 @@ namespace _Project.Develop.Runtime.Entities return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayEndEvent() {Value = value}); } - public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess InAttackProcessC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess>(); - - public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable InAttackProcess => InAttackProcessC.Value; - - public bool TryGetInAttackProcess(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) - { - bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess component); - if(result) - value = component.Value; - else - value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable); - return result; - } - - public _Project.Develop.Runtime.Entities.Entity AddInAttackProcess() - { - return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable() }); - } - - public _Project.Develop.Runtime.Entities.Entity AddInAttackProcess(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable value) - { - return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess() {Value = value}); - } - } } diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/AttackComponents.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/AttackComponents.cs index 4cb43a1..7602176 100644 --- a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/AttackComponents.cs +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/AttackComponents.cs @@ -14,9 +14,9 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack public class AttackProcessInitialTime : IEntityComponent { public ReactiveVariable Value; } public class AttackProcessCurrentTime : IEntityComponent { public ReactiveVariable Value; } - - public class AttackDelayTime : IEntityComponent { public ReactiveVariable Value; } - public class AttackDelayEndEvent : IEntityComponent { public ReactiveEvent Value; } public class InAttackProcess : IEntityComponent { public ReactiveVariable Value; } + + public class AttackDelayTime : IEntityComponent { public ReactiveVariable Value; } + public class AttackDelayEndEvent : IEntityComponent { public ReactiveEvent Value; } } \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/AttackDelayEndTriggerSystem.cs b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/AttackDelayEndTriggerSystem.cs new file mode 100644 index 0000000..cee042a --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/AttackDelayEndTriggerSystem.cs @@ -0,0 +1,56 @@ +using System; +using _Project.Develop.Runtime.Entities; +using _Project.Develop.Runtime.Utils.ReactiveManagement; +using _Project.Develop.Runtime.Utils.ReactiveManagement.Event; +using UnityEngine; + +namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems +{ + public class AttackDelayEndTriggerSystem: IInitializableSystem, IDisposableSystem + { + private ReactiveEvent _attackDelayEndEvent; + private ReactiveVariable _delay; + private ReactiveVariable _attackProcessCurrentTime; + + private ReactiveEvent _startAttackEvent; + + private bool _alreadyAttacked; + + private IDisposable _timerDisposable; + private IDisposable _startAttackDisposable; + + public void OnInit(Entity entity) + { + _attackDelayEndEvent = entity.AttackDelayEndEvent; + _delay = entity.AttackDelayTime; + _attackProcessCurrentTime = entity.AttackProcessCurrentTime; + _startAttackEvent = entity.StartAttackEvent; + + _timerDisposable = _attackProcessCurrentTime.Subscribe(OnTimerChanged); + _startAttackDisposable = _startAttackEvent.Subscribe(OnStartAttack); + } + + private void OnStartAttack() + { + _alreadyAttacked = false; + } + + private void OnTimerChanged(float arg1, float currentTime) + { + if (_alreadyAttacked) + return; + + if(currentTime >= _delay.Value) + { + _attackDelayEndEvent.Invoke(); + _alreadyAttacked = true; + } + } + + public void OnDispose() + { + _timerDisposable.Dispose(); + _startAttackDisposable.Dispose(); + } + } +} \ No newline at end of file diff --git a/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/AttackDelayEndTriggerSystem.cs.meta b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/AttackDelayEndTriggerSystem.cs.meta new file mode 100644 index 0000000..51c223f --- /dev/null +++ b/Assets/_Project/Develop/Runtime/Logic/Gameplay/Features/Attack/Systems/Base/AttackDelayEndTriggerSystem.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 92c35eed65fd4a628f530c9780e710f2 +timeCreated: 1771682337 \ No newline at end of file