BITFALL/Assets/Artists/Scripts/Entities/Health/EntityBleeding.cs

91 lines
1.9 KiB
C#
Raw Normal View History

2024-02-21 01:40:53 +08:00
using System;
2023-12-30 17:37:48 +08:00
using System.Collections;
using System.Collections.Generic;
2024-01-27 04:09:57 +08:00
using BITFALL.Entities.Inventory;
2023-12-30 17:37:48 +08:00
using BITKit;
using BITKit.Entities;
2024-02-21 01:40:53 +08:00
using BITKit.UX;
2023-12-30 17:37:48 +08:00
using UnityEngine;
namespace BITFALL.Entities
{
public struct BleedingDamage:IDamageType
{
2024-02-21 01:40:53 +08:00
}
[Serializable]
public struct StopBleeding : IProperty
{
2023-12-30 17:37:48 +08:00
}
public class EntityBleeding : EntityBehavior
{
[SerializeReference, SubclassSelector] private ITicker _ticker;
[SerializeField] private bool isBleeding;
[SerializeField] private int bleedingDamage;
[Inject] private IHealth _health;
2024-01-27 04:09:57 +08:00
[Inject] private IEntityInventory _inventory;
2024-02-21 01:40:53 +08:00
[Inject] private IEntityOverride _override;
[Inject(true)] private IUXPopup _popup;
2023-12-30 17:37:48 +08:00
public override void OnAwake()
{
base.OnAwake();
_ticker.Add(OnTick);
_health.OnSetAlive += OnSetAlive;
_health.OnDamageRelease += OnDamageRelease;
2024-01-27 04:09:57 +08:00
_inventory.OnUsedItem += OnUsedItem;
}
private void OnUsedItem(IBasicItem obj)
{
2024-02-21 01:40:53 +08:00
if (isBleeding is false) return;
2024-01-27 04:09:57 +08:00
var asset = obj.GetAssetable();
2024-02-21 01:40:53 +08:00
if (asset.TryGetProperty<StopBleeding>(out _))
{
isBleeding = false;
_popup?.Popup("<color=green>你停止了流血</color>");
}
2023-12-30 17:37:48 +08:00
}
private void OnSetAlive(bool obj)
{
isBleeding = false;
}
2024-02-21 01:40:53 +08:00
private void OnDamageRelease(DamageMessage obj)
2023-12-30 17:37:48 +08:00
{
2024-02-21 01:40:53 +08:00
if (isBleeding) return;
2023-12-30 17:37:48 +08:00
switch (obj.DamageType)
{
case BulletDamageMessage:
case MeleeDamageMessage { Bleeding: true }:
isBleeding = true;
2024-02-21 01:40:53 +08:00
_popup?.Popup("<color=red>你正在流血</color>");
2023-12-30 17:37:48 +08:00
break;
}
}
private void OnTick(float obj)
{
if (isBleeding is false) return;
if (_health.IsAlive is false) return;
2024-02-21 01:40:53 +08:00
if (_override.IsOvering) return;
2023-12-30 17:37:48 +08:00
UnityEntity.Invoke<DamageMessage>(
new DamageMessage()
{
Target = UnityEntity,
Damage = bleedingDamage,
DamageType = new BleedingDamage()
}
);
}
}
}