61 lines
1.2 KiB
C#
61 lines
1.2 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using BITKit;
|
||
|
using BITKit.Entities;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace BITFALL.Entities
|
||
|
{
|
||
|
public struct BleedingDamage:IDamageType
|
||
|
{
|
||
|
|
||
|
}
|
||
|
public class EntityBleeding : EntityBehavior
|
||
|
{
|
||
|
[SerializeReference, SubclassSelector] private ITicker _ticker;
|
||
|
[SerializeField] private bool isBleeding;
|
||
|
[SerializeField] private int bleedingDamage;
|
||
|
[Inject] private IHealth _health;
|
||
|
public override void OnAwake()
|
||
|
{
|
||
|
base.OnAwake();
|
||
|
_ticker.Add(OnTick);
|
||
|
_health.OnSetAlive += OnSetAlive;
|
||
|
_health.OnDamageRelease += OnDamageRelease;
|
||
|
}
|
||
|
|
||
|
private void OnSetAlive(bool obj)
|
||
|
{
|
||
|
isBleeding = false;
|
||
|
}
|
||
|
|
||
|
private void OnDamageRelease(DamageMessage obj)
|
||
|
{
|
||
|
switch (obj.DamageType)
|
||
|
{
|
||
|
case BulletDamageMessage:
|
||
|
isBleeding = true;
|
||
|
break;
|
||
|
case MeleeDamageMessage { Bleeding: true }:
|
||
|
isBleeding = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OnTick(float obj)
|
||
|
{
|
||
|
if (isBleeding is false) return;
|
||
|
if (_health.IsAlive is false) return;
|
||
|
UnityEntity.Invoke<DamageMessage>(
|
||
|
new DamageMessage()
|
||
|
{
|
||
|
Target = UnityEntity,
|
||
|
Damage = bleedingDamage,
|
||
|
DamageType = new BleedingDamage()
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|