Rework game over logic and game initialization
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
@@ -17,6 +18,8 @@ public partial class Inventory : Node, IInventory
|
||||
// TODO: Constants class with export
|
||||
private const int _maxInventorySize = 20;
|
||||
|
||||
public event Action<string> BroadcastMessage;
|
||||
|
||||
public Inventory()
|
||||
{
|
||||
Items = [];
|
||||
@@ -25,6 +28,20 @@ public partial class Inventory : Node, IInventory
|
||||
[Save("inventory_items")]
|
||||
public List<InventoryItem> Items { get; private set; }
|
||||
|
||||
public bool PickUpItem(InventoryItem item)
|
||||
{
|
||||
var isAdded = TryAdd(item);
|
||||
if (isAdded)
|
||||
{
|
||||
BroadcastMessage?.Invoke($"{item.ItemName} picked up.");
|
||||
item.QueueFree();
|
||||
}
|
||||
else
|
||||
BroadcastMessage?.Invoke($"Could not pick up {item.ItemName}.");
|
||||
|
||||
return isAdded;
|
||||
}
|
||||
|
||||
public bool TryAdd(InventoryItem inventoryItem)
|
||||
{
|
||||
if (Items.Count >= _maxInventorySize)
|
||||
|
||||
Reference in New Issue
Block a user