Ejemplo n.º 1
0
        private void InitializeStatValues()
        {
            bool setTamingFood = TamingFoodData.TryLoadDefaultFoodData(out specialFoodData);

            if (specialFoodData == null)
            {
                specialFoodData = new Dictionary <string, TamingData>();
            }
            _V.specialFoodData = specialFoodData;

            const string defaultFoodNameKey = "default";

            if (setTamingFood && specialFoodData.ContainsKey(defaultFoodNameKey))
            {
                _V.defaultFoodData = specialFoodData[defaultFoodNameKey].specialFoodValues;
            }
            else
            {
                _V.defaultFoodData = new Dictionary <string, TamingFood>();
            }

            //var speciesWoFoodData = new List<string>(); // to determine which species has no food data yet
            _V.speciesNames = new List <string>();
            foreach (Species sp in _V.species)
            {
                _V.speciesNames.Add(sp.name);
                if (setTamingFood && specialFoodData.ContainsKey(sp.name))
                {
                    sp.taming.eats              = specialFoodData[sp.name].eats;
                    sp.taming.eatsAlsoPostTame  = specialFoodData[sp.name].eatsAlsoPostTame;
                    sp.taming.specialFoodValues = specialFoodData[sp.name].specialFoodValues;
                }
                //if (sp.IsDomesticable && !specialFoodData.ContainsKey(sp.name)) speciesWoFoodData.Add(sp.name);
            }
            //System.Windows.Forms.Clipboard.SetText(speciesWoFoodData.Any() ? string.Join("\n", speciesWoFoodData) : string.Empty);

            OrderSpeciesAndApplyCustomVariants();

            _V.LoadAliases();
            _V.UpdateSpeciesBlueprintDictionaries();
            _V.loadedModsHash = NoModsHash;

            // transfer extra loaded objects from the old object to the new one
            _V.modsManifest             = modsManifest;
            _V.serverMultipliersPresets = serverMultipliersPresets;
        }
Ejemplo n.º 2
0
        private void InitializeStatValues()
        {
            bool setTamingFood = TamingFoodData.TryLoadDefaultFoodData(out specialFoodData);

            if (specialFoodData == null)
            {
                specialFoodData = new Dictionary <string, TamingData>();
            }
            _V.specialFoodData = specialFoodData;

            if (setTamingFood && specialFoodData.ContainsKey("default"))
            {
                _V.defaultFoodData = specialFoodData["default"].specialFoodValues;
            }
            else
            {
                _V.defaultFoodData = new Dictionary <string, TamingFood>();
            }

            _V.speciesNames = new List <string>();
            foreach (Species sp in _V.species)
            {
                _V.speciesNames.Add(sp.name);
                if (setTamingFood && specialFoodData.ContainsKey(sp.name))
                {
                    sp.taming.eats = specialFoodData[sp.name].eats;
                    sp.taming.specialFoodValues = specialFoodData[sp.name].specialFoodValues;
                }
            }

            OrderSpeciesAndApplyCustomVariants();

            _V.LoadAliases();
            _V.UpdateSpeciesBlueprintDictionaries();
            _V.loadedModsHash = NoModsHash;

            // transfer extra loaded objects from the old object to the new one
            _V.modsManifest             = modsManifest;
            _V.serverMultipliersPresets = serverMultipliersPresets;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the values from the default file.
        /// </summary>
        /// <returns></returns>
        public bool LoadValues()
        {
            try
            {
                using (FileStream file = FileService.GetJsonFileStream(Path.Combine(FileService.ValuesFolder, FileService.ValuesJson)))
                {
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Values)
                                                                                    , new DataContractJsonSerializerSettings()
                    {
                        UseSimpleDictionaryFormat = true
                    }
                                                                                    );
                    var tmpV = (Values)ser.ReadObject(file);
                    if (tmpV.format != CURRENT_FORMAT_VERSION)
                    {
                        throw new FormatException("Unhandled format version");
                    }
                    _V = tmpV;
                }
            }
            catch (FileNotFoundException)
            {
                if (MessageBox.Show($"Values-File {FileService.ValuesJson} not found. " +
                                    "ARK Smart Breeding will not work properly without that file.\n\n" +
                                    "Do you want to visit the releases page to redownload it?",
                                    "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start(Updater.ReleasesUrl);
                }
                return(false);
            }
            catch (FormatException)
            {
                MessageBox.Show($"File {FileService.ValuesJson} is a format that is unsupported in this version of ARK Smart Breeding." +
                                "\n\nTry updating to a newer version.",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(NullReferenceException))
                {
                    throw;
                }
                MessageBox.Show($"File {FileService.ValuesJson} couldn't be opened or read.\nErrormessage:\n\n" + e.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            bool setTamingFood = TamingFoodData.TryLoadDefaultFoodData(out specialFoodData);

            if (specialFoodData == null)
            {
                specialFoodData = new Dictionary <string, TamingData>();
            }
            _V.specialFoodData = specialFoodData;

            if (setTamingFood && specialFoodData.ContainsKey("default"))
            {
                _V.defaultFoodData = specialFoodData["default"].specialFoodValues;
            }
            else
            {
                _V.defaultFoodData = new Dictionary <string, TamingFood>();
            }

            _V.speciesNames = new List <string>();
            foreach (Species sp in _V.species)
            {
                _V.speciesNames.Add(sp.name);
                if (setTamingFood && specialFoodData.ContainsKey(sp.name))
                {
                    sp.taming.eats = specialFoodData[sp.name].eats;
                    sp.taming.specialFoodValues = specialFoodData[sp.name].specialFoodValues;
                }
            }

            OrderSpecies();

            _V.LoadAliases();
            _V.UpdateSpeciesBlueprintDictionaries();
            _V.loadedModsHash = CreatureCollection.CalculateModListHash(new List <Mod>());

            if (_V.modsManifest == null)
            {
                if (modsManifest != null)
                {
                    _V.modsManifest = modsManifest;
                }
                else
                {
                    _V.LoadModsManifest();
                }
            }

            if (serverMultipliersPresets != null)
            {
                _V.serverMultipliersPresets = serverMultipliersPresets;
            }
            else if (!ServerMultipliersPresets.TryLoadServerMultipliersPresets(out _V.serverMultipliersPresets))
            {
                MessageBox.Show("The file with the server multipliers couldn't be loaded. Changed settings, e.g. for the singleplayer will be not available.\nIt's recommended to download the application again.",
                                "Server multiplier file not loaded.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(true);
        }