private bool PlaceItem(List <Region> handledDungeons, List <InventoryItemType> insertedItemPool, List <Location> currentLocations, InventoryItemType insertedItem, bool logOrderedItem = false) { if (currentLocations.All(x => x.NeverItems.Contains(insertedItem))) { return(false); } int insertedLocationIndex = romLocations.GetInsertedLocation(currentLocations, insertedItem, random); var insertedLocation = currentLocations[insertedLocationIndex]; bool itemPlaced; if (!handledDungeons.Contains(insertedLocation.Region)) { itemPlaced = GenerateDungeonItems(insertedLocation.Region, insertedItem, logOrderedItem); if (itemPlaced) { handledDungeons.Add(insertedLocation.Region); } } else { itemPlaced = true; insertedLocation.Item = new InventoryItem(insertedItem); } if (itemPlaced) { insertedItemPool.Remove(insertedItem); haveItems.Add(insertedItem); if (logOrderedItem) { log?.AddOrderedItem(currentLocations[insertedLocationIndex]); } } return(itemPlaced); }
private void GenerateItemPositions() { do { var currentLocations = romLocations.GetAvailableLocations(haveItems); var candidateItemList = new List <ItemType>(); // Generate candidate item list foreach (var candidateItem in itemPool) { haveItems.Add(candidateItem); var newLocations = romLocations.GetAvailableLocations(haveItems); if (newLocations.Count > currentLocations.Count) { romLocations.TryInsertCandidateItem(currentLocations, candidateItemList, candidateItem); } haveItems.Remove(candidateItem); } // Grab an item from the candidate list if there are any, otherwise, grab a random item if (candidateItemList.Count > 0) { var insertedItem = candidateItemList[random.Next(candidateItemList.Count)]; itemPool.Remove(insertedItem); haveItems.Add(insertedItem); int insertedLocation = romLocations.GetInsertedLocation(currentLocations, insertedItem, random); currentLocations[insertedLocation].Item = new Item(insertedItem); if (log != null) { log.AddOrderedItem(currentLocations[insertedLocation]); } } else { ItemType insertedItem = romLocations.GetInsertedItem(currentLocations, itemPool, random); itemPool.Remove(insertedItem); haveItems.Add(insertedItem); int insertedLocation = romLocations.GetInsertedLocation(currentLocations, insertedItem, random); currentLocations[insertedLocation].Item = new Item(insertedItem); } } while (itemPool.Count > 0); var unavailableLocations = romLocations.GetUnavailableLocations(haveItems); foreach (var unavailableLocation in unavailableLocations) { unavailableLocation.Item = new Item(ItemType.Nothing); } if (log != null) { log.AddGeneratedItems(romLocations.Locations); } }
private void GenerateItemPositions() { do { var currentLocations = romLocations.GetAvailableLocations(haveItems); var candidateItemList = new List <ItemType>(); // Generate candidate item list foreach (var candidateItem in itemPool) { haveItems.Add(candidateItem); var newLocations = romLocations.GetAvailableLocations(haveItems); if (newLocations.Count > currentLocations.Count) { romLocations.TryInsertCandidateItem(currentLocations, candidateItemList, candidateItem); } haveItems.Remove(candidateItem); } AdjustCandidateItems(candidateItemList, haveItems, romLocations); // Grab an item from the candidate list if there are any, otherwise, grab a random item if (candidateItemList.Count > 0) { var insertedItem = candidateItemList[random.Next(candidateItemList.Count)]; itemPool.Remove(insertedItem); haveItems.Add(insertedItem); int insertedLocation = romLocations.GetInsertedLocation(currentLocations, insertedItem, random); currentLocations[insertedLocation].Item = new Item(insertedItem); log?.AddOrderedItem(currentLocations[insertedLocation]); } else { try { ItemType insertedItem = romLocations.GetInsertedItem(currentLocations, itemPool, random); itemPool.Remove(insertedItem); haveItems.Add(insertedItem); int insertedLocation = romLocations.GetInsertedLocation(currentLocations, insertedItem, random); currentLocations[insertedLocation].Item = new Item(insertedItem); } catch (ArgumentOutOfRangeException) { if (RandomizerVersion.Debug) { using (var writer = new StreamWriter(string.Format("unavailableLocations - {0}.txt", string.Format(romLocations.SeedFileString, seed)))) { var unavailable = romLocations.GetUnavailableLocations(haveItems); writer.WriteLine("Unavailable Locations"); writer.WriteLine("---------------------"); foreach (var location in unavailable.OrderBy(x => x.Name)) { writer.WriteLine(location.Name); } writer.WriteLine(); writer.WriteLine("Have Items"); writer.WriteLine("----------"); foreach (var item in haveItems) { writer.WriteLine(item); } writer.WriteLine(); writer.WriteLine("Item Pool"); writer.WriteLine("---------"); foreach (var item in itemPool) { writer.WriteLine(item); } } } throw; } } } while (itemPool.Count > 0); var unavailableLocations = romLocations.GetUnavailableLocations(haveItems); foreach (var unavailableLocation in unavailableLocations) { unavailableLocation.Item = new Item(ItemType.Nothing); } log?.AddGeneratedItems(romLocations.Locations); log?.AddSpecialLocations(romLocations.SpecialLocations); }