using System.Collections.Generic; using Godot; public static 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; foreach (string resource in resources.Keys) { totalWeight += GetWeight(resource, layer); } float randomWeight = (float)(GameData.rand.NextDouble() * totalWeight); float cumulative = 0f; foreach (string resource in resources.Keys) { cumulative += GetWeight(resource, layer); if (randomWeight <= cumulative) return resource; } return "stone"; } private static float GetWeight(string resource, int layer) { return Mathf.Lerp(weights[resource][0], weights[resource][1], layer); } }