Beispiel #1
0
        /// <summary>
        /// The initial generation of the dictionary of dialog replacement based on the currently randomized item locations
        /// </summary>
        /// <returns>A Dictionary containing keys of locationdialogID and values of replacementdialogID</returns>
        ///
        public static Dictionary <string, string> GenerateDialogMappingforItems()
        {
            Dictionary <string, string>          dialogmap         = new Dictionary <string, string>();
            Dictionary <EItems, string>          itemToDialogIDMap = GetDialogIDtoItems();
            Dictionary <LocationRO, RandoItemRO> current           = RandomizerStateManager.Instance.CurrentLocationToItemMapping;

            /* OLD
             * foreach (KeyValuePair<LocationRO, RandoItemRO> KVP in current)
             * {
             *  Console.WriteLine($"Dialog mapping -- {KVP.Key.PrettyLocationName}");
             *  EItems LocationChecked = (EItems)Enum.Parse(typeof(EItems), KVP.Key.PrettyLocationName);
             *  RandoItemRO ItemActuallyFound = KVP.Value;
             *
             *  if (ItemtoDialogIDMap.ContainsKey(LocationChecked) && ItemtoDialogIDMap.ContainsKey(ItemActuallyFound.Item))
             *  {
             *      dialogmap.Add(ItemtoDialogIDMap[LocationChecked], ItemtoDialogIDMap[ItemActuallyFound.Item]);
             *      Console.WriteLine($"We mapped item dialog {ItemtoDialogIDMap[ItemActuallyFound.Item]} to the location {ItemtoDialogIDMap[LocationChecked]}");
             *  }
             * }
             */

            //I am gonna keep the mappings limited to basic locations since the advanced locations are handled by another process.
            foreach (LocationRO location in RandomizerConstants.GetRandoLocationList())
            {
                Console.WriteLine($"Dialog mapping -- {location.PrettyLocationName}");
                EItems      locationChecked   = (EItems)Enum.Parse(typeof(EItems), location.PrettyLocationName);
                RandoItemRO itemActuallyFound = current[location];

                if (itemToDialogIDMap.ContainsKey(locationChecked) && itemToDialogIDMap.ContainsKey(itemActuallyFound.Item))
                {
                    dialogmap.Add(itemToDialogIDMap[locationChecked], itemToDialogIDMap[itemActuallyFound.Item]);
                    Console.WriteLine($"We mapped item dialog {itemToDialogIDMap[itemActuallyFound.Item]} to the location {itemToDialogIDMap[locationChecked]}");
                }
            }

            return(dialogmap);
        }
        /// <summary>
        /// Parses the mappings string from the seed to create the mappings collection for this seed.
        /// </summary>
        /// <param name="seed">Seed whos mappings we wish to parse.</param>
        /// <returns>Collection of mappings.</returns>
        public static Dictionary <LocationRO, RandoItemRO> ParseLocationToItemMappings(SeedRO seed)
        {
            //Prep
            Dictionary <LocationRO, RandoItemRO> mappings          = new Dictionary <LocationRO, RandoItemRO>();
            Dictionary <string, LocationRO>      officialLocations = new Dictionary <string, LocationRO>();
            Dictionary <string, RandoItemRO>     officialItems     = new Dictionary <string, RandoItemRO>();

            //Fill official collections for easy searching
            foreach (LocationRO location in RandomizerConstants.GetRandoLocationList())
            {
                officialLocations.Add(location.LocationName, location);
            }

            foreach (RandoItemRO item in RandomizerConstants.GetRandoItemList())
            {
                officialItems.Add(item.Name, item);
            }

            foreach (RandoItemRO item in RandomizerConstants.GetNotesList())
            {
                officialItems.Add(item.Name, item);
            }

            //loading for advanced seeds
            if (seed.Settings[SettingType.Difficulty].Equals(SettingValue.Advanced))
            {
                //locations
                foreach (LocationRO location in RandomizerConstants.GetAdvancedRandoLocationList())
                {
                    officialLocations.Add(location.LocationName, location);
                }
                //items
                foreach (RandoItemRO item in RandomizerConstants.GetAdvancedRandoItemList())
                {
                    officialItems.Add(item.Name, item);
                }
            }

            //Split up all the mappings
            string[] mappingsArr = seed.MappingInfo.Split(',');

            foreach (string mappingStr in mappingsArr)
            {
                //Split off the location and item string
                string[]    mappingArr = mappingStr.Split('~');
                LocationRO  location   = null;
                RandoItemRO item       = new RandoItemRO();


                //Get the LocationRO and RandoItemRO from the list of known items
                if (officialLocations.ContainsKey(mappingArr[0]))
                {
                    location = officialLocations[mappingArr[0]];
                }
                else
                {
                    //If for some reason something that could not be mapped to an official location, let's fail for now.
                    throw new RandomizerException($"Location named '{mappingArr[0]}' could not be located in collection of official locations.");
                }

                if (officialItems.ContainsKey(mappingArr[1]))
                {
                    item = officialItems[mappingArr[1]];
                }
                else
                {
                    //If for some reason something that could not be mapped to an official location, let's fail for now.
                    throw new RandomizerException($"Item named '{mappingArr[1]}' could not be located in collection of official items.");
                }

                //We get here, then we are good. Save off this mapping and move on.
                mappings.Add(location, item);
            }

            Console.WriteLine("Mapping parsed successfully!");
            return(mappings);
        }