BITFALL/Assets/Artists/Scripts/Entities/Inventory/PlayerCustomItemBehaviour.cs

69 lines
1.8 KiB
C#

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;
using BITKit.UX;
using UnityEngine;
namespace BITFALL.Items
{
[CustomType(typeof(ICustomItemBehavior))]
public abstract class CustomItemBehavior : ICustomItemBehavior, IProperty
{
[Inject]
protected IEntity _entity;
public bool IsAdditive;
[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;
[SerializeField] private bool autoUse;
[Inject] private IHealth _health;
[Inject(true)] private IKnockdown _knockdown;
[Inject(true)] private IUXPopup _popup;
public override bool TryUse(IBasicItem item)
{
if(_health.IsAlive is false) return false;
if (_health.HealthPoint >= _health.MaxHealthPoint)
{
_popup?.Popup("<color=yellow>生命值已满</color>");
return false;
}
if (_knockdown is { IsKnockdown: true })
{
_popup?.Popup("<color=yellow>你被击倒了</color>");
return false;
}
if (autoUse)
{
_inventory.UseItem(item);
return true;
}
return false;
}
public override void OnUse(IBasicItem item)
{
base.OnUse(item);
_health.HealthPoint+=healValue;
}
}
}