2023-11-30 00:23:23 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using BITFALL.Entities;
|
|
|
|
using BITFALL.Entities.Inventory;
|
|
|
|
using BITFALL.Player.Inventory;
|
|
|
|
using BITKit;
|
|
|
|
using BITKit.Entities;
|
2023-12-03 17:35:43 +08:00
|
|
|
using BITKit.UX;
|
2023-11-30 00:23:23 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BITFALL.Items
|
|
|
|
{
|
|
|
|
[CustomType(typeof(ICustomItemBehavior))]
|
|
|
|
public abstract class CustomItemBehavior : ICustomItemBehavior, IProperty
|
|
|
|
{
|
2024-02-21 01:40:53 +08:00
|
|
|
[Inject]
|
2023-11-30 00:23:23 +08:00
|
|
|
protected IEntity _entity;
|
2024-02-21 01:40:53 +08:00
|
|
|
public bool IsAdditive;
|
2023-11-30 00:23:23 +08:00
|
|
|
[Inject] protected IEntityInventory _inventory;
|
|
|
|
|
|
|
|
public virtual bool TryUse(IBasicItem item) => true;
|
|
|
|
|
|
|
|
public virtual void OnUse(IBasicItem item)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public sealed class PlayerHealItem : CustomItemBehavior
|
|
|
|
{
|
|
|
|
[SerializeField] private int healValue;
|
2024-02-21 01:40:53 +08:00
|
|
|
[SerializeField] private bool autoUse;
|
2023-11-30 00:23:23 +08:00
|
|
|
|
|
|
|
[Inject] private IHealth _health;
|
|
|
|
|
|
|
|
[Inject(true)] private IKnockdown _knockdown;
|
2023-12-03 17:35:43 +08:00
|
|
|
|
|
|
|
[Inject(true)] private IUXPopup _popup;
|
2024-01-27 04:09:57 +08:00
|
|
|
|
2023-11-30 00:23:23 +08:00
|
|
|
public override bool TryUse(IBasicItem item)
|
|
|
|
{
|
|
|
|
if(_health.IsAlive is false) return false;
|
2023-12-03 17:35:43 +08:00
|
|
|
if (_health.HealthPoint >= _health.MaxHealthPoint)
|
|
|
|
{
|
|
|
|
_popup?.Popup("<color=yellow>生命值已满</color>");
|
|
|
|
return false;
|
|
|
|
}
|
2024-02-21 01:40:53 +08:00
|
|
|
if (_knockdown is { IsKnockdown: true })
|
2023-11-30 00:23:23 +08:00
|
|
|
{
|
2023-12-03 17:35:43 +08:00
|
|
|
_popup?.Popup("<color=yellow>你被击倒了</color>");
|
2023-11-30 00:23:23 +08:00
|
|
|
return false;
|
|
|
|
}
|
2024-02-21 01:40:53 +08:00
|
|
|
if (autoUse)
|
|
|
|
{
|
|
|
|
_inventory.UseItem(item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2023-11-30 00:23:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnUse(IBasicItem item)
|
|
|
|
{
|
|
|
|
base.OnUse(item);
|
|
|
|
_health.HealthPoint+=healValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|