public IMyVoxelFillProperties CreateRandom(int index, MaterialSelectionModel defaultMaterial, IEnumerable<MaterialSelectionModel> materialsCollection, IEnumerable<GenerateVoxelDetailModel> voxelCollection) { int idx; var randomModel = new AsteroidByteFillProperties { Index = index, MainMaterial = defaultMaterial, SecondMaterial = defaultMaterial, ThirdMaterial = defaultMaterial, FourthMaterial = defaultMaterial, FifthMaterial = defaultMaterial, SixthMaterial = defaultMaterial, SeventhMaterial = defaultMaterial, }; // Must be by reference, not value. var largeVoxelFileList = voxelCollection.Where(v => v.FileSize > 100000).ToList(); var smallVoxelFileList = voxelCollection.Where(v => v.FileSize > 0 && v.FileSize < 100000).ToList(); // Random Asteroid. var d = RandomUtil.GetDouble(1, 100); var islarge = false; if (largeVoxelFileList.Count == 0 && smallVoxelFileList.Count == 0) { // no asteroids? You are so screwed. throw new Exception("No valid asteroids found. Re-validate your game cache."); } if (largeVoxelFileList.Count == 0) // empty last list? Force to small list. d = 1; if (smallVoxelFileList.Count == 0) // empty small list? Force to large list. d = 100; if (d > 70) { idx = RandomUtil.GetInt(largeVoxelFileList.Count); randomModel.VoxelFile = largeVoxelFileList[idx]; islarge = true; } else { idx = RandomUtil.GetInt(smallVoxelFileList.Count); randomModel.VoxelFile = smallVoxelFileList[idx]; } // Random Main Material non-Rare. var nonRare = materialsCollection.Where(m => m.IsRare == false).ToArray(); idx = RandomUtil.GetInt(nonRare.Length); randomModel.MainMaterial = nonRare[idx]; int percent; var rare = materialsCollection.Where(m => m.IsRare && m.MinedRatio >= 1).ToList(); var superRare = materialsCollection.Where(m => m.IsRare && m.MinedRatio < 1).ToList(); if (islarge) { // Random 1. Rare. if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); percent = RandomUtil.GetInt(40, 60); randomModel.SecondMaterial = rare[idx]; randomModel.SecondPercent = percent; rare.RemoveAt(idx); } // Random 2. Rare. if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); percent = RandomUtil.GetInt(6, 12); randomModel.ThirdMaterial = rare[idx]; randomModel.ThirdPercent = percent; rare.RemoveAt(idx); } // Random 3. Rare. if (rare.Count > 0) { idx = RandomUtil.GetInt(rare.Count); percent = RandomUtil.GetInt(6, 12); randomModel.ThirdMaterial = rare[idx]; randomModel.ThirdPercent = percent; rare.RemoveAt(idx); } // Random 4. Super Rare. if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); percent = RandomUtil.GetInt(2, 4); randomModel.FourthMaterial = superRare[idx]; randomModel.FourthPercent = percent; superRare.RemoveAt(idx); } // Random 5. Super Rare. if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); percent = RandomUtil.GetInt(1, 3); randomModel.FifthMaterial = superRare[idx]; randomModel.FifthPercent = percent; superRare.RemoveAt(idx); } // Random 6. Super Rare. if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); percent = RandomUtil.GetInt(1, 3); randomModel.SixthMaterial = superRare[idx]; randomModel.SixthPercent = percent; superRare.RemoveAt(idx); } // Random 7. Super Rare. if (superRare.Count > 0) { idx = RandomUtil.GetInt(superRare.Count); percent = RandomUtil.GetInt(1, 3); randomModel.SeventhMaterial = superRare[idx]; randomModel.SeventhPercent = percent; superRare.RemoveAt(idx); } } else // Small Asteroid. { // Random 1. Rare. idx = RandomUtil.GetInt(rare.Count); percent = RandomUtil.GetInt(6, 13); randomModel.SecondMaterial = rare[idx]; randomModel.SecondPercent = percent; // Random 2. Super Rare. idx = RandomUtil.GetInt(superRare.Count); percent = RandomUtil.GetInt(2, 4); randomModel.ThirdMaterial = superRare[idx]; randomModel.ThirdPercent = percent; superRare.RemoveAt(idx); } return randomModel; }