public static int GetWeightedRandomIndex(this HediffComp_RandySpawnUponDeath comp, List <int> AlreadyPickedOptions) { if (!comp.Props.settings.HasSomethingToSpawn) { return(-1); } List <ThingSettings> TSList; if (comp.HasColorCondition) { TSList = comp.ThingSettingsWithColor(); } else { TSList = comp.FullOptionList; } if (!AlreadyPickedOptions.NullOrEmpty()) { TSList = comp.ThingSettingsWithExclusion(TSList, AlreadyPickedOptions); } float DiceThrow = Rand.Range(0, comp.ThingsTotalWeight(TSList)); for (int i = 0; i < TSList.Count; i++) { if ((DiceThrow -= TSList[i].weight) < 0) { if (comp.MyDebug) { Log.Warning("GetWeightedRandomIndex : returning thing " + i); } if (AlreadyPickedOptions.NullOrEmpty() && !comp.HasColorCondition) { return(i); } else { int normalizedIndex = comp.Props.settings.things.IndexOf(TSList[i]); if (comp.MyDebug) { Log.Warning("GetWeightedRandomIndex : returning thing " + i + " normalized:" + normalizedIndex); } return(normalizedIndex); } } } if (comp.MyDebug) { Log.Warning("GetWeightedRandomIndex : failed to return proper index, returning -1"); } return(-1); }