72 lines
1.4 KiB
C#
72 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITFALL.Entities.Inventory;
|
|
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;
|
|
|
|
[Inject] private IEntityInventory _inventory;
|
|
public override void OnAwake()
|
|
{
|
|
base.OnAwake();
|
|
_ticker.Add(OnTick);
|
|
_health.OnSetAlive += OnSetAlive;
|
|
_health.OnDamageRelease += OnDamageRelease;
|
|
|
|
_inventory.OnUsedItem += OnUsedItem;
|
|
}
|
|
|
|
private void OnUsedItem(IBasicItem obj)
|
|
{
|
|
var asset = obj.GetAssetable();
|
|
if (obj is null) return;
|
|
}
|
|
|
|
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()
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|