public override int GetHashCode() { int hash = 1; if (ScoutName.Length != 0) { hash ^= ScoutName.GetHashCode(); } if (TrainerId != 0UL) { hash ^= TrainerId.GetHashCode(); } if (DropRate != 0) { hash ^= DropRate.GetHashCode(); } if (DisplayOrder != 0) { hash ^= DisplayOrder.GetHashCode(); } if (U5 != 0) { hash ^= U5.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public async Task AddDropRate(string itemName, string odds, [Remainder] string source) { await Context.Message.DeleteAsync(); try { var input = string.Join(" ", itemName, odds, source); if (!DropRate.TryParse(input, out var dropRate)) { await ReplyAsync($"Sorry {Context.Message.Author.Username}, that drop rate is in an incorrect format"); } else if (_contribService.Exists(dropRate)) { await ReplyAsync($"Sorry {Context.Message.Author.Username}, these odds already exist"); var result = new DropRateResult { ItemName = dropRate.ItemName, DropRates = new[] { _contribService.FindByNaturalKey(dropRate) as DropRate } }; await ReplyAsync(result); } else { await _contribService.AddContrib(dropRate, Context.Message.Author); await ReplyAsync($"Ok {Context.Message.Author.Username}, the drop rate has been added"); } } catch (Exception ex) { var userMessage = $"Sorry {Context.Message.Author.Username}, I was unable to add that drop rate"; await HandleErrorAsync(userMessage, ex); } }
public static ItemData GetFromDropTable(DropRate rate) { if (!initialized || dropTable[rate].Count == 0) { Init(); } return(dropTable[rate][Random.Range(0, dropTable[rate].Count)]); }
public static void SpawnRandomObject(Tile tile) { int numStacksAlreadyPlaced = 0; Vector2Int tilePos = new Vector2Int(tile.x, tile.y); var containingBiomes = tile.map.biomes.Where(b => b.area.Contains(tilePos)).ToList(); var subBiomes = new List <Biome>(); foreach (var biome in containingBiomes) { GatherBiomes(tilePos, ref subBiomes, biome); } containingBiomes.AddRange(subBiomes); float totalProbability = 0; List <BiomeRate> viableDrops = new List <BiomeRate>(); foreach (var biome in containingBiomes) { totalProbability += biome.biomeType.nothingProbability; if (biome.biomeType.nothingProbability != 0) { var biomeRate = new BiomeRate(biome, null); viableDrops.Add(biomeRate); } foreach (var dropRate in biome.biomeType.objects) { if (dropRate.requireSpawnable && !tile.AllowsSpawn()) { continue; } if (dropRate.onlySpawnOn != null && dropRate.onlySpawnOn.Length != 0) { if (!tile.ContainsObjectOfType(dropRate.onlySpawnOn)) { continue; } } if (dropRate.dontSpawnOn != null && dropRate.dontSpawnOn.Length != 0) { if (tile.ContainsObjectOfType(dropRate.dontSpawnOn)) { continue; } } numStacksAlreadyPlaced = 0; biome.stacksSpawned.TryGetValue(dropRate.item, out numStacksAlreadyPlaced); if (numStacksAlreadyPlaced < dropRate.maxQuantityPerBiome || dropRate.maxQuantityPerBiome == -1) { var biomeRate = new BiomeRate(biome, dropRate); viableDrops.Add(biomeRate); totalProbability += dropRate.probability; } } } float r = UnityEngine.Random.Range(0, totalProbability); DropRate typeOfObjectToSpawn = null; float currentProbability = 0; float previousProbability = 0; foreach (var biomeRate in viableDrops) { Biome biome = biomeRate.biome; BiomeDropRate dropRate = biomeRate.dropRate; if (dropRate == null) { previousProbability = currentProbability; currentProbability += biome.biomeType.nothingProbability; } else { previousProbability = currentProbability; currentProbability += dropRate.probability; } if (r >= previousProbability && r < currentProbability) { if (dropRate == null) { // Spawn nothing break; } else { bool anyStacksPlaced = biome.stacksSpawned.TryGetValue(dropRate.item, out numStacksAlreadyPlaced); if (anyStacksPlaced) { biome.stacksSpawned[dropRate.item]++; } else { biome.stacksSpawned[dropRate.item] = 1; } typeOfObjectToSpawn = dropRate; break; } } } if (typeOfObjectToSpawn != null) { int quantity = UnityEngine.Random.Range(typeOfObjectToSpawn.minQuantity, typeOfObjectToSpawn.maxQuantity + 1); tile.SpawnAndAddObject(typeOfObjectToSpawn.item, quantity); } }
public ItemData(JToken jToken) { Name = jToken[Keys.KEY_NAME].Value <string>(); Description = jToken[Keys.KEY_DESCRIPTION].Value <string>(); DropRate = (DropRate)jToken[Keys.KEY_DROPRATE].Value <int>(); }