public void fillMoonPropabilities() { string jsonString = File.ReadAllText("./SystemGenerator/Workers/Version2/Data/SystemMoons.json"); dynamic files = JsonConvert.DeserializeObject(jsonString); List <MoonChance> chances = new List <MoonChance>(); foreach (var f in files.moons) { MoonChance chance = new MoonChance { type = f.moon.planetType, circle = f.moon.circle, probability = f.moon.probability }; if (chances.Any(e => e.circle == chance.circle)) { chance.probStart = chances.Last(e => e.circle == chance.circle).probEnd; } chance.probEnd = chance.probStart + chance.probability; chances.Add(chance); if (!circleMoonChances.ContainsKey(chance.circle)) { circleMoonChances.Add(chance.circle, new List <MoonChance>()); } circleMoonChances[chance.circle].Add(chance); } }
public int getMoonType(int _circle) { int random = RandomHelper.GetRandomInt(0, 100); if (!circleMoonChances.ContainsKey(_circle)) { return(0); } if (!circleMoonChances[_circle].Any(e => e.probStart <= random && e.probEnd > random)) { return(0); } MoonChance moon = circleMoonChances[_circle].First(e => e.probStart <= random && e.probEnd > random); return(moonObjectId(moon.type)); }