Fix up item usage

This commit is contained in:
2025-03-07 18:40:14 -08:00
parent 93c04440d4
commit fe3c539a62
15 changed files with 125 additions and 65 deletions

View File

@@ -5,16 +5,17 @@ using Chickensoft.Serialization;
using Godot;
using System.Collections.Generic;
using System.Linq;
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Game.Ma;
public interface IInventory : INode
{
public List<InventoryItem> Items { get; }
public List<IInventoryItem> Items { get; }
public bool TryAdd(InventoryItem inventoryItem);
public bool TryAdd(IInventoryItem inventoryItem);
public void Remove(InventoryItem inventoryItem);
public void Remove(IInventoryItem inventoryItem);
public void Sort();
}
@@ -33,9 +34,9 @@ public partial class Inventory : Node, IInventory
}
[Save("inventory_items")]
public List<InventoryItem> Items { get; private set; }
public List<IInventoryItem> Items { get; private set; }
public bool TryAdd(InventoryItem inventoryItem)
public bool TryAdd(IInventoryItem inventoryItem)
{
if (Items.Count >= _maxInventorySize)
return false;
@@ -44,15 +45,15 @@ public partial class Inventory : Node, IInventory
return true;
}
public void Remove(InventoryItem inventoryItem) => Items.Remove(inventoryItem);
public void Remove(IInventoryItem inventoryItem) => Items.Remove(inventoryItem);
public void Sort()
{
var equippedWeapon = Items.OfType<Weapon>().Where(x => x.IsEquipped);
var equippedArmor = Items.OfType<Armor>().Where(x => x.IsEquipped);
var equippedAccessory = Items.OfType<Accessory>().Where(x => x.IsEquipped);
var equippedItems = new List<InventoryItem>();
var equippedWeapon = Items.OfType<Weapon>().Where(x => x.IsEquipped).Cast<IInventoryItem>();
var equippedArmor = Items.OfType<Armor>().Where(x => x.IsEquipped).Cast<IInventoryItem>();
var equippedAccessory = Items.OfType<Accessory>().Where(x => x.IsEquipped).Cast<IInventoryItem>();
var equippedItems = new List<IInventoryItem>();
equippedItems.AddRange(equippedWeapon);
equippedItems.AddRange(equippedArmor);
equippedItems.AddRange(equippedAccessory);