mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
feat: add hero and body deal damage
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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
|
||||
@@ -9,4 +10,6 @@ namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Damage
|
||||
public class TakeDamageEvent : IEntityComponent { public ReactiveEvent<float> Value; }
|
||||
|
||||
public class CanApplyDamage : IEntityComponent { public ICompositeCondition Value; }
|
||||
|
||||
public class BodyContactDamage : IEntityComponent { public ReactiveVariable<float> Value; }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 184b10356b354fbb9d4ec3e182cbe8e5
|
||||
timeCreated: 1771676819
|
||||
@@ -3,6 +3,7 @@ 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.Damage
|
||||
{
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement.Event;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Damage
|
||||
{
|
||||
public class DealDamageOnContactSystem: IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private Entity _entity;
|
||||
private Buffer<Entity> _contacts;
|
||||
private ReactiveVariable<float> _damage;
|
||||
|
||||
private List<Entity> _processedEntities;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_entity = entity;
|
||||
_contacts = entity.ContactEntitiesBuffer;
|
||||
_damage = entity.BodyContactDamage;
|
||||
|
||||
_processedEntities = new List<Entity>(_contacts.Items.Length);
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
for (int i = 0; i < _contacts.Count; i++)
|
||||
{
|
||||
Entity contactEntity = _contacts.Items[i];
|
||||
|
||||
if(_processedEntities.Contains(contactEntity) == false)
|
||||
{
|
||||
_processedEntities.Add(contactEntity);
|
||||
|
||||
if (contactEntity.TryGetTakeDamageRequest(out ReactiveEvent<float> takeDamageRequest))
|
||||
takeDamageRequest.Invoke(_damage.Value);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = _processedEntities.Count - 1; i >= 0; i--)
|
||||
if (ContainInContacts(_processedEntities[i]) == false)
|
||||
_processedEntities.RemoveAt(i);
|
||||
}
|
||||
|
||||
private bool ContainInContacts(Entity entity)
|
||||
{
|
||||
for (int i = 0; i < _contacts.Count; i++)
|
||||
if (_contacts.Items[i] == entity)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b87d3d31c8d940df81767830621e290f
|
||||
timeCreated: 1771676878
|
||||
Reference in New Issue
Block a user