mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
working spder bomb
This commit is contained in:
parent
6125565d8c
commit
f1f40a91dd
17 changed files with 400 additions and 105 deletions
|
|
@ -8,20 +8,23 @@ using Cirno.Scripts.Resources;
|
|||
public partial class InventoryManager : Node2D
|
||||
{
|
||||
public bool RedKeycard { get; set; }
|
||||
|
||||
|
||||
private Dictionary<string, ItemContainer> _itemsDict = new Dictionary<string, ItemContainer>();
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
[Signal]
|
||||
public delegate void ItemUsedEventHandler(LootItem itemKey, int totalCount);
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -31,12 +34,12 @@ public partial class InventoryManager : Node2D
|
|||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public bool HasItems(List<string> itemKeys)
|
||||
{
|
||||
return itemKeys.Aggregate(false, (current, item) => current || GetItemCount(item) > 0);
|
||||
}
|
||||
|
||||
|
||||
public int GetItemCount(string itemKey)
|
||||
{
|
||||
return _itemsDict.TryGetValue(itemKey, out var itm) ? itm.Count : 0;
|
||||
|
|
@ -47,20 +50,20 @@ public partial class InventoryManager : Node2D
|
|||
if (!_itemsDict.TryGetValue(itemKey, out var itm)) return 0;
|
||||
|
||||
int removed = Math.Min(itm.Count, amount);
|
||||
|
||||
|
||||
itm.Count -= amount;
|
||||
|
||||
if (itm.Count <= 0)
|
||||
{
|
||||
_itemsDict.Remove(itemKey);
|
||||
}
|
||||
|
||||
|
||||
EmitSignal(nameof(ItemRemoved), itemKey, itm.Count);
|
||||
|
||||
return removed;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public bool AddItem(LootItem item)
|
||||
{
|
||||
//var item = new LootItem() { Item = type, Amount = amount };
|
||||
|
|
@ -73,7 +76,7 @@ public partial class InventoryManager : Node2D
|
|||
Count = item.Amount,
|
||||
});
|
||||
GD.Print($"Added new ({item.ItemKey}) {item.Item} x{item.Amount}");
|
||||
|
||||
|
||||
EmitSignal(nameof(ItemAdded), item, item.Amount);
|
||||
}
|
||||
else
|
||||
|
|
@ -82,7 +85,7 @@ public partial class InventoryManager : Node2D
|
|||
{
|
||||
itm.Count += item.Amount;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (item.PickupIfMaxed)
|
||||
{
|
||||
|
|
@ -95,10 +98,10 @@ public partial class InventoryManager : Node2D
|
|||
}
|
||||
EmitSignal(nameof(ItemAdded), item, itm.Count);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void AddRedKeycard()
|
||||
{
|
||||
RedKeycard = true;
|
||||
|
|
@ -114,29 +117,27 @@ public partial class InventoryManager : Node2D
|
|||
if (!_itemsDict.TryGetValue(itemKey, out var itm)) return false;
|
||||
|
||||
if (itm.Count == 0) return false;
|
||||
GD.Print($"Used item in manager {itemKey}");
|
||||
|
||||
switch (itm.Item.Item)
|
||||
{
|
||||
case ItemTypes.Medkit:
|
||||
// Heal
|
||||
break;
|
||||
// Heal
|
||||
case ItemTypes.FrogBomb:
|
||||
// Use Bomb
|
||||
break;
|
||||
// Use Bomb
|
||||
case ItemTypes.Bomb:
|
||||
// Bomb
|
||||
break;
|
||||
// Bomb
|
||||
case ItemTypes.Mine:
|
||||
break;
|
||||
case ItemTypes.Battery:
|
||||
EmitSignal(SignalName.ItemUsed, itm.Item, itm.Count);
|
||||
break;
|
||||
case ItemTypes.Weapon:
|
||||
// Equip weapon
|
||||
EmitSignal(SignalName.WeaponEquip, itm.Item.ItemKey);
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue