public async Task <IActionResult> GetSpoiler(string seedGuid) { try { var seedData = await context.Seeds.Include(x => x.Worlds).ThenInclude(x => x.Locations).SingleOrDefaultAsync(x => x.Guid == seedGuid); if (seedData != null) { IRandomizer randomizer = seedData.GameId switch { "smz3" => new Randomizer.SMZ3.Randomizer(), _ => new Randomizer.SuperMetroid.Randomizer() }; var itemData = randomizer.GetItems(); var locationData = randomizer.GetLocations(); /* Return 400 Bad Request if someone is trying to get the spoiler for a race rom */ foreach (var world in seedData.Worlds) { try { var settings = JsonSerializer.Deserialize <Dictionary <string, string> >(world.Settings); if (settings["race"] == "true") { return(new StatusCodeResult(400)); } } catch { world.Locations = null; } } /* Generate spoiler location data */ var spoilerLocationData = new List <SpoilerLocationData>(); foreach (var world in seedData.Worlds) { foreach (var location in world.Locations) { spoilerLocationData.Add(new SpoilerLocationData { LocationId = location.LocationId, LocationName = locationData[location.LocationId].Name, LocationType = locationData[location.LocationId].Type, LocationRegion = locationData[location.LocationId].Region, LocationArea = locationData[location.LocationId].Area, ItemId = location.ItemId, ItemName = itemData[location.ItemId].Name, WorldId = world.WorldId, ItemWorldId = location.ItemWorldId, }); } world.Locations = null; world.Patch = null; } return(new OkObjectResult(new SpoilerData { Seed = seedData, Locations = spoilerLocationData })); } else { return(new StatusCodeResult(404)); } } catch { return(new StatusCodeResult(500)); } }