mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
feat: add attack delay trigger system
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92c35eed65fd4a628f530c9780e710f2
|
||||
timeCreated: 1771682337
|
||||
Reference in New Issue
Block a user