Exemplo 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;
        }
Exemplo 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;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads extra values-files that can add species values or modify existing ones
        /// </summary>
        public bool LoadModValues(List <string> modValueFileNames, bool showResults, out List <Mod> mods)
        {
            loadedModsHash = 0;
            List <Values> modifiedValues = new List <Values>();

            mods = new List <Mod>();
            if (modValueFileNames == null)
            {
                return(false);
            }

            CheckAndUpdateModFiles(modValueFileNames);

            foreach (string mf in modValueFileNames)
            {
                string filename = FileService.GetJsonPath(Path.Combine(FileService.ValuesFolder, mf));

                if (TryLoadValuesFile(filename, setModFileName: true, out Values modValues))
                {
                    modifiedValues.Add(modValues);
                }
            }

            int speciesUpdated = 0;
            int speciesAdded   = 0;

            // update data if existing
            foreach (Values modValues in modifiedValues)
            {
                // if mods are loaded multiple times, only keep the last
                mods.Remove(modValues.mod);
                mods.Add(modValues.mod);

                // species
                if (modValues.species != null)
                {
                    foreach (Species sp in modValues.species)
                    {
                        if (string.IsNullOrWhiteSpace(sp.blueprintPath))
                        {
                            continue;
                        }

                        Species originalSpecies = SpeciesByBlueprint(sp.blueprintPath);
                        if (originalSpecies != null)
                        {
                            _V.species.Remove(originalSpecies);
                        }
                        _V.species.Add(sp);
                        sp.Mod = modValues.mod;
                        speciesAdded++;

                        if (!blueprintToSpecies.ContainsKey(sp.blueprintPath))
                        {
                            blueprintToSpecies.Add(sp.blueprintPath, sp);
                        }
                    }
                }

                // TODO support for mod colors
            }

            loadedModsHash = CreatureCollection.CalculateModListHash(mods);

            if (speciesUpdated == 0 && speciesAdded == 0)
            {
                return(true); // nothing changed
            }
            // sort new species
            OrderSpecies();

            // mod-fooddata TODO

            _V.LoadAliases();
            _V.UpdateSpeciesBlueprintDictionaries();

            if (showResults)
            {
                MessageBox.Show($"The following mods were loaded:\n{string.Join(", ", modifiedValues.Select(m => m.mod.title).ToArray())}\n\n"
                                + $"Species with changed stats: {speciesUpdated}\nSpecies added: {speciesAdded}",
                                "Additional Values succesfully added", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return(true);
        }
Exemplo n.º 4
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);
        }