From 5eab205a9cd67364a668ea7e693d844e6ac1f950 Mon Sep 17 00:00:00 2001 From: Nicola Date: Sat, 9 May 2026 15:06:46 +0200 Subject: [PATCH] Added unlock mechanic with testing if player has all items in inventory. --- Scripts/UI/Common/UIHandler.cs | 20 ++++++++++++-------- Scripts/World/Layer.cs | 10 ++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Scripts/UI/Common/UIHandler.cs b/Scripts/UI/Common/UIHandler.cs index 85ea2e3..b620f82 100644 --- a/Scripts/UI/Common/UIHandler.cs +++ b/Scripts/UI/Common/UIHandler.cs @@ -169,19 +169,23 @@ public partial class UIHandler : Control { currentLayer.Text = $"Current layer: {GameData.currentLayer}/{GameData.ruinSize}"; deepestLayer.Text = $"Deepest layer: {GameData.lowestLayer}"; + unlockLayer.TooltipText = "Needed items: \r" + GameData.map[GameData.lowestLayer].DisplayGateIngredients(); + unlockLayer.Disabled = !GameData.inventory.CanCraft(GameData.map[GameData.lowestLayer].gateIngredients, 1); } public void UnlockLayer() { - foreach (Ingredient ingredient in GameData.map[GameData.lowestLayer].gateIngredients) + if (GameData.inventory.CanCraft(GameData.map[GameData.lowestLayer].gateIngredients, 1)) { - GD.Print($"{ingredient.Item} ({ingredient.Amount})"); - } - GD.Print("------------------------"); - GameData.lowestLayer++; - if (GameData.lowestLayer == GameData.ruinSize) - { - GD.Print("GAME WON!"); + foreach (Ingredient ingredient in GameData.map[GameData.lowestLayer].gateIngredients) + { + GameData.inventory.RemoveItem(ingredient.Item, ingredient.Amount); + } + GameData.lowestLayer++; + if (GameData.lowestLayer == GameData.ruinSize) + { + GD.Print("GAME WON!"); + } } } } diff --git a/Scripts/World/Layer.cs b/Scripts/World/Layer.cs index 691c5c9..95ee1c5 100644 --- a/Scripts/World/Layer.cs +++ b/Scripts/World/Layer.cs @@ -264,4 +264,14 @@ public partial class Layer : Node3D } return result; } + + public string DisplayGateIngredients() + { + string result = ""; + foreach (Ingredient ingredient in gateIngredients) + { + result += $"{ItemData.GetReadableName(ingredient.Item)} ({ingredient.Amount})\r"; + } + return result; + } }