From 213d0aed977f246aa8a2268573c3be84447404ab Mon Sep 17 00:00:00 2001 From: Nicola Date: Sat, 9 May 2026 14:57:06 +0200 Subject: [PATCH] Added gate unlock generation and simple Game Won print --- Scenes/Game.tscn | 1 + Scripts/UI/Common/UIHandler.cs | 12 ++++- Scripts/World/Layer.cs | 1 + Scripts/World/World.cs | 80 +++++++++++++++++++++++++++++++++- 4 files changed, 90 insertions(+), 4 deletions(-) diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index fdab27a..9d803d9 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -524,6 +524,7 @@ layout_mode = 2 tooltip_text = "Menu (ESC)" texture_normal = ExtResource("12_3so38") +[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/HeaderContainer/VBoxContainer/UnlockLayer" to="CanvasLayer/UIHandler" method="UnlockLayer"] [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Renaming/Button" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="SaveRobotName"] [connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons/Clear" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="ClearWindow"] [connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons/Compile" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="CompileProgram"] diff --git a/Scripts/UI/Common/UIHandler.cs b/Scripts/UI/Common/UIHandler.cs index e92e0e8..85ea2e3 100644 --- a/Scripts/UI/Common/UIHandler.cs +++ b/Scripts/UI/Common/UIHandler.cs @@ -169,11 +169,19 @@ public partial class UIHandler : Control { currentLayer.Text = $"Current layer: {GameData.currentLayer}/{GameData.ruinSize}"; deepestLayer.Text = $"Deepest layer: {GameData.lowestLayer}"; - } public void UnlockLayer() { - + foreach (Ingredient ingredient in GameData.map[GameData.lowestLayer].gateIngredients) + { + GD.Print($"{ingredient.Item} ({ingredient.Amount})"); + } + GD.Print("------------------------"); + GameData.lowestLayer++; + if (GameData.lowestLayer == GameData.ruinSize) + { + GD.Print("GAME WON!"); + } } } diff --git a/Scripts/World/Layer.cs b/Scripts/World/Layer.cs index 34438e6..691c5c9 100644 --- a/Scripts/World/Layer.cs +++ b/Scripts/World/Layer.cs @@ -16,6 +16,7 @@ public partial class Layer : Node3D public Vector2I gateCoordinate; public List currentResources; public bool isGateOpen = false; + public List gateIngredients = new(); public override void _Ready() { diff --git a/Scripts/World/World.cs b/Scripts/World/World.cs index 7a2c2e6..ef5712b 100644 --- a/Scripts/World/World.cs +++ b/Scripts/World/World.cs @@ -1,5 +1,6 @@ using Godot; using System.Collections.Generic; +using System.Linq; using static GameData; public partial class World : Node3D @@ -230,6 +231,81 @@ public partial class World : Node3D private void SetGateRequirements() { - + List availableResources = new List(); + List possibleIngredients; + bool canCraft; + double highestCraftTime; + double lowestCraftTime; + foreach (Layer layer in map) + { + highestCraftTime = 0; + lowestCraftTime = double.MaxValue; + possibleIngredients = new List(); + //Step 1: Determine all possible resources for this and all previous layers combined + foreach (string resource in layer.currentResources) + { + if (availableResources.Contains(resource)) continue; + availableResources.Add(resource); + } + //Step 2: Check which items can be crafted with those items, repeat until no further items are added to the list + bool addedNewItem; + do + { + addedNewItem = false; + + foreach (ItemData item in availableItems.Values) + { + if (possibleIngredients.Any(existing => existing.Id == item.Id)) + continue; + + canCraft = item.Inputs.All(input => availableResources.Contains(input.Item)); + + if (!canCraft) + continue; + + possibleIngredients.Add(item); + availableResources.Add(item.Id); + + lowestCraftTime = Mathf.Min(lowestCraftTime, item.CraftTime); + highestCraftTime = Mathf.Max(highestCraftTime, item.CraftTime); + + addedNewItem = true; + } + + } while (addedNewItem); + //Step 3: Choose gate items needed based on crafting time and layer it is for (Lower layers -> More advanced items -> More crafting time) + double goalCraftTime = Mathf.Lerp(lowestCraftTime, highestCraftTime, Mathf.Clamp(layer.level/(float)ruinSize, 0, 1)); + int ingredientAmount = rand.Next(1, 1 + ruinSize / 2); + float craftTimeModifier = 0f; + double craftTimeLower, craftTimeUpper; + for (int i = 0; i < ingredientAmount; i++) + { + craftTimeLower = goalCraftTime - goalCraftTime * craftTimeModifier; + craftTimeUpper = goalCraftTime + goalCraftTime * craftTimeModifier; + + List validIngredients = possibleIngredients + .Where(item => + item.CraftTime >= craftTimeLower && + item.CraftTime <= craftTimeUpper && + !layer.gateIngredients.Any(ingredient => ingredient.Item == item.Id)) + .ToList(); + + if (validIngredients.Count == 0) + { + i--; + craftTimeModifier += 0.05f; + continue; + } + + ItemData item = validIngredients[rand.Next(validIngredients.Count)]; + + layer.gateIngredients.Add(new Ingredient + { + Item = item.Id, + Amount = rand.Next(5 + layer.level, 20 + layer.level) + }); + craftTimeModifier = 0f; + } + } } -} +} \ No newline at end of file