Ability to switch weapons through the menu

This commit is contained in:
Marco 2025-02-25 18:42:11 +01:00
commit ff6d46ebcd
11 changed files with 61 additions and 4 deletions

View file

@ -11,13 +11,16 @@ public partial class InventoryManager : Node2D
private Dictionary<string, ItemContainer> _itemsDict = new Dictionary<string, ItemContainer>();
public Dictionary<string, ItemContainer> Items => _itemsDict;
public List<ItemContainer> Items => _itemsDict.Where(x => x.Value.Count > 0).Select(x => x.Value).ToList();
[Signal]
public delegate void ItemAddedEventHandler(LootItem item, int currentAmount);
[Signal]
public delegate void ItemRemovedEventHandler(string itemKey, int currentAmount);
[Signal]
public delegate void WeaponEquipEventHandler(string itemKey);
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@ -105,6 +108,37 @@ public partial class InventoryManager : Node2D
{
RedKeycard = false;
}
public bool UseItem(string itemKey)
{
if (!_itemsDict.TryGetValue(itemKey, out var itm)) return false;
if (itm.Count == 0) return false;
switch (itm.Item.Item)
{
case ItemTypes.Medkit:
// Heal
break;
case ItemTypes.FrogBomb:
// Use Bomb
break;
case ItemTypes.Bomb:
// Bomb
break;
case ItemTypes.Mine:
break;
case ItemTypes.Battery:
break;
case ItemTypes.Weapon:
// Equip weapon
EmitSignal(SignalName.WeaponEquip, itm.Item.ItemKey);
break;
}
return true;
}
}
public class ItemContainer