Finished first EA Version #1

Merged
Nicola merged 110 commits from dev into main 2026-05-19 20:01:13 +02:00
4 changed files with 90 additions and 4 deletions
Showing only changes of commit 213d0aed97 - Show all commits
+1
View File
@@ -524,6 +524,7 @@ layout_mode = 2
tooltip_text = "Menu (ESC)" tooltip_text = "Menu (ESC)"
texture_normal = ExtResource("12_3so38") 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="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/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"] [connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Buttons/Compile" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="CompileProgram"]
+10 -2
View File
@@ -169,11 +169,19 @@ public partial class UIHandler : Control
{ {
currentLayer.Text = $"Current layer: {GameData.currentLayer}/{GameData.ruinSize}"; currentLayer.Text = $"Current layer: {GameData.currentLayer}/{GameData.ruinSize}";
deepestLayer.Text = $"Deepest layer: {GameData.lowestLayer}"; deepestLayer.Text = $"Deepest layer: {GameData.lowestLayer}";
} }
public void UnlockLayer() 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!");
}
} }
} }
+1
View File
@@ -16,6 +16,7 @@ public partial class Layer : Node3D
public Vector2I gateCoordinate; public Vector2I gateCoordinate;
public List<string> currentResources; public List<string> currentResources;
public bool isGateOpen = false; public bool isGateOpen = false;
public List<Ingredient> gateIngredients = new();
public override void _Ready() public override void _Ready()
{ {
+76
View File
@@ -1,5 +1,6 @@
using Godot; using Godot;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using static GameData; using static GameData;
public partial class World : Node3D public partial class World : Node3D
@@ -230,6 +231,81 @@ public partial class World : Node3D
private void SetGateRequirements() private void SetGateRequirements()
{ {
List<string> availableResources = new List<string>();
List<ItemData> possibleIngredients;
bool canCraft;
double highestCraftTime;
double lowestCraftTime;
foreach (Layer layer in map)
{
highestCraftTime = 0;
lowestCraftTime = double.MaxValue;
possibleIngredients = new List<ItemData>();
//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<ItemData> 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;
}
}
} }
} }