public IEnumerable <T> Create(int level) { // modify the level randomly int walkedLevel = Rng.WalkLevel(level).Clamp(1, 100); // choose up to it (best of two tries) int choiceValue = Math.Max(Rng.IntInclusive(walkedLevel), Rng.IntInclusive(walkedLevel)); IDrop <T> dropped = null; // count through to find the last one at least the random level foreach (DropChoice choice in Choices) { if (choiceValue >= choice.Odds) { dropped = choice.Drop; } } // drop it if we have one if (dropped != null) { // if the choice was less than the max, then bump up the subsequent level a bit to compensate int bonus = (walkedLevel - choiceValue) / 4; level = Math.Max(Game.MaxDepth, level + bonus); foreach (var item in dropped.Create(level)) { yield return(item); } } }
public IEnumerable <T> Create(int level) { // modify the level randomly float choiceValue = Rng.WalkLevel(level).Clamp(1, 100); IDrop <T> dropped = null; // count through to find the last one at least the random level foreach (DropChoice choice in Choices) { if (choiceValue >= choice.Odds) { dropped = choice.Drop; } } // drop it if we have one if (dropped != null) { foreach (var item in dropped.Create(level)) { yield return(item); } } }
public IEnumerable <T> Create(int level) { // use the actual total in case the data adds up to more than 100 float totalOdds = Math.Max(TotalOdds, Choices.Sum((choice) => choice.Odds)); float choiceValue = Rng.Float(TotalOdds); IDrop <T> dropped = null; // count through to find the chosen one foreach (DropChoice choice in Choices) { choiceValue -= choice.Odds; if (choiceValue <= 0) { dropped = choice.Drop; break; } } // drop it if we have one if (dropped != null) { foreach (var item in dropped.Create(level)) { yield return(item); } } }
public static T CreateOne <T>(this IDrop <T> drop, int level) { foreach (T item in drop.Create(level)) { return(item); } return(default(T)); }