In progress item changes
This commit is contained in:
@@ -27,9 +27,9 @@ public partial class Inventory : Node, IInventory
|
||||
}
|
||||
|
||||
[Save("inventory_items")]
|
||||
public List<InventoryItem> Items { get; private set; }
|
||||
public List<IBaseInventoryItem> Items { get; private set; }
|
||||
|
||||
public bool PickUpItem(InventoryItem item)
|
||||
public bool PickUpItem(IBaseInventoryItem item)
|
||||
{
|
||||
var isAdded = TryAdd(item);
|
||||
if (isAdded)
|
||||
@@ -43,7 +43,7 @@ public partial class Inventory : Node, IInventory
|
||||
return isAdded;
|
||||
}
|
||||
|
||||
public bool TryAdd(InventoryItem inventoryItem)
|
||||
public bool TryAdd(IBaseInventoryItem inventoryItem)
|
||||
{
|
||||
if (Items.Count >= _maxInventorySize)
|
||||
return false;
|
||||
@@ -55,7 +55,7 @@ public partial class Inventory : Node, IInventory
|
||||
|
||||
public bool AtCapacity() => Items.Count >= _maxInventorySize;
|
||||
|
||||
public bool TryInsert(InventoryItem inventoryItem, int index)
|
||||
public bool TryInsert(IBaseInventoryItem inventoryItem, int index)
|
||||
{
|
||||
if (Items.Count >= _maxInventorySize || index >= _maxInventorySize || index < 0)
|
||||
return false;
|
||||
@@ -65,20 +65,20 @@ public partial class Inventory : Node, IInventory
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove(InventoryItem inventoryItem)
|
||||
public void Remove(IBaseInventoryItem inventoryItem)
|
||||
{
|
||||
Items.Remove(inventoryItem);
|
||||
InventoryChanged?.Invoke();
|
||||
}
|
||||
|
||||
public bool Sort(EquipableItem currentWeapon, EquipableItem currentArmor, EquipableItem currentAccessory, EquipableItem currentAmmo)
|
||||
public bool Sort(IWeapon currentWeapon, IArmor currentArmor, IAccessory currentAccessory, IEquipableItem currentAmmo)
|
||||
{
|
||||
var initialList = Items;
|
||||
var equippedWeapon = Items.OfType<Weapon>().Where(x => x == currentWeapon);
|
||||
var equippedArmor = Items.OfType<Armor>().Where(x => x == currentArmor);
|
||||
var equippedAccessory = Items.OfType<Accessory>().Where(x => x == currentAccessory);
|
||||
var equippedAmmo = Items.OfType<Ammo>().Where(x => x == currentAmmo);
|
||||
var equippedItems = new List<InventoryItem>();
|
||||
var equippedItems = new List<IBaseInventoryItem>();
|
||||
equippedItems.AddRange(equippedWeapon);
|
||||
equippedItems.AddRange(equippedArmor);
|
||||
equippedItems.AddRange(equippedAccessory);
|
||||
@@ -96,12 +96,12 @@ public partial class Inventory : Node, IInventory
|
||||
Items = [.. equippedItems, .. weapons, .. armor, .. accessories, .. ammo, .. consumables, .. throwables, .. effectItems, .. jewelItems, .. setItems];
|
||||
|
||||
var stackableItems = Items.OfType<IStackable>();
|
||||
var itemsToStack = stackableItems.GroupBy(x => ((InventoryItem)x).ItemName).Where(x => x.Count() > 1);
|
||||
var itemsToStack = stackableItems.GroupBy(x => ((IBaseInventoryItem)x).ItemName).Where(x => x.Count() > 1);
|
||||
foreach (var itemStack in itemsToStack)
|
||||
{
|
||||
var firstItem = itemStack.First();
|
||||
firstItem.SetCount(itemStack.Sum(x => x.Count.Value));
|
||||
var itemsToRemove = itemStack.Except([firstItem]).Cast<InventoryItem>();
|
||||
var itemsToRemove = itemStack.Except([firstItem]).Cast<IBaseInventoryItem>();
|
||||
foreach (var item in itemsToRemove)
|
||||
Remove(item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user