mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-02 22:31:10 +00:00
feat: add attack delay trigger system
This commit is contained in:
@@ -53,7 +53,9 @@ namespace _Project.Develop.Runtime.Entities
|
|||||||
.AddInAttackProcess()
|
.AddInAttackProcess()
|
||||||
.AddStartAttackRequest()
|
.AddStartAttackRequest()
|
||||||
.AddStartAttackEvent()
|
.AddStartAttackEvent()
|
||||||
.AddEndAttackEvent();
|
.AddEndAttackEvent()
|
||||||
|
.AddAttackDelayTime(new ReactiveVariable<float>(2))
|
||||||
|
.AddAttackDelayEndEvent();
|
||||||
|
|
||||||
ICompositeCondition canMove = new CompositeCondition()
|
ICompositeCondition canMove = new CompositeCondition()
|
||||||
.Add(new FuncCondition(() => entity.IsDead.Value == false));
|
.Add(new FuncCondition(() => entity.IsDead.Value == false));
|
||||||
@@ -92,6 +94,7 @@ namespace _Project.Develop.Runtime.Entities
|
|||||||
|
|
||||||
.AddSystem(new StartAttackSystem())
|
.AddSystem(new StartAttackSystem())
|
||||||
.AddSystem(new ProcessAttackTimerSystem())
|
.AddSystem(new ProcessAttackTimerSystem())
|
||||||
|
.AddSystem(new AttackDelayEndTriggerSystem())
|
||||||
.AddSystem(new EndAttackSystem())
|
.AddSystem(new EndAttackSystem())
|
||||||
|
|
||||||
.AddSystem(new ApplyDamageSystem())
|
.AddSystem(new ApplyDamageSystem())
|
||||||
|
|||||||
@@ -858,6 +858,30 @@ namespace _Project.Develop.Runtime.Entities
|
|||||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessCurrentTime() {Value = value});
|
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackProcessCurrentTime() {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});
|
||||||
|
}
|
||||||
|
|
||||||
public _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayTime AttackDelayTimeC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayTime>();
|
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 _Project.Develop.Runtime.Utils.ReactiveManagement.ReactiveVariable<System.Single> AttackDelayTime => AttackDelayTimeC.Value;
|
||||||
@@ -906,29 +930,5 @@ namespace _Project.Develop.Runtime.Entities
|
|||||||
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.AttackDelayEndEvent() {Value = 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});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack
|
|||||||
|
|
||||||
public class AttackProcessInitialTime : IEntityComponent { public ReactiveVariable<float> Value; }
|
public class AttackProcessInitialTime : IEntityComponent { public ReactiveVariable<float> Value; }
|
||||||
public class AttackProcessCurrentTime : 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 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