private static void TakeItemsFromWeightedSelection(WeightedSelection <ItemIndex> weightedSelection, ref CostTypeDef.PayCostContext context, ref List <ItemIndex> itemsToTake, int halfTotalItemCount) { while (weightedSelection.Count > 0 && itemsToTake.Count < halfTotalItemCount) { int choiceIndex = weightedSelection.EvaluateToChoiceIndex(context.rng.nextNormalizedFloat); WeightedSelection <ItemIndex> .ChoiceInfo choice = weightedSelection.GetChoice(choiceIndex); ItemIndex value = choice.value; int num = (int)choice.weight; num--; if (num <= 0) { weightedSelection.RemoveChoice(choiceIndex); } else { weightedSelection.ModifyChoiceWeight(choiceIndex, (float)num); } itemsToTake.Add(value); } }