public TreasureResult GenerateTreasure(int maxValue = -1) { // Get the lower and upper bounds int minBound = Int32.MaxValue, maxBound = Int32.MinValue; foreach (TreasureEntry e in entries) { if (e.LowerBound < minBound) { minBound = e.LowerBound; } if (e.HigherBound > maxBound) { maxBound = e.HigherBound; } } TreasureResult result = null; do { // Get a random value and see which entry it matches int randInt = rand.Next(minBound, maxBound); TreasureEntry entry = null; for (int i = 0; i < entries.Count && entry == null; i++) { if (randInt >= entries[i].LowerBound && randInt <= entries[i].HigherBound) { entry = entries[i]; } } randInt = rand.Next(entry.MinWorth, entry.MaxWorth); string desc = entry.Examples[rand.Next(entry.Examples.Count)]; result = new TreasureResult(randInt, desc); }while (maxValue != -1 && result.Worth > maxValue); return(result); }
public TreasureResult GenerateTreasure(int maxValue = -1) { // Get the lower and upper bounds int minBound = Int32.MaxValue, maxBound = Int32.MinValue; foreach (TreasureEntry e in entries) { if (e.LowerBound < minBound) minBound = e.LowerBound; if (e.HigherBound > maxBound) maxBound = e.HigherBound; } TreasureResult result = null; do { // Get a random value and see which entry it matches int randInt = rand.Next(minBound, maxBound); TreasureEntry entry = null; for (int i = 0; i < entries.Count && entry == null; i++) { if (randInt >= entries[i].LowerBound && randInt <= entries[i].HigherBound) { entry = entries[i]; } } randInt = rand.Next(entry.MinWorth, entry.MaxWorth); string desc = entry.Examples[rand.Next(entry.Examples.Count)]; result = new TreasureResult(randInt, desc); } while ( maxValue != -1 && result.Worth > maxValue); return result; }