using System.Collections.Generic; using Godot; public class ResourceDistributor { public static Dictionary resources = ResourceLoader.LoadResourceSymbols(); public static Dictionary weights = ResourceLoader.LoadResourceWeights(); public static string GetResource(int layer) { return ChooseWeighted(layer); } private static string ChooseWeighted(int layer) { float totalWeight = 0f; float weightLerp; foreach (string resource in resources.Keys) { weightLerp = Mathf.Lerp(weights[resource][0], weights[resource][1], layer); totalWeight += weightLerp; } float r = (float)(GameData.rand.NextDouble() * totalWeight); float cumulative = 0f; foreach (string resource in resources.Keys) { weightLerp = Mathf.Lerp(weights[resource][0], weights[resource][1], layer); cumulative += weightLerp; if (r <= cumulative) return resource; } return "stone"; } }