SupaLidlGame/Items/Item.cs

80 lines
1.5 KiB
C#
Raw Normal View History

2022-11-13 19:52:09 -08:00
using Godot;
using SupaLidlGame.Characters;
2023-06-03 18:21:46 -07:00
namespace SupaLidlGame.Items;
public abstract partial class Item : Node2D
2022-11-13 19:52:09 -08:00
{
2023-08-10 23:08:41 -07:00
[Signal]
public delegate void UsedItemEventHandler(Item item);
2023-06-03 18:21:46 -07:00
[Export]
2023-12-29 17:45:36 -08:00
public bool CanStack { get; set; } = false;
2022-11-13 19:52:09 -08:00
2023-06-03 18:21:46 -07:00
[Export]
2023-12-29 17:45:36 -08:00
public ItemMetadata Metadata { get; set; }
2023-03-19 13:54:48 -07:00
2023-06-03 18:21:46 -07:00
public int Count { get; set; } = 1;
2023-03-19 13:54:48 -07:00
2023-06-03 18:21:46 -07:00
public bool IsOneHanded { get; set; } = false;
2023-03-19 23:36:36 -07:00
2023-06-03 18:21:46 -07:00
public Character CharacterOwner { get; set; }
2023-03-26 13:03:45 -07:00
2023-08-31 19:03:16 -07:00
/// <summary>
/// Determines if the item is being used. This property determines if
/// a character can use another item or not.
/// See <see cref="Character.UseCurrentItem"/>
/// </summary>
///
2023-06-03 18:21:46 -07:00
public virtual bool IsUsing => false;
2023-04-16 14:11:17 -07:00
2023-06-03 18:21:46 -07:00
/// <summary>
/// Determines if this item can directly stack with other items
/// </summary>
public virtual bool StacksWith(Item item)
{
if (!CanStack)
2023-03-19 13:54:48 -07:00
{
2023-06-03 18:21:46 -07:00
return false;
}
2023-03-19 13:54:48 -07:00
2023-12-29 17:45:36 -08:00
if (Metadata.Name != item.Metadata.Name)
2023-06-03 18:21:46 -07:00
{
return false;
}
2023-03-19 13:54:48 -07:00
2023-06-03 18:21:46 -07:00
// several more conditions may be added soon
2023-03-19 13:54:48 -07:00
2023-06-03 18:21:46 -07:00
return true;
}
2023-03-19 13:54:48 -07:00
2023-06-03 18:21:46 -07:00
public abstract void Equip(Character character);
2022-11-13 19:52:09 -08:00
2023-06-03 18:21:46 -07:00
public abstract void Unequip(Character character);
2022-11-13 19:52:09 -08:00
2023-06-03 18:21:46 -07:00
public abstract void Use();
2022-11-13 19:52:09 -08:00
2023-06-03 18:21:46 -07:00
public abstract void Deuse();
2023-08-08 00:54:00 -07:00
public virtual void UseAlt()
{
}
public virtual void DeuseAlt()
{
}
public virtual void Remove()
{
if (IsUsing)
{
Deuse();
}
Unequip(CharacterOwner);
QueueFree();
}
2022-11-13 19:52:09 -08:00
}