mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
feat: add feature damage
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b87bc393428846e3b37bf463760253c1
|
||||
timeCreated: 1771525636
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd8ccd1d58fe484d933c61c5c640fff3
|
||||
timeCreated: 1771525914
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79d8679b310c457bb73f676d4aaef890
|
||||
timeCreated: 1771525646
|
||||
Reference in New Issue
Block a user