Add projectiles
This commit is contained in:
@@ -69,24 +69,27 @@ public partial class Inventory : Node, IInventory
|
||||
InventoryChanged?.Invoke();
|
||||
}
|
||||
|
||||
public bool Sort(EquipableItem currentWeapon, EquipableItem currentArmor, EquipableItem currentAccessory)
|
||||
public bool Sort(EquipableItem currentWeapon, EquipableItem currentArmor, EquipableItem currentAccessory, EquipableItem 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>();
|
||||
equippedItems.AddRange(equippedWeapon);
|
||||
equippedItems.AddRange(equippedArmor);
|
||||
equippedItems.AddRange(equippedAccessory);
|
||||
equippedItems.AddRange(equippedAmmo);
|
||||
var listToSort = Items.Except(equippedItems);
|
||||
var weapons = listToSort.Where(x => x is Weapon).OrderBy(x => x as Weapon, new WeaponComparer());
|
||||
var armor = listToSort.Where(x => x is Armor).OrderBy(x => x as Armor, new ArmorComparer());
|
||||
var accessories = listToSort.Where(x => x is Accessory).OrderBy(x => x as Accessory, new AccessoryComparer());
|
||||
var ammo = listToSort.Where(x => x is Ammo).OrderBy(x => x as Ammo, new AmmoComparer());
|
||||
var consumables = listToSort.Where(x => x is ConsumableItem).OrderBy(x => x as ConsumableItem, new ConsumableComparer());
|
||||
var throwables = listToSort.Where(x => x is ThrowableItem).OrderBy(x => x as ThrowableItem, new ThrowableComparer());
|
||||
var effectItems = listToSort.Where(x => x is EffectItem).OrderBy(x => x as EffectItem, new EffectComparer());
|
||||
Items = [.. equippedItems, .. weapons, .. armor, .. accessories, .. consumables, .. throwables, .. effectItems];
|
||||
Items = [.. equippedItems, .. weapons, .. armor, .. accessories, .. ammo, .. consumables, .. throwables, .. effectItems];
|
||||
|
||||
var stackableItems = Items.OfType<IStackable>();
|
||||
var itemsToStack = stackableItems.GroupBy(x => ((InventoryItem)x).ItemName).Where(x => x.Count() > 1);
|
||||
@@ -131,6 +134,14 @@ public partial class Inventory : Node, IInventory
|
||||
}
|
||||
}
|
||||
|
||||
public class AmmoComparer : IComparer<Ammo>
|
||||
{
|
||||
public int Compare(Ammo x, Ammo y)
|
||||
{
|
||||
return x.ItemName.CompareTo(y.ItemName);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsumableComparer : IComparer<ConsumableItem>
|
||||
{
|
||||
public int Compare(ConsumableItem x, ConsumableItem y)
|
||||
|
||||
Reference in New Issue
Block a user