feat: add feature damage

This commit is contained in:
Bragin Stepan
2026-02-19 23:40:03 +05:00
parent 1174be2d43
commit 1a067a3563
7 changed files with 146 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
using _Project.Develop.Runtime.Logic.Gameplay.Features.Lifetime.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.Utilities.Conditions;
using _Project.Develop.Runtime.Utils.InputManagement;
@@ -35,6 +36,8 @@ namespace _Project.Develop.Runtime.Entities
.AddRotationSpeed(new ReactiveVariable<float>(800))
.AddMaxHealth(new ReactiveVariable<float>(150))
.AddCurrentHealth(new ReactiveVariable<float>(150))
.AddTakeDamageRequest()
.AddTakeDamageEvent()
.AddIsDead()
.AddIsMoving()
.AddInDeathProcess()
@@ -54,13 +57,18 @@ namespace _Project.Develop.Runtime.Entities
.Add(new FuncCondition(() => entity.IsDead.Value))
.Add(new FuncCondition(() => entity.InDeathProcess.Value == false));
ICompositeCondition canApplyDamage = new CompositeCondition()
.Add(new FuncCondition(() => entity.IsDead.Value == false));
entity
.AddCanMove(canMove)
.AddCanRotate(canRotate)
.AddCanApplyDamage(canApplyDamage)
.AddMustDie(mustDie)
.AddMustSelfRelease(mustSelfRelease);
entity
.AddSystem(new ApplyDamageSystem())
.AddSystem(new RigidbodyMovementSystem())
.AddSystem(new RigidbodyRotationSystem())
.AddSystem(new MoveDirectionByInputSystem(_playerInput))

View File

@@ -461,5 +461,72 @@ namespace _Project.Develop.Runtime.Entities
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Movement.CanJump() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageRequest TakeDamageRequestC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageRequest>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single> TakeDamageRequest => TakeDamageRequestC.Value;
public bool TryGetTakeDamageRequest(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single> value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageRequest component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single>);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddTakeDamageRequest()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageRequest() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single>() });
}
public _Project.Develop.Runtime.Entities.Entity AddTakeDamageRequest(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageRequest() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageEvent TakeDamageEventC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageEvent>();
public _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single> TakeDamageEvent => TakeDamageEventC.Value;
public bool TryGetTakeDamageEvent(out _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single> value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageEvent component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single>);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddTakeDamageEvent()
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageEvent() { Value = new _Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single>() });
}
public _Project.Develop.Runtime.Entities.Entity AddTakeDamageEvent(_Project.Develop.Runtime.Utils.ReactiveManagement.Event.ReactiveEvent<System.Single> value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.TakeDamageEvent() {Value = value});
}
public _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.CanApplyDamage CanApplyDamageC => GetComponent<_Project.Develop.Runtime.Logic.Gameplay.Features.Damage.CanApplyDamage>();
public _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition CanApplyDamage => CanApplyDamageC.Value;
public bool TryGetCanApplyDamage(out _Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
{
bool result = TryGetComponent(out _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.CanApplyDamage component);
if(result)
value = component.Value;
else
value = default(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition);
return result;
}
public _Project.Develop.Runtime.Entities.Entity AddCanApplyDamage(_Project.Develop.Runtime.Utilities.Conditions.ICompositeCondition value)
{
return AddComponent(new _Project.Develop.Runtime.Logic.Gameplay.Features.Damage.CanApplyDamage() {Value = value});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b87bc393428846e3b37bf463760253c1
timeCreated: 1771525636

View File

@@ -0,0 +1,49 @@
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;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Damage
{
public class ApplyDamageSystem : IInitializableSystem, IDisposableSystem
{
private ReactiveEvent<float> _damageRequest;
private ReactiveEvent<float> _damageEvent;
private ReactiveVariable<float> _health;
private ICompositeCondition _canApplyDamage;
private IDisposable _requestDisposable;
public void OnInit(Entity entity)
{
_damageRequest = entity.TakeDamageRequest;
_damageEvent = entity.TakeDamageEvent;
_health = entity.CurrentHealth;
_canApplyDamage = entity.CanApplyDamage;
_requestDisposable = _damageRequest.Subscribe(OnDamageRequest);
}
public void OnDispose()
{
_requestDisposable.Dispose();
}
private void OnDamageRequest(float damage)
{
if (damage < 0)
throw new ArgumentOutOfRangeException(nameof(damage));
if (_canApplyDamage.Evaluate() == false)
return;
_health.Value = MathF.Max(_health.Value - damage, 0);
_damageEvent.Invoke(damage);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bd8ccd1d58fe484d933c61c5c640fff3
timeCreated: 1771525914

View File

@@ -0,0 +1,12 @@
using _Project.Develop.Runtime.Entities;
using _Project.Develop.Runtime.Utilities.Conditions;
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Damage
{
public class TakeDamageRequest : IEntityComponent { public ReactiveEvent<float> Value; }
public class TakeDamageEvent : IEntityComponent { public ReactiveEvent<float> Value; }
public class CanApplyDamage : IEntityComponent { public ICompositeCondition Value; }
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 79d8679b310c457bb73f676d4aaef890
timeCreated: 1771525646