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

@@ -1,4 +1,5 @@
using _Project.Develop.Runtime.Logic.Gameplay.Features.Damage;
using _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems;
using _Project.Develop.Runtime.Logic.Gameplay.Features.Damage;
using _Project.Develop.Runtime.Logic.Gameplay.Features.Lifetime.Systems;
using _Project.Develop.Runtime.Logic.Gameplay.Features.Movement;
using _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.Systems;
@@ -46,7 +47,13 @@ namespace _Project.Develop.Runtime.Entities
.AddIsMoving()
.AddInDeathProcess()
.AddDeathProcessInitialTime(new ReactiveVariable<float>(2))
.AddDeathProcessCurrentTime();
.AddDeathProcessCurrentTime()
.AddAttackProcessInitialTime(new ReactiveVariable<float>(3))
.AddAttackProcessCurrentTime()
.AddInAttackProcess()
.AddStartAttackRequest()
.AddStartAttackEvent()
.AddEndAttackEvent();
ICompositeCondition canMove = new CompositeCondition()
.Add(new FuncCondition(() => entity.IsDead.Value == false));
@@ -64,11 +71,17 @@ namespace _Project.Develop.Runtime.Entities
ICompositeCondition canApplyDamage = new CompositeCondition()
.Add(new FuncCondition(() => entity.IsDead.Value == false));
ICompositeCondition canStartAttack = new CompositeCondition()
.Add(new FuncCondition(() => entity.IsDead.Value == false))
.Add(new FuncCondition(() => entity.InAttackProcess.Value == false))
.Add(new FuncCondition(() => entity.IsMoving.Value == false));
entity
.AddCanMove(canMove)
.AddCanRotate(canRotate)
.AddCanApplyDamage(canApplyDamage)
.AddMustDie(mustDie)
.AddCanStartAttack(canStartAttack)
.AddMustSelfRelease(mustSelfRelease);
entity
@@ -76,9 +89,16 @@ namespace _Project.Develop.Runtime.Entities
.AddSystem(new RotateDirectionByMoveInputSystem(_playerInput))
.AddSystem(new RigidbodyMovementSystem())
.AddSystem(new RigidbodyRotationSystem())
.AddSystem(new StartAttackSystem())
.AddSystem(new ProcessAttackTimerSystem())
.AddSystem(new EndAttackSystem())
.AddSystem(new ApplyDamageSystem())
.AddSystem(new DeathSwitcherSystem())
.AddSystem(new DeathProcessTimerSystem())
.AddSystem(new DisableCollidersOnDeathSystem())
.AddSystem(new SelfReleaseSystem(_entitiesLifeContext));
@@ -136,14 +156,18 @@ namespace _Project.Develop.Runtime.Entities
.AddMustSelfRelease(mustSelfRelease);
entity
.AddSystem(new BodyContactsDetectingSystem())
.AddSystem(new BodyContactsEntitiesFilterSystem(_collidersRegistryService))
.AddSystem(new DealDamageOnContactSystem())
.AddSystem(new ApplyDamageSystem())
.AddSystem(new RigidbodyMovementSystem())
.AddSystem(new RigidbodyRotationSystem())
.AddSystem(new BodyContactsDetectingSystem())
.AddSystem(new BodyContactsEntitiesFilterSystem(_collidersRegistryService))
.AddSystem(new DealDamageOnContactSystem())
.AddSystem(new ApplyDamageSystem())
.AddSystem(new DeathSwitcherSystem())
.AddSystem(new DeathProcessTimerSystem())
.AddSystem(new DisableCollidersOnDeathSystem())
.AddSystem(new SelfReleaseSystem(_entitiesLifeContext));

View File

@@ -719,5 +719,216 @@ namespace _Project.Develop.Runtime.Entities
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.BodyContactDamage() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackRequest StartAttackRequestC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackRequest>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent StartAttackRequest => StartAttackRequestC.Value;
public bool TryGetStartAttackRequest(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackRequest component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddStartAttackRequest()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackRequest() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent() });
}
public _Project.Develop.Runtime.Entities.Entity AddStartAttackRequest(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackRequest() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackEvent StartAttackEventC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackEvent>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent StartAttackEvent => StartAttackEventC.Value;
public bool TryGetStartAttackEvent(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackEvent component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddStartAttackEvent()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackEvent() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent() });
}
public _Project.Develop.Runtime.Entities.Entity AddStartAttackEvent(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.StartAttackEvent() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.CanStartAttack CanStartAttackC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.CanStartAttack>();
public _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition CanStartAttack => CanStartAttackC.Value;
public bool TryGetCanStartAttack(out _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.CanStartAttack component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddCanStartAttack(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.CanStartAttack() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.EndAttackEvent EndAttackEventC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.EndAttackEvent>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent EndAttackEvent => EndAttackEventC.Value;
public bool TryGetEndAttackEvent(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.EndAttackEvent component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddEndAttackEvent()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.EndAttackEvent() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent() });
}
public _Project.Develop.Runtime.Entities.Entity AddEndAttackEvent(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.EndAttackEvent() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessInitialTime AttackProcessInitialTimeC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessInitialTime>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> AttackProcessInitialTime => AttackProcessInitialTimeC.Value;
public bool TryGetAttackProcessInitialTime(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessInitialTime component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddAttackProcessInitialTime()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessInitialTime() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>() });
}
public _Project.Develop.Runtime.Entities.Entity AddAttackProcessInitialTime(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessInitialTime() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessCurrentTime AttackProcessCurrentTimeC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessCurrentTime>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> AttackProcessCurrentTime => AttackProcessCurrentTimeC.Value;
public bool TryGetAttackProcessCurrentTime(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessCurrentTime component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddAttackProcessCurrentTime()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessCurrentTime() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>() });
}
public _Project.Develop.Runtime.Entities.Entity AddAttackProcessCurrentTime(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessCurrentTime() {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<System.Single> AttackDelayTime => AttackDelayTimeC.Value;
public bool TryGetAttackDelayTime(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayTime component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddAttackDelayTime()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayTime() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single>() });
}
public _Project.Develop.Runtime.Entities.Entity AddAttackDelayTime(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayTime() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayEndEvent AttackDelayEndEventC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayEndEvent>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent AttackDelayEndEvent => AttackDelayEndEventC.Value;
public bool TryGetAttackDelayEndEvent(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayEndEvent component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddAttackDelayEndEvent()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayEndEvent() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent() });
}
public _Project.Develop.Runtime.Entities.Entity AddAttackDelayEndEvent(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent value)
{
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<System.Boolean> InAttackProcess => InAttackProcessC.Value;
public bool TryGetInAttackProcess(out _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> 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<System.Boolean>);
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<System.Boolean>() });
}
public _Project.Develop.Runtime.Entities.Entity AddInAttackProcess(_Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Boolean> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.InAttackProcess() {Value = value});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b89412a37593416d972b8a40fe4ad61d
timeCreated: 1771680505

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