feat: add attack delay trigger system

This commit is contained in:
Bragin Stepan
2026-02-21 19:05:44 +05:00
parent 0b7c4700fd
commit 2affd03993
5 changed files with 90 additions and 28 deletions

View File

@@ -14,9 +14,9 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack
public class AttackProcessInitialTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class AttackProcessCurrentTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class AttackDelayTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class AttackDelayEndEvent : IEntityComponent { public ReactiveEvent Value; }
public class InAttackProcess : IEntityComponent { public ReactiveVariable<bool> Value; }
public class AttackDelayTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class AttackDelayEndEvent : IEntityComponent { public ReactiveEvent Value; }
}

View File

@@ -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<float> _delay;
private ReactiveVariable<float> _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();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 92c35eed65fd4a628f530c9780e710f2
timeCreated: 1771682337