mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
feat: add base attack systems
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09e2d7dedb34455a8ca464d3a25e6f38
|
||||
timeCreated: 1771680515
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db3e7a5aa2634428a39cefa672bbb597
|
||||
timeCreated: 1771680531
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e5cd43b995e43eaaf01eb772ce4e53f
|
||||
timeCreated: 1771681280
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14247d25256641f4bdebce95c190de83
|
||||
timeCreated: 1771681439
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b3331518167469c8bedadab4206184f
|
||||
timeCreated: 1771681046
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a699afa5a7c24f0c8d16cc6639068255
|
||||
timeCreated: 1771680808
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30ae0ba2feaa4da3b5463d2cb8d5bfbe
|
||||
timeCreated: 1771681294
|
||||
Reference in New Issue
Block a user