91 lines
1.9 KiB
C#
91 lines
1.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITFALL.Entities.Inventory;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.UX;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Entities
|
|
{
|
|
public struct BleedingDamage:IDamageType
|
|
{
|
|
|
|
}
|
|
[Serializable]
|
|
public struct StopBleeding : IProperty
|
|
{
|
|
|
|
}
|
|
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;
|
|
|
|
|
|
[Inject] private IEntityOverride _override;
|
|
|
|
[Inject(true)] private IUXPopup _popup;
|
|
public override void OnAwake()
|
|
{
|
|
base.OnAwake();
|
|
_ticker.Add(OnTick);
|
|
_health.OnSetAlive += OnSetAlive;
|
|
_health.OnDamageRelease += OnDamageRelease;
|
|
|
|
_inventory.OnUsedItem += OnUsedItem;
|
|
}
|
|
|
|
private void OnUsedItem(IBasicItem obj)
|
|
{
|
|
if (isBleeding is false) return;
|
|
var asset = obj.GetAssetable();
|
|
|
|
if (asset.TryGetProperty<StopBleeding>(out _))
|
|
{
|
|
isBleeding = false;
|
|
_popup?.Popup("<color=green>你停止了流血</color>");
|
|
}
|
|
}
|
|
|
|
private void OnSetAlive(bool obj)
|
|
{
|
|
isBleeding = false;
|
|
}
|
|
|
|
private void OnDamageRelease(DamageMessage obj)
|
|
{
|
|
if (isBleeding) return;
|
|
switch (obj.DamageType)
|
|
{
|
|
case BulletDamageMessage:
|
|
case MeleeDamageMessage { Bleeding: true }:
|
|
isBleeding = true;
|
|
_popup?.Popup("<color=red>你正在流血</color>");
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void OnTick(float obj)
|
|
{
|
|
if (isBleeding is false) return;
|
|
if (_health.IsAlive is false) return;
|
|
if (_override.IsOvering) return;
|
|
UnityEntity.Invoke<DamageMessage>(
|
|
new DamageMessage()
|
|
{
|
|
Target = UnityEntity,
|
|
Damage = bleedingDamage,
|
|
DamageType = new BleedingDamage()
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|