feat: add base attack systems

This commit is contained in:
Bragin Stepan
2026-02-21 18:57:18 +05:00
parent dfd7b5ccf3
commit 0b7c4700fd
14 changed files with 417 additions and 6 deletions

View File

@@ -0,0 +1,22 @@
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utilities.Conditions;
using _Project.Develop.Runtime.Utils.ReactiveManagement;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack
{
public class StartAttackRequest : IEntityComponent { public ReactiveEvent Value; }
public class StartAttackEvent : IEntityComponent { public ReactiveEvent Value; }
public class CanStartAttack : IEntityComponent { public ICompositeCondition Value; }
public class EndAttackEvent : IEntityComponent { public ReactiveEvent Value; }
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; }
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 09e2d7dedb34455a8ca464d3a25e6f38
timeCreated: 1771680515

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: db3e7a5aa2634428a39cefa672bbb597
timeCreated: 1771680531

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5e5cd43b995e43eaaf01eb772ce4e53f
timeCreated: 1771681280

View File

@@ -0,0 +1,44 @@
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 EndAttackSystem : IInitializableSystem, IDisposableSystem
{
private ReactiveEvent _endAttackEvent;
private ReactiveVariable<bool> _inAttackProcess;
private ReactiveVariable<float> _attackProcessInitialTime;
private ReactiveVariable<float> _attackProcessCurrentTime;
private IDisposable _timerDisposable;
public void OnInit(Entity entity)
{
_endAttackEvent = entity.EndAttackEvent;
_inAttackProcess = entity.InAttackProcess;
_attackProcessInitialTime = entity.AttackProcessInitialTime;
_attackProcessCurrentTime = entity.AttackProcessCurrentTime;
_timerDisposable = _attackProcessCurrentTime.Subscribe(OnTimerChanged);
}
private void OnTimerChanged(float arg1, float currentTime)
{
if (TimeIsDone(currentTime))
{
_inAttackProcess.Value = false;
_endAttackEvent.Invoke();
}
}
public void OnDispose()
{
_timerDisposable.Dispose();
}
private bool TimeIsDone(float currentTime) => currentTime >= _attackProcessInitialTime.Value;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 14247d25256641f4bdebce95c190de83
timeCreated: 1771681439

View File

@@ -0,0 +1,43 @@
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.Attack.Systems
{
public class ProcessAttackTimerSystem: IInitializableSystem, IDisposableSystem, IUpdatableSystem
{
private ReactiveVariable<float> _currentTime;
private ReactiveVariable<bool> _inAttackProcess;
private ReactiveEvent _startAttackEvent;
private IDisposable _startAttackEventDisposable;
public void OnInit(Entity entity)
{
_currentTime = entity.AttackProcessCurrentTime;
_inAttackProcess = entity.InAttackProcess;
_startAttackEvent = entity.StartAttackEvent;
_startAttackEventDisposable = _startAttackEvent.Subscribe(OnStartAttackProcess);
}
private void OnStartAttackProcess()
{
_currentTime.Value = 0;
}
public void OnUpdate(float deltaTime)
{
if (_inAttackProcess.Value == false)
return;
_currentTime.Value += deltaTime;
}
public void OnDispose()
{
_startAttackEventDisposable.Dispose();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b3331518167469c8bedadab4206184f
timeCreated: 1771681046

View File

@@ -0,0 +1,43 @@
using System;
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utilities.Conditions;
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 StartAttackSystem : IInitializableSystem, IDisposableSystem
{
private ReactiveEvent _startAttackRequest;
private ReactiveEvent _startAttackEvent;
private ReactiveVariable<bool> _inAttackProcess;
private ICompositeCondition _canStartAttack;
private IDisposable _attackRequestDisposable;
public void OnInit(Entity entity)
{
_startAttackRequest = entity.StartAttackRequest;
_startAttackEvent = entity.StartAttackEvent;
_inAttackProcess = entity.InAttackProcess;
_canStartAttack = entity.CanStartAttack;
_attackRequestDisposable = _startAttackRequest.Subscribe(OnAttackRequest);
}
private void OnAttackRequest()
{
if (_canStartAttack.Evaluate())
{
_inAttackProcess.Value = true;
_startAttackEvent.Invoke();
}
}
public void OnDispose()
{
_attackRequestDisposable.Dispose();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a699afa5a7c24f0c8d16cc6639068255
timeCreated: 1771680808

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 30ae0ba2feaa4da3b5463d2cb8d5bfbe
timeCreated: 1771681294