feat: add shoot and cooldown systems

This commit is contained in:
Bragin Stepan
2026-02-21 23:53:45 +05:00
parent 2affd03993
commit af20400b84
25 changed files with 1174 additions and 233 deletions

View File

@@ -2,21 +2,30 @@
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
{
public class StartAttackRequest : IEntityComponent { public ReactiveEvent Value; }
public class StartAttackEvent : IEntityComponent { public ReactiveEvent Value; }
public class InstantAttackDamage : IEntityComponent { public ReactiveVariable<float> Value; }
public class ShootPoint : IEntityComponent { public Transform Value; }
public class CanStartAttack : IEntityComponent { public ICompositeCondition Value; }
public class StartAttackRequest : IEntityComponent { public ReactiveEvent Value; }
public class StartAttackEvent : IEntityComponent { public ReactiveEvent 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 InAttackProcess : IEntityComponent { public ReactiveVariable<bool> Value; }
public class AttackDelayTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class AttackDelayEndEvent : IEntityComponent { public ReactiveEvent Value; }
public class MustCancelAttack : IEntityComponent { public ICompositeCondition Value; }
public class AttackCanceledEvent : IEntityComponent { public ReactiveEvent Value; }
public class AttackCooldownInitialTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class AttackCooldownCurrentTime : IEntityComponent { public ReactiveVariable<float> Value; }
public class InAttackCooldown : IEntityComponent { public ReactiveVariable<bool> Value; }
}

View File

@@ -0,0 +1,15 @@
using _Project.Develop.Runtime.Entities;
using UnityEngine;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack
{
public class ShootPointEntityRegistrator : MonoEntityRegistrator
{
[SerializeField] private Transform _shootPoint;
public override void Register(Entity entity)
{
entity.AddShootPoint(_shootPoint);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1675979b03c84ec3b990009a37f3d6d9
timeCreated: 1771692788

View File

@@ -0,0 +1,35 @@
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.Systems
{
public class AttackCancelSystem : IInitializableSystem, IUpdatableSystem
{
private ReactiveVariable<bool> _inAttackProcess;
private ReactiveEvent _attackCanceledEvent;
private ICompositeCondition _mustCancelAttack;
public void OnInit(Entity entity)
{
_inAttackProcess = entity.InAttackProcess;
_attackCanceledEvent = entity.AttackCanceledEvent;
_mustCancelAttack = entity.MustCancelAttack;
}
public void OnUpdate(float deltaTime)
{
if (_inAttackProcess.Value == false)
return;
if (_mustCancelAttack.Evaluate())
{
_inAttackProcess.Value = false;
_attackCanceledEvent.Invoke();
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: afac0aa4f8e842d08a5326a7c89bcd53
timeCreated: 1771693765

View File

@@ -0,0 +1,53 @@
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 AttackCooldownTimerSystem : IInitializableSystem, IUpdatableSystem, IDisposableSystem
{
private ReactiveVariable<float> _currentTime;
private ReactiveVariable<float> _initialTime;
private ReactiveVariable<bool> _inAttackCooldown;
private ReactiveEvent _endAttackEvent;
private IDisposable _endAttackEventDisposable;
public void OnInit(Entity entity)
{
_currentTime = entity.AttackCooldownCurrentTime;
_initialTime = entity.AttackCooldownInitialTime;
_inAttackCooldown = entity.InAttackCooldown;
_endAttackEvent = entity.EndAttackEvent;
_endAttackEventDisposable = _endAttackEvent.Subscribe(OnEndAttack);
}
private void OnEndAttack()
{
_currentTime.Value = _initialTime.Value;
_inAttackCooldown.Value = true;
}
public void OnUpdate(float deltaTime)
{
if (_inAttackCooldown.Value == false)
return;
_currentTime.Value -= deltaTime;
if (CooldownIsOver())
_inAttackCooldown.Value = false;
}
private bool CooldownIsOver() => _currentTime.Value <= 0;
public void OnDispose()
{
_endAttackEventDisposable.Dispose();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 781d9ce92c044a06b9279a90539e041b
timeCreated: 1771693960

View File

@@ -32,6 +32,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems
{
_inAttackProcess.Value = true;
_startAttackEvent.Invoke();
Debug.Log("Старт атаки");
}
else
{
Debug.Log("Не могу атаковать!");
}
}

View File

@@ -0,0 +1,50 @@
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.Shoot
{
public class InstantShootSystem : IInitializableSystem, IDisposableSystem
{
private readonly EntitiesFactory _entitiesFactory;
private ReactiveEvent _attackDelayEndEvent;
private Entity _entity;
private ReactiveVariable<float> _damage;
private Transform _shootPoint;
private IDisposable _attackDelayEndDisposable;
public InstantShootSystem(EntitiesFactory entitiesFactory)
{
_entitiesFactory = entitiesFactory;
}
public void OnInit(Entity entity)
{
_entity = entity;
_attackDelayEndEvent = entity.AttackDelayEndEvent;
_damage = entity.InstantAttackDamage;
_shootPoint = entity.ShootPoint;
_attackDelayEndDisposable = _attackDelayEndEvent.Subscribe(OnAttackDelayEnd);
}
private void OnAttackDelayEnd()
{
_entitiesFactory.CreateProjectile(_shootPoint.position, _shootPoint.forward, _damage.Value);
}
public void OnDispose()
{
_attackDelayEndDisposable.Dispose();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8380bd6de9cc46cdbb48f281c3ce660e
timeCreated: 1771693051