Added gate unlock generation and simple Game Won print
This commit is contained in:
@@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public partial class Layer : Node3D
|
||||
public Vector2I gateCoordinate;
|
||||
public List<string> currentResources;
|
||||
public bool isGateOpen = false;
|
||||
public List<Ingredient> gateIngredients = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
+78
-2
@@ -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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user