예제 #1
0
        /*TODO Maybe use later, for now will not take a file name
         * //On submit of rando file name
         * bool OnEnterRandoFileName(string fileName)
         * {
         *  Console.WriteLine($"File name received: {fileName}");
         *  randoFileName = fileName;
         *
         *  //Pop up next input for which file slot to create this file in
         *  TextEntryPopup fileSlotPopup = InitTextEntryPopup(generateSeedButton.addedTo, "Which save slot would you like to start a rando seed?", (entry) => OnEnterRandoFileSlot(entry), 1, null, CharsetFlags.Number);
         *  fileSlotPopup.onBack += () =>
         *  {
         *      fileSlotPopup.gameObject.SetActive(false);
         *      generateSeedButton.textEntryPopup.gameObject.SetActive(true);
         *      generateSeedButton.textEntryPopup.StartCoroutine(generateSeedButton.textEntryPopup.BackWhenBackButtonReleased());
         *  };
         *  generateSeedButton.textEntryPopup.gameObject.SetActive(false);
         *
         *  //Initialize the file slot popup
         *  fileSlotPopup.Init(string.Empty);
         *  fileSlotPopup.gameObject.SetActive(true);
         *  fileSlotPopup.transform.SetParent(generateSeedButton.addedTo.transform.parent);
         *  generateSeedButton.addedTo.gameObject.SetActive(false);
         *  Canvas.ForceUpdateCanvases();
         *  fileSlotPopup.initialSelection.GetComponent<UIObjectAudioHandler>().playAudio = false;
         *  EventSystem.current.SetSelectedGameObject(fileSlotPopup.initialSelection);
         *  fileSlotPopup.initialSelection.GetComponent<UIObjectAudioHandler>().playAudio = true;
         *  return false;
         * }
         */

        ///On submit of rando file location
        bool OnEnterFileSlot(string fileSlot)
        {
            Console.WriteLine($"In Method: OnEnterFileSlot. Provided value: '{fileSlot}'");
            Console.WriteLine($"Received file slot number: {fileSlot}");
            int slot = Convert.ToInt32(fileSlot);

            if (slot < 1 || slot > 3)
            {
                Console.WriteLine($"Invalid slot number provided: {slot}");
                return(false);
            }

            //Load in mappings and save them to the state

            //Load encoded seed information
            string encodedSeedInfo = ItemRandomizerUtil.LoadMappingsFromFile(slot);

            Console.WriteLine($"File reading complete. Received the following encoded seed info: '{encodedSeedInfo}'");
            string decodedSeedInfo = ItemRandomizerUtil.DecryptSeedInfo(encodedSeedInfo);

            Console.WriteLine($"Decryption complete. Received the following seed info: '{decodedSeedInfo}'");

            SeedRO seedRO = ItemRandomizerUtil.ParseSeed(slot, decodedSeedInfo);

            randoStateManager.AddSeed(seedRO);

            //Save
            Save.seedData = randomizerSaveMethod.GenerateSaveData();

            return(true);
        }
예제 #2
0
        public string GenerateSaveData()
        {
            StringBuilder modValue = new StringBuilder();

            for (int i = 1; i <= 3; i++)
            {
                SeedRO seed = stateManager.GetSeedForFileSlot(i);
                modValue.Append("" + RANDO_OPTION_VALUE_DELIM + seed.Seed + RANDO_OPTION_TYPE_DELIM + seed.SeedType);

                foreach (SettingType setting in seed.Settings.Keys)
                {
                    modValue.Append("" + RANDO_OPTION_SETTING_DELIM + setting + RANDO_OPTION_SETTING_VALUE_DELIM + seed.Settings[setting]);
                }
                //Capturing collected items per seed
                if (seed.CollectedItems.Count > 0)
                {
                    modValue.Append("" + RANDO_OPTION_SETTING_DELIM + "CollectedItems=");
                    foreach (RandoItemRO collectedItem in seed.CollectedItems)
                    {
                        modValue.Append("" + collectedItem + RANDO_OPTION_ITEM_DELIM);
                    }
                    //Shaving off the last ','
                    modValue.Length--;
                }
                //Add seed info
                if (seed.MappingInfo != null && !seed.MappingInfo.Equals(""))
                {
                    modValue.Append("" + RANDO_OPTION_SETTING_DELIM + "Mappings=" + seed.MappingInfo);
                }
            }

            Console.WriteLine($"Saving seed data: '{modValue}'");

            return(modValue.ToString());
        }
예제 #3
0
 public SeedRO GetSeedForFileSlot(int fileSlot)
 {
     if (!seeds.ContainsKey(fileSlot))
     {
         seeds[fileSlot] = new SeedRO(fileSlot, SeedType.None, 0, null, null, null);
     }
     return(seeds[fileSlot]);
 }
예제 #4
0
 /// <summary>
 /// Reset's the state's seed for the provided file slot. This will replace the seed with an empty seed, telling the mod this fileslot is not randomized.
 /// </summary>
 public void ResetSeedForFileSlot(int fileSlot)
 {
     //Simply keeping resetting logic here in case I want to change it i'll only do so here
     Console.WriteLine($"Resetting file slot '{fileSlot}'");
     if (seeds.ContainsKey(fileSlot))
     {
         seeds[fileSlot] = new SeedRO(fileSlot, SeedType.None, 0, null, null, null);
     }
     Console.WriteLine("File slot reset complete.");
 }
        /// <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);
        }
예제 #6
0
 /// <summary>
 /// Add seed to state's collection of seeds.
 /// </summary>
 public void AddSeed(SeedRO seed)
 {
     seeds[seed.FileSlot] = seed;
 }