mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
feat: add shoot and cooldown systems
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1675979b03c84ec3b990009a37f3d6d9
|
||||
timeCreated: 1771692788
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afac0aa4f8e842d08a5326a7c89bcd53
|
||||
timeCreated: 1771693765
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 781d9ce92c044a06b9279a90539e041b
|
||||
timeCreated: 1771693960
|
||||
@@ -32,6 +32,11 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Attack.Systems
|
||||
{
|
||||
_inAttackProcess.Value = true;
|
||||
_startAttackEvent.Invoke();
|
||||
Debug.Log("Старт атаки");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Не могу атаковать!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8380bd6de9cc46cdbb48f281c3ce660e
|
||||
timeCreated: 1771693051
|
||||
@@ -0,0 +1,36 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utils.InputManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Input
|
||||
{
|
||||
public class AttackByInputSystem : IInitializableSystem, IDisposableSystem
|
||||
{
|
||||
private readonly IPlayerInput _playerInput;
|
||||
|
||||
private ReactiveEvent _startAttackRequest;
|
||||
|
||||
public AttackByInputSystem(IPlayerInput playerInput)
|
||||
{
|
||||
_playerInput = playerInput;
|
||||
}
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_startAttackRequest = entity.StartAttackRequest;
|
||||
|
||||
_playerInput.Interact.Enter += OnAttackRequest;
|
||||
}
|
||||
|
||||
private void OnAttackRequest(float value)
|
||||
{
|
||||
_startAttackRequest.Invoke();
|
||||
}
|
||||
|
||||
public void OnDispose()
|
||||
{
|
||||
_playerInput.Interact.Enter -= OnAttackRequest;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b9a5877786f409aa00af044e4b0ab10
|
||||
timeCreated: 1771695880
|
||||
@@ -3,7 +3,7 @@ using _Project.Develop.Runtime.Utils.InputManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Input
|
||||
{
|
||||
public class MoveDirectionByInputSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using _Project.Develop.Runtime.Utils.InputManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Input
|
||||
{
|
||||
public class RotateDirectionByMoveInputSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities.Conditions;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -9,6 +10,7 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
private ReactiveVariable<Vector3> _direction;
|
||||
private ReactiveVariable<float> _speed;
|
||||
private Transform _transform;
|
||||
private ICompositeCondition _canRotate;
|
||||
|
||||
private const float DeadZone = 0.1f;
|
||||
|
||||
@@ -17,10 +19,17 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Movement
|
||||
_direction = entity.RotateDirection;
|
||||
_speed = entity.RotationSpeed;
|
||||
_transform = entity.Transform;
|
||||
_canRotate = entity.CanRotate;
|
||||
|
||||
if (_direction.Value != Vector3.zero)
|
||||
_transform.rotation = Quaternion.LookRotation(_direction.Value.normalized);
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
if (_canRotate.Evaluate() == false)
|
||||
return;
|
||||
|
||||
if (_direction.Value.magnitude < DeadZone)
|
||||
return;
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.Systems
|
||||
{
|
||||
public class DeathMaskTouchDetectorSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private Buffer<Collider> _contacts;
|
||||
private ReactiveVariable<bool> _isTouchDeathMask;
|
||||
private LayerMask _deathMask;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_contacts = entity.ContactCollidersBuffer;
|
||||
_isTouchDeathMask = entity.IsTouchDeathMask;
|
||||
_deathMask = entity.DeathMask;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
for (int i = 0; i < _contacts.Count; i++)
|
||||
{
|
||||
if (MatchWithDeathLayer(_contacts.Items[i]))
|
||||
{
|
||||
_isTouchDeathMask.Value = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_isTouchDeathMask.Value = false;
|
||||
}
|
||||
|
||||
private bool MatchWithDeathLayer(Collider collider) => ((1 << collider.gameObject.layer) & _deathMask) != 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d117def644741f292aef71042b65c6b
|
||||
timeCreated: 1771695342
|
||||
Reference in New Issue
Block a user