58 lines
1.5 KiB
C#
58 lines
1.5 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 UnityEngine;
|
|
|
|
namespace BITFALL.Items
|
|
{
|
|
[CustomType(typeof(ICustomItemBehavior))]
|
|
public abstract class CustomItemBehavior : ICustomItemBehavior, IProperty
|
|
{
|
|
protected IEntity _entity;
|
|
[Inject] protected IEntityInventory _inventory;
|
|
|
|
public void Inject(IEntity entity)
|
|
{
|
|
_entity = entity;
|
|
entity.Inject(this);
|
|
}
|
|
|
|
public virtual bool TryUse(IBasicItem item) => true;
|
|
|
|
public virtual void OnUse(IBasicItem item)
|
|
{
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class PlayerHealItem : CustomItemBehavior
|
|
{
|
|
[SerializeField] private int healValue;
|
|
|
|
[Inject] private IHealth _health;
|
|
|
|
[Inject(true)] private IKnockdown _knockdown;
|
|
public override bool TryUse(IBasicItem item)
|
|
{
|
|
if(_health.IsAlive is false) return false;
|
|
if (_health.HealthPoint == _health.MaxHealthPoint) return false;
|
|
if (_knockdown is not null && _knockdown.IsKnockdown)
|
|
{
|
|
return false;
|
|
}
|
|
return base.TryUse(item);
|
|
}
|
|
|
|
public override void OnUse(IBasicItem item)
|
|
{
|
|
base.OnUse(item);
|
|
_health.HealthPoint+=healValue;
|
|
}
|
|
}
|
|
}
|