public static async Task ImportCollectionFromSavegame(CreatureCollection creatureCollection, string filename, string serverName) { string[] rafts = { "Raft_BP_C", "MotorRaft_BP_C", "Barge_BP_C" }; (GameObjectContainer gameObjectContainer, float gameTime) = await readSavegameFile(filename); IEnumerable <GameObject> tamedCreatureObjects = gameObjectContainer .Where(o => o.IsCreature() && o.IsTamed() && !o.IsUnclaimedBaby() && !rafts.Contains(o.ClassString)); if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportTribeNameFilter)) { string[] filters = Properties.Settings.Default.ImportTribeNameFilter.Split(',') .Select(s => s.Trim()) .Where(s => !string.IsNullOrEmpty(s)) .ToArray(); tamedCreatureObjects = tamedCreatureObjects.Where(o => { string tribeName = o.GetPropertyValue <string>("TribeName", defaultValue: string.Empty); return(filters.Any(filter => tribeName.Contains(filter))); }); } ImportSavegame importSavegame = new ImportSavegame(gameTime); int? wildLevelStep = creatureCollection.getWildLevelStep(); List <Creature> creatures = tamedCreatureObjects.Select(o => importSavegame.convertGameObject(o, wildLevelStep)).ToList(); importCollection(creatureCollection, creatures, serverName); }
private static void importCollection(CreatureCollection creatureCollection, List <Creature> newCreatures, string serverName) { if (creatureCollection.changeCreatureStatusOnSavegameImport) { // mark creatures that are no longer present as unavailable var removedCreatures = creatureCollection.creatures.Where(c => c.status == CreatureStatus.Available && c.server == serverName).Except(newCreatures); foreach (var c in removedCreatures) { c.status = CreatureStatus.Unavailable; } // mark creatures that re-appear as available (due to server transfer / obelisk / etc) var readdedCreatures = creatureCollection.creatures.Where(c => c.status == CreatureStatus.Unavailable || c.status == CreatureStatus.Obelisk).Intersect(newCreatures); foreach (var c in readdedCreatures) { c.status = CreatureStatus.Available; } } newCreatures.ForEach(creature => { creature.server = serverName; }); creatureCollection.MergeCreatureList(newCreatures, true); }
private void loadSettings(CreatureCollection cc) { if (cc.multipliers.Length > 7) { for (int s = 0; s < 8; s++) { if (cc.multipliers[s].Length > 3) { multSetter[s].Multipliers = cc.multipliers[s]; } } } numericUpDownHatching.Value = (decimal)cc.breedingMultipliers[0]; numericUpDownMaturation.Value = (decimal)cc.breedingMultipliers[1]; numericUpDownDomLevelNr.Value = cc.maxDomLevel; numericUpDownMaxBreedingSug.Value = cc.maxBreedingSuggestions; numericUpDownMaxWildLevel.Value = cc.maxWildLevel; numericUpDownImprintingM.Value = (decimal)cc.imprintingMultiplier; numericUpDownTamingSpeed.Value = (decimal)cc.tamingSpeedMultiplier; numericUpDownTamingFoodRate.Value = (decimal)cc.tamingFoodRateMultiplier; checkBoxAutoSave.Checked = Properties.Settings.Default.autosave; numericUpDownAutosaveMinutes.Value = Properties.Settings.Default.autosaveMinutes; chkExperimentalOCR.Checked = Properties.Settings.Default.OCR; chkCollectionSync.Checked = Properties.Settings.Default.syncCollection; if (Properties.Settings.Default.celsius) { radioButtonCelsius.Checked = true; } else { radioButtonFahrenheit.Checked = true; } }
private void loadSettings(CreatureCollection cc) { if (cc.multipliers.Length > 7) { for (int s = 0; s < 8; s++) { if (cc.multipliers[s].Length > 3) { multSetter[s].Multipliers = cc.multipliers[s]; } } } numericUpDownHatching.Value = (decimal)cc.EggHatchSpeedMultiplier; numericUpDownMaturation.Value = (decimal)cc.BabyMatureSpeedMultiplier; numericUpDownDomLevelNr.Value = cc.maxDomLevel; numericUpDownMaxBreedingSug.Value = cc.maxBreedingSuggestions; numericUpDownMaxWildLevel.Value = cc.maxWildLevel; numericUpDownMaxChartLevel.Value = cc.maxChartLevel; numericUpDownImprintingM.Value = (decimal)cc.imprintingMultiplier; numericUpDownBabyCuddleIntervalMultiplier.Value = (decimal)cc.babyCuddleIntervalMultiplier; numericUpDownTamingSpeed.Value = (decimal)cc.tamingSpeedMultiplier; numericUpDownTamingFoodRate.Value = (decimal)cc.tamingFoodRateMultiplier; nudMatingInterval.Value = (decimal)cc.MatingIntervalMultiplier; nudBabyFoodConsumptionSpeed.Value = (decimal)cc.BabyFoodConsumptionSpeedMultiplier; checkBoxAutoSave.Checked = Properties.Settings.Default.autosave; numericUpDownAutosaveMinutes.Value = Properties.Settings.Default.autosaveMinutes; chkExperimentalOCR.Checked = Properties.Settings.Default.OCR; chkbSpeechRecognition.Checked = Properties.Settings.Default.SpeechRecognition; nudOverlayInfoDuration.Value = Properties.Settings.Default.OverlayInfoDuration; chkCollectionSync.Checked = Properties.Settings.Default.syncCollection; if (Properties.Settings.Default.celsius) { radioButtonCelsius.Checked = true; } else { radioButtonFahrenheit.Checked = true; } checkBoxOxygenForAll.Checked = Properties.Settings.Default.oxygenForAll; string ocrApp = Properties.Settings.Default.OCRApp; int i = cbOCRApp.Items.IndexOf(ocrApp); if (i == -1) { textBoxOCRCustom.Text = ocrApp; cbOCRApp.SelectedIndex = cbOCRApp.Items.IndexOf("Custom"); } else { cbOCRApp.SelectedIndex = i; } nudEvolutionEvent.Value = (decimal)Properties.Settings.Default.evolutionMultiplier; customSCStarving.SoundFile = Properties.Settings.Default.soundStarving; customSCWakeup.SoundFile = Properties.Settings.Default.soundWakeup; customSCBirth.SoundFile = Properties.Settings.Default.soundBirth; }
public Settings(CreatureCollection cc) { initStuff(); this.cc = cc; setControls(cc); checkBoxAutoSave.Checked = Properties.Settings.Default.autosave; numericUpDownAutosaveMinutes.Value = Properties.Settings.Default.autosaveMinutes; chkExperimentalOCR.Checked = Properties.Settings.Default.OCR; }
/// <summary> /// Check if mod files for the missing species are available. /// </summary> private static void CheckForMissingModFiles(CreatureCollection creatureCollection, List <string> unknownSpeciesBlueprints, string exportFilePath = null, string creatureName = null) { var(locallyAvailableModFiles, onlineAvailableModFiles, unavailableModFiles, alreadyLoadedModFilesWithoutNeededClass) = HandleUnknownMods.CheckForMissingModFiles(unknownSpeciesBlueprints, creatureCollection.ModList); bool locallyAvailableModsExist = locallyAvailableModFiles != null && locallyAvailableModFiles.Any(); bool onlineAvailableModsExist = onlineAvailableModFiles != null && onlineAvailableModFiles.Any(); bool unavailableModsExist = unavailableModFiles != null && unavailableModFiles.Any(); bool alreadyLoadedModFilesWithoutNeededClassExist = alreadyLoadedModFilesWithoutNeededClass != null && alreadyLoadedModFilesWithoutNeededClass.Any(); MessageBoxes.ShowMessageBox("Some of the creatures to be imported have an unknown species, most likely because a mod is used.\n" + "To import these creatures, this application needs additional information about these mods." + (locallyAvailableModsExist ? "\n\nThe value files for the following mods are already locally available and just need to be added to the library:\n\n- " + string.Join("\n- ", locallyAvailableModFiles) : string.Empty) + (onlineAvailableModsExist ? "\n\nThe value files for the following mods can be downloaded automatically if you want:\n\n- " + string.Join("\n- ", onlineAvailableModFiles) : string.Empty) + (unavailableModsExist ? "\n\nThe values for species for the following mods are unknown.\nYou can create a mod values file manually if you have all the needed stat values, see the manual for more info.\nYou can also check on the discord server of ASB the #mod-requests channel and ask for that mod, maybe we'll add support for it in the future.\n\n- " + string.Join("\n- ", unavailableModFiles) : string.Empty) + (alreadyLoadedModFilesWithoutNeededClassExist ? "\n\nThe values for species for the following mods are unknown even though an according mod file was already loaded, i.e. the species blueprint path is not in the mod file. If it is a manual mod file, make sure the blueprint path is correct.\n\n- " + string.Join("\n- ", alreadyLoadedModFilesWithoutNeededClass) + "\n\nThe following blueprint paths were not found in the mod file:\n\n" + string.Join("\n", unknownSpeciesBlueprints.Where(bp => alreadyLoadedModFilesWithoutNeededClass.Any(m => bp.StartsWith($"/Game/Mods/{m}/")))) : string.Empty) + (string.IsNullOrEmpty(exportFilePath) ? null : $"\n\nThe according export file is located at\n{exportFilePath}") + (string.IsNullOrEmpty(creatureName) ? null : $"\n\nThe creature is named\n{creatureName}") , "Unknown species", MessageBoxIcon.Information); if ((locallyAvailableModsExist || onlineAvailableModsExist) && MessageBox.Show("Do you want to " + (onlineAvailableModsExist ? "download and " : string.Empty) + "add the values-files for the following mods to the library?\n\n- " + string.Join("\n- ", onlineAvailableModFiles) + (locallyAvailableModsExist && onlineAvailableModsExist ? "\n\n- " : string.Empty) + string.Join("\n- ", locallyAvailableModFiles), "Add value-files?", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes) { List <string> modTagsToAdd = new List <string>(); if (locallyAvailableModsExist) { modTagsToAdd.AddRange(locallyAvailableModFiles); } if (onlineAvailableModsExist) { modTagsToAdd.AddRange(onlineAvailableModFiles); } HandleUnknownMods.AddModsToCollection(creatureCollection, modTagsToAdd); } }
public static async Task ImportCollectionFromSavegame(CreatureCollection creatureCollection, string filename, string serverName) { (GameObjectContainer gameObjectContainer, float gameTime) = await Task.Run(() => ReadSavegameFile(filename)); var ignoreClasses = Values.V.IgnoreSpeciesClassesOnImport; var importUnclaimedBabies = Properties.Settings.Default.SaveFileImportUnclaimedBabies; IEnumerable <GameObject> tamedCreatureObjects = gameObjectContainer .Where(o => o.IsCreature() && o.IsTamed() && (importUnclaimedBabies || (o.IsCryo && Properties.Settings.Default.SaveImportCryo) || !o.IsUnclaimedBaby()) && !ignoreClasses.Contains(o.ClassString)); if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportTribeNameFilter)) { string[] filters = Properties.Settings.Default.ImportTribeNameFilter.Split(',') .Select(s => s.Trim()) .Where(s => !string.IsNullOrEmpty(s)) .ToArray(); if (filters.Any()) { tamedCreatureObjects = tamedCreatureObjects.Where(o => { string tribeName = o.GetPropertyValue <string>("TribeName", defaultValue: string.Empty); return(filters.Any(filter => tribeName.Contains(filter))); }); } } ImportSavegame importSavegame = new ImportSavegame(gameTime); int? wildLevelStep = creatureCollection.getWildLevelStep(); var creatures = tamedCreatureObjects.Select(o => importSavegame.ConvertGameObject(o, wildLevelStep)).Where(c => c != null).ToArray(); ArkName.ClearCache(); // if there are creatures with unknown species, check if the according mod-file is available var unknownSpeciesCreatures = creatures.Where(c => c.Species == null).ToArray(); if (!unknownSpeciesCreatures.Any() || Properties.Settings.Default.IgnoreUnknownBlueprintsOnSaveImport || MessageBox.Show("The species of " + unknownSpeciesCreatures.Length + " creature" + (unknownSpeciesCreatures.Length != 1 ? "s" : "") + " is not recognized, probably because they are from a mod that is not loaded.\n" + "The unrecognized species-classes are as follows, all the according creatures cannot be imported:\n\n" + string.Join("\n", unknownSpeciesCreatures.Select(c => c.name).Distinct().ToArray()) + "\n\nTo import the unrecognized creatures, you first need mod values-files, see Settings - Mod value manager… if the mod value is available\n\n" + "Do you want to import the recognized creatures? If you click no, nothing is imported.", "Unrecognized species while importing savegame", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes ) { ImportCollection(creatureCollection, creatures.Where(c => c.Species != null).ToList(), serverName); } }
private void NewCollection() { if (_collectionDirty && MessageBox.Show("Your Creature Collection has been modified since it was last saved, " + "are you sure you want to discard your changes and create a new Library without saving?", "Discard Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } if (_creatureCollection.modIDs?.Any() ?? false) { // if old collection had additionalValues, load the original ones to reset all modded values var(statValuesLoaded, _) = LoadStatAndKibbleValues(applySettings: false); if (!statValuesLoaded) { MessageBox.Show("Couldn't load stat values. Please redownload the application.", $"{Loc.S("error")} while loading the stat-values - {Utils.ApplicationNameVersion}", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (_creatureCollection.serverMultipliers == null) { _creatureCollection.serverMultipliers = Values.V.serverMultipliersPresets.GetPreset(ServerMultipliersPresets.OFFICIAL); } // use previously used multipliers again in the new file ServerMultipliers oldMultipliers = _creatureCollection.serverMultipliers; _creatureCollection = new CreatureCollection { serverMultipliers = oldMultipliers, ModList = new List <Mod>() }; _creatureCollection.FormatVersion = CreatureCollection.CURRENT_FORMAT_VERSION; pedigree1.Clear(); breedingPlan1.Clear(); creatureInfoInputExtractor.Clear(true); creatureInfoInputTester.Clear(true); ApplySettingsToValues(); InitializeCollection(); UpdateCreatureListings(); creatureBoxListView.Clear(); Properties.Settings.Default.LastSaveFile = null; _currentFileName = null; _fileSync.ChangeFile(_currentFileName); SetCollectionChanged(false); }
private void NewCollection() { if (collectionDirty) { if (MessageBox.Show("Your Creature Collection has been modified since it was last saved, " + "are you sure you want to discard your changes and create a new Library without saving?", "Discard Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } if (creatureCollection.modIDs?.Count > 0) { // if old collection had additionalValues, load the original ones to reset all modded values Values.V.LoadValues(); if (speechRecognition != null) { speechRecognition.updateNeeded = true; } } if (creatureCollection.serverMultipliers == null) { creatureCollection.serverMultipliers = Values.V.serverMultipliersPresets.GetPreset(ServerMultipliersPresets.OFFICIAL); } // use previously used multipliers again in the new file ServerMultipliers oldMultipliers = creatureCollection.serverMultipliers; creatureCollection = new CreatureCollection { serverMultipliers = oldMultipliers }; creatureCollection.FormatVersion = CreatureCollection.CURRENT_FORMAT_VERSION; pedigree1.Clear(); breedingPlan1.Clear(); ApplySettingsToValues(); InitializeCollection(); UpdateCreatureListings(); creatureBoxListView.Clear(); Properties.Settings.Default.LastSaveFile = ""; Properties.Settings.Default.LastImportFile = ""; currentFileName = ""; fileSync.ChangeFile(currentFileName); SetCollectionChanged(false); }
/// <summary> /// Creates a new collection. /// </summary> /// <param name="resetCollection">If true, the user is not asked and a new collection is created. This can be used if something went wrong while loading a file and a clean collection is needed.</param> private void NewCollection(bool resetCollection = false) { if (!resetCollection && _collectionDirty && CustomMessageBox.Show(Loc.S("Collection changed discard and new?"), Loc.S("Discard changes?"), Loc.S("Discard changes and new"), buttonCancel: Loc.S("Cancel"), icon: MessageBoxIcon.Warning) != DialogResult.Yes ) { return; } if (_creatureCollection.modIDs?.Any() ?? false) { // if old collection had additionalValues, load the original ones to reset all modded values var(statValuesLoaded, _) = LoadStatAndKibbleValues(applySettings: false); if (!statValuesLoaded) { MessageBoxes.ShowMessageBox("Couldn't load stat values. Please redownload the application.", $"{Loc.S("error")} while loading the stat-values"); } } if (_creatureCollection.serverMultipliers == null) { _creatureCollection.serverMultipliers = Values.V.serverMultipliersPresets.GetPreset(ServerMultipliersPresets.OFFICIAL); } // use previously used multipliers again in the new file ServerMultipliers oldMultipliers = _creatureCollection.serverMultipliers; _creatureCollection = new CreatureCollection { serverMultipliers = oldMultipliers, ModList = new List <Mod>() }; pedigree1.Clear(); breedingPlan1.Clear(); creatureInfoInputExtractor.Clear(true); creatureInfoInputTester.Clear(true); ApplySettingsToValues(); InitializeCollection(); UpdateCreatureListings(); creatureBoxListView.Clear(); Properties.Settings.Default.LastSaveFile = null; _currentFileName = null; _fileSync.ChangeFile(_currentFileName); SetCollectionChanged(false); }
public static async Task ImportCollectionFromSavegame(CreatureCollection creatureCollection, string filename, string serverName) { if (Values.V.ignoreSpeciesClassesOnImport == null) { Values.V.LoadIgnoreSpeciesClassesFile(); } (GameObjectContainer gameObjectContainer, float gameTime) = await readSavegameFile(filename); IEnumerable <GameObject> tamedCreatureObjects = gameObjectContainer .Where(o => o.IsCreature() && o.IsTamed() && !o.IsUnclaimedBaby() && !Values.V.ignoreSpeciesClassesOnImport.Contains(o.ClassString)); if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ImportTribeNameFilter)) { string[] filters = Properties.Settings.Default.ImportTribeNameFilter.Split(',') .Select(s => s.Trim()) .Where(s => !string.IsNullOrEmpty(s)) .ToArray(); tamedCreatureObjects = tamedCreatureObjects.Where(o => { string tribeName = o.GetPropertyValue <string>("TribeName", defaultValue: string.Empty); return(filters.Any(filter => tribeName.Contains(filter))); }); } ImportSavegame importSavegame = new ImportSavegame(gameTime); int? wildLevelStep = creatureCollection.getWildLevelStep(); List <Creature> creatures = tamedCreatureObjects.Select(o => importSavegame.convertGameObject(o, wildLevelStep)).ToList(); // if there are creatures with unknown species, check if the according mod-file is available var unknownSpeciesCreatures = creatures.Where(c => c.Species == null).ToList(); if (!unknownSpeciesCreatures.Any() || MessageBox.Show("The species of " + unknownSpeciesCreatures.Count.ToString() + " creature" + (unknownSpeciesCreatures.Count != 1 ? "s" : "") + " is not recognized, probably because they are from a mod that is not loaded.\n" + "The unrecognized species-classes are as follows, all the according creatures cannot be imported: " + string.Join(", ", unknownSpeciesCreatures.Select(c => c.name).Distinct().ToArray()) + "\n(To import the unrecognized creatures, you first need additional values-files.)\n\n" + "Do you want to import the recognized creatures? If you click no, nothing is imported.", "Unrecognized species while importing savegame", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes ) { importCollection(creatureCollection, creatures.Where(c => c.Species != null).ToList(), serverName); } }
private void setControls(CreatureCollection cc) { if (cc.multipliers.Length > 7) { for (int s = 0; s < 8; s++) { if (cc.multipliers[s].Length > 3) { multSetter[s].Multipliers = cc.multipliers[s]; } } } numericUpDownHatching.Value = (decimal)cc.breedingMultipliers[0]; numericUpDownMaturation.Value = (decimal)cc.breedingMultipliers[1]; numericUpDownDomLevelNr.Value = cc.maxDomLevel; numericUpDownMaxBreedingSug.Value = cc.maxBreedingSuggestions; numericUpDownMaxWildLevel.Value = cc.maxWildLevel; }
/// <summary> /// Check if mod files for the missing species are available. /// </summary> /// <param name="unknownSpeciesBlueprints"></param> public static void CheckForMissingModFiles(CreatureCollection creatureCollection, List <string> unknownSpeciesBlueprints) { var(locallyAvailableModFiles, onlineAvailableModFiles, unavailableModFiles) = mods.HandleUnknownMods.CheckForMissingModFiles(unknownSpeciesBlueprints); bool locallyAvailableModsExist = locallyAvailableModFiles != null && locallyAvailableModFiles.Any(); bool onlineAvailableModsExist = onlineAvailableModFiles != null && onlineAvailableModFiles.Any(); bool unavailableModsExist = unavailableModFiles != null && unavailableModFiles.Any(); MessageBox.Show("Some of the creatures to be imported have an unknown species, most likely because a mod is used.\n" + "To import these creatures, this application needs additional informations about these mods." + (locallyAvailableModsExist ? "\n\nThe value files for the following mods are already locally available and just need to be added to the library:\n\n- " + string.Join("\n- ", locallyAvailableModFiles) : "") + (onlineAvailableModsExist ? "\n\nThe value files for the following mods can be downloaded automatically if you want:\n\n- " + string.Join("\n- ", onlineAvailableModFiles) : "") + (unavailableModsExist ? "\n\nThe value files for the following mods are unknown. You probably manually need to create a mod-file to import the creatures depending on it.\n\n- " + string.Join("\n- ", unavailableModFiles) : ""), "Unknown species", MessageBoxButtons.OK, MessageBoxIcon.Information); if ((locallyAvailableModsExist || onlineAvailableModsExist) && MessageBox.Show("Do you want to " + (onlineAvailableModsExist ? "download and " : "") + "add the values-files for the following mods to the library?\n\n- " + string.Join("\n- ", onlineAvailableModFiles) + (locallyAvailableModsExist && onlineAvailableModsExist ? "\n\n- " : string.Empty) + string.Join("\n- ", locallyAvailableModFiles), "Add value-files?", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes) { List <string> modTagsToAdd = new List <string>(); if (locallyAvailableModsExist) { modTagsToAdd.AddRange(locallyAvailableModFiles); } if (onlineAvailableModsExist) { modTagsToAdd.AddRange(onlineAvailableModFiles); } mods.HandleUnknownMods.AddModsToCollection(creatureCollection, modTagsToAdd); } }
/// <summary> /// Check if mod files for the missing species are available. /// </summary> /// <param name="unknownSpeciesBlueprints"></param> public static void CheckForMissingModFiles(CreatureCollection creatureCollection, List <string> unknownSpeciesBlueprints) { var(locallyAvailableModFiles, onlineAvailableModFiles, unavailableModFiles) = mods.HandleUnknownMods.CheckForMissingModFiles(unknownSpeciesBlueprints); bool locallyAvailableModsExist = locallyAvailableModFiles != null && locallyAvailableModFiles.Any(); bool onlineAvailableModsExist = onlineAvailableModFiles != null && onlineAvailableModFiles.Any(); bool unavailableModsExist = unavailableModFiles != null && unavailableModFiles.Any(); MessageBoxes.ShowMessageBox("Some of the creatures to be imported have an unknown species, most likely because a mod is used.\n" + "To import these creatures, this application needs additional information about these mods." + (locallyAvailableModsExist ? "\n\nThe value files for the following mods are already locally available and just need to be added to the library:\n\n- " + string.Join("\n- ", locallyAvailableModFiles) : "") + (onlineAvailableModsExist ? "\n\nThe value files for the following mods can be downloaded automatically if you want:\n\n- " + string.Join("\n- ", onlineAvailableModFiles) : "") + (unavailableModsExist ? "\n\nThe values for species for the following mods are unknown.\nYou can create a mod values file manually if you have all the needed stat values, see the manual for more info.\nYou can also check on the discord server of ASB the #mod-requests channel and ask for that mod, maybe we'll add support for it in the future.\n\n- " + string.Join("\n- ", unavailableModFiles) : ""), "Unknown species", MessageBoxIcon.Information); if ((locallyAvailableModsExist || onlineAvailableModsExist) && MessageBox.Show("Do you want to " + (onlineAvailableModsExist ? "download and " : "") + "add the values-files for the following mods to the library?\n\n- " + string.Join("\n- ", onlineAvailableModFiles) + (locallyAvailableModsExist && onlineAvailableModsExist ? "\n\n- " : string.Empty) + string.Join("\n- ", locallyAvailableModFiles), "Add value-files?", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == DialogResult.Yes) { List <string> modTagsToAdd = new List <string>(); if (locallyAvailableModsExist) { modTagsToAdd.AddRange(locallyAvailableModFiles); } if (onlineAvailableModsExist) { modTagsToAdd.AddRange(onlineAvailableModFiles); } mods.HandleUnknownMods.AddModsToCollection(creatureCollection, modTagsToAdd); } }
private static void ImportCollection(CreatureCollection creatureCollection, List <Creature> newCreatures, string serverName) { if (creatureCollection.changeCreatureStatusOnSavegameImport) { // mark creatures that are no longer present as unavailable var removedCreatures = creatureCollection.creatures.Where(c => c.status == CreatureStatus.Available && c.server == serverName).Except(newCreatures); foreach (var c in removedCreatures) { c.status = CreatureStatus.Unavailable; } } newCreatures.ForEach(creature => { creature.server = serverName; }); creatureCollection.MergeCreatureList(newCreatures, addPreviouslylDeletedCreatures: true); }
// currently not used //public void saveJSON() //{ // // to create minified json of current values // DataContractJsonSerializer writer = new DataContractJsonSerializer(typeof(Values)); // try // { // System.IO.FileStream file = System.IO.File.Create("values.json"); // writer.WriteObject(file, _V); // file.Close(); // } // catch (Exception e) // { // MessageBox.Show("Error during serialization.\nErrormessage:\n\n" + e.Message, "Serialization-Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} public void applyMultipliers(CreatureCollection cc, bool eventMultipliers = false, bool applyStatMultipliers = true) { imprintingStatScaleMultiplier = cc.imprintingMultiplier; babyFoodConsumptionSpeedMultiplier = eventMultipliers ? cc.BabyFoodConsumptionSpeedMultiplierEvent : cc.BabyFoodConsumptionSpeedMultiplier; double eggHatchSpeedMultiplier = eventMultipliers ? cc.EggHatchSpeedMultiplierEvent : cc.EggHatchSpeedMultiplier; double babyMatureSpeedMultiplier = eventMultipliers ? cc.BabyMatureSpeedMultiplierEvent : cc.BabyMatureSpeedMultiplier; double matingIntervalMultiplier = eventMultipliers ? cc.MatingIntervalMultiplierEvent : cc.MatingIntervalMultiplier; for (int sp = 0; sp < species.Count; sp++) { if (applyStatMultipliers) { // stat-multiplier for (int s = 0; s < 8; s++) { species[sp].stats[s].BaseValue = (double)species[sp].statsRaw[s][0]; // don't apply the multiplier if AddWhenTamed is negative (currently the only case is the Giganotosaurus, which does not get the subtraction multiplied) species[sp].stats[s].AddWhenTamed = (double)species[sp].statsRaw[s][3] * (species[sp].statsRaw[s][3] > 0 ? cc.multipliers[s][0] : 1); species[sp].stats[s].MultAffinity = (double)species[sp].statsRaw[s][4] * cc.multipliers[s][1]; species[sp].stats[s].IncPerTamedLevel = (double)species[sp].statsRaw[s][2] * cc.multipliers[s][2]; species[sp].stats[s].IncPerWildLevel = (double)species[sp].statsRaw[s][1] * cc.multipliers[s][3]; } } // breeding multiplier if (species[sp].breeding != null) { if (eggHatchSpeedMultiplier > 0) { species[sp].breeding.gestationTimeAdjusted = species[sp].breeding.gestationTime / eggHatchSpeedMultiplier; species[sp].breeding.incubationTimeAdjusted = species[sp].breeding.incubationTime / eggHatchSpeedMultiplier; } if (babyMatureSpeedMultiplier > 0) { species[sp].breeding.maturationTimeAdjusted = species[sp].breeding.maturationTime / babyMatureSpeedMultiplier; } species[sp].breeding.matingCooldownMinAdjusted = species[sp].breeding.matingCooldownMin * matingIntervalMultiplier; species[sp].breeding.matingCooldownMaxAdjusted = species[sp].breeding.matingCooldownMax * matingIntervalMultiplier; } } }
private static void ImportCollection(CreatureCollection creatureCollection, List <Creature> newCreatures, string serverName) { if (creatureCollection.changeCreatureStatusOnSavegameImport) { // mark creatures that are no longer present as unavailable var removedCreatures = creatureCollection.creatures.Where(c => c.status == CreatureStatus.Available && c.server == serverName).Except(newCreatures); foreach (var c in removedCreatures) { c.status = CreatureStatus.Unavailable; } // mark creatures that re-appear as available (due to server transfer / obelisk / etc) var readdedCreatures = creatureCollection.creatures.Where(c => c.status == CreatureStatus.Unavailable || c.status == CreatureStatus.Obelisk).Intersect(newCreatures); foreach (var c in readdedCreatures) { c.status = CreatureStatus.Available; } } // update creature status that can be determined from the import var creaturesNowInPods = creatureCollection.creatures.Intersect(newCreatures.Where(c => c.status == CreatureStatus.Cryopod)); foreach (var c in creaturesNowInPods) { c.status = CreatureStatus.Cryopod; } var creaturesNowOutOfPods = creatureCollection.creatures.Where(c => c.status == CreatureStatus.Cryopod).Intersect(newCreatures.Where(c => c.status != CreatureStatus.Cryopod)); foreach (var c in creaturesNowInPods) { c.status = CreatureStatus.Available; } newCreatures.ForEach(creature => { creature.server = serverName; }); creatureCollection.MergeCreatureList(newCreatures, true, false, true); }
// currently not used //public void saveJSON() //{ // // to create minified json of current values // DataContractJsonSerializer writer = new DataContractJsonSerializer(typeof(Values)); // try // { // System.IO.FileStream file = System.IO.File.Create("values.json"); // writer.WriteObject(file, _V); // file.Close(); // } // catch (Exception e) // { // MessageBox.Show("Error during serialization.\nErrormessage:\n\n" + e.Message, "Serialization-Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} public void applyMultipliers(CreatureCollection cc) { imprintingMultiplier = cc.imprintingMultiplier; tamingSpeedMultiplier = cc.tamingSpeedMultiplier; tamingFoodRateMultiplier = cc.tamingFoodRateMultiplier; for (int sp = 0; sp < species.Count; sp++) { // stat-multiplier for (int s = 0; s < 8; s++) { species[sp].stats[s].BaseValue = (double)species[sp].statsRaw[s][0]; // don't apply the multiplier if AddWhenTamed is negative (currently the only case is the Giganotosaurus, which does not get the subtraction multiplied) species[sp].stats[s].AddWhenTamed = (double)species[sp].statsRaw[s][3] * (species[sp].statsRaw[s][3] > 0 ? cc.multipliers[s][0] : 1); species[sp].stats[s].MultAffinity = (double)species[sp].statsRaw[s][4] * cc.multipliers[s][1]; species[sp].stats[s].IncPerTamedLevel = (double)species[sp].statsRaw[s][2] * cc.multipliers[s][2]; species[sp].stats[s].IncPerWildLevel = (double)species[sp].statsRaw[s][1] * cc.multipliers[s][3]; } // breeding multiplier if (species[sp].breeding != null) { if (cc.EggHatchSpeedMultiplier > 0) { species[sp].breeding.gestationTimeAdjusted = species[sp].breeding.gestationTime / cc.EggHatchSpeedMultiplier; species[sp].breeding.incubationTimeAdjusted = species[sp].breeding.incubationTime / cc.EggHatchSpeedMultiplier; } if (cc.BabyMatureSpeedMultiplier > 0) { species[sp].breeding.maturationTimeAdjusted = species[sp].breeding.maturationTime / cc.BabyMatureSpeedMultiplier; } if (cc.MatingIntervalMultiplier > 0) { species[sp].breeding.matingCooldownMinAdjusted = species[sp].breeding.matingCooldownMin / cc.MatingIntervalMultiplier; species[sp].breeding.matingCooldownMaxAdjusted = species[sp].breeding.matingCooldownMax / cc.MatingIntervalMultiplier; } } } }
public void UpdateCreatureData(CreatureCollection cc) { // TODO }
// currently not used //public void saveJSON() //{ // // to create minified json of current values // DataContractJsonSerializer writer = new DataContractJsonSerializer(typeof(Values)); // try // { // System.IO.FileStream file = System.IO.File.Create("values.json"); // writer.WriteObject(file, _V); // file.Close(); // } // catch (Exception e) // { // MessageBox.Show("Error during serialization.\nErrormessage:\n\n" + e.Message, "Serialization-Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // } //} public void applyMultipliers(CreatureCollection cc, bool eventMultipliers = false, bool applyStatMultipliers = true) { imprintingStatScaleMultiplier = cc.imprintingMultiplier; babyFoodConsumptionSpeedMultiplier = eventMultipliers ? cc.BabyFoodConsumptionSpeedMultiplierEvent : cc.BabyFoodConsumptionSpeedMultiplier; double eggHatchSpeedMultiplier = eventMultipliers ? cc.EggHatchSpeedMultiplierEvent : cc.EggHatchSpeedMultiplier; double babyMatureSpeedMultiplier = eventMultipliers ? cc.BabyMatureSpeedMultiplierEvent : cc.BabyMatureSpeedMultiplier; double matingIntervalMultiplier = eventMultipliers ? cc.MatingIntervalMultiplierEvent : cc.MatingIntervalMultiplier; babyCuddleIntervalMultiplier = eventMultipliers ? cc.babyCuddleIntervalMultiplierEvent : cc.babyCuddleIntervalMultiplier; tamingSpeedMultiplier = eventMultipliers ? cc.tamingSpeedMultiplierEvent : cc.tamingSpeedMultiplier; if (cc.singlePlayerSettings) { matingIntervalMultiplier *= matingIntervalMultiplierSP; eggHatchSpeedMultiplier *= eggHatchSpeedMultiplierSP; babyMatureSpeedMultiplier *= babyMatureSpeedMultiplierSP; babyCuddleIntervalMultiplier *= babyCuddleIntervalMultiplierSP; tamingSpeedMultiplier *= tamingSpeedMultiplierSP; } // check for 0 if (matingIntervalMultiplier == 0) { matingIntervalMultiplier = 1; } if (eggHatchSpeedMultiplier == 0) { eggHatchSpeedMultiplier = 1; } if (babyMatureSpeedMultiplier == 0) { babyMatureSpeedMultiplier = 1; } if (babyCuddleIntervalMultiplier == 0) { babyCuddleIntervalMultiplier = 1; } if (tamingSpeedMultiplier == 0) { tamingSpeedMultiplier = 1; } for (int sp = 0; sp < species.Count; sp++) { if (applyStatMultipliers) { // stat-multiplier for (int s = 0; s < 8; s++) { species[sp].stats[s].BaseValue = (float)species[sp].statsRaw[s][0]; // don't apply the multiplier if AddWhenTamed is negative (e.g. Giganotosaurus, Griffin) species[sp].stats[s].AddWhenTamed = (float)species[sp].statsRaw[s][3] * (species[sp].statsRaw[s][3] > 0 ? (float)cc.multipliers[s][0] : 1); // don't apply the multiplier if MultAffinity is negative (e.g. Aberration variants) species[sp].stats[s].MultAffinity = (float)species[sp].statsRaw[s][4] * (species[sp].statsRaw[s][4] > 0 ? (float)cc.multipliers[s][1] : 1); species[sp].stats[s].IncPerTamedLevel = (float)species[sp].statsRaw[s][2] * (float)cc.multipliers[s][2]; species[sp].stats[s].IncPerWildLevel = (float)species[sp].statsRaw[s][1] * (float)cc.multipliers[s][3]; if (cc.singlePlayerSettings && statMultipliersSP[s] != null) { // don't apply the multiplier if AddWhenTamed is negative (e.g. Giganotosaurus, Griffin) species[sp].stats[s].AddWhenTamed *= statMultipliersSP[s][0] != null && species[sp].stats[s].AddWhenTamed > 0 ? (float)statMultipliersSP[s][0] : 1; // don't apply the multiplier if MultAffinity is negative (e.g. Aberration variants) species[sp].stats[s].MultAffinity *= statMultipliersSP[s][1] != null && species[sp].stats[s].MultAffinity > 0 ? (float)statMultipliersSP[s][1] : 1; species[sp].stats[s].IncPerTamedLevel *= statMultipliersSP[s][2] != null ? (float)statMultipliersSP[s][2] : 1; species[sp].stats[s].IncPerWildLevel *= statMultipliersSP[s][3] != null ? (float)statMultipliersSP[s][3] : 1; } } } // breeding multiplier if (species[sp].breeding != null) { if (eggHatchSpeedMultiplier > 0) { species[sp].breeding.gestationTimeAdjusted = species[sp].breeding.gestationTime / eggHatchSpeedMultiplier; species[sp].breeding.incubationTimeAdjusted = species[sp].breeding.incubationTime / eggHatchSpeedMultiplier; } if (babyMatureSpeedMultiplier > 0) { species[sp].breeding.maturationTimeAdjusted = species[sp].breeding.maturationTime / babyMatureSpeedMultiplier; } species[sp].breeding.matingCooldownMinAdjusted = species[sp].breeding.matingCooldownMin * matingIntervalMultiplier; species[sp].breeding.matingCooldownMaxAdjusted = species[sp].breeding.matingCooldownMax * matingIntervalMultiplier; } } }
/// <summary> /// Loads the given creature collection file. /// </summary> /// <param name="filePath">File that contains the collection</param> /// <param name="keepCurrentCreatures">add the creatures of the loaded file to the current ones</param> /// <param name="keepCurrentSelections">don't change the species selection or tab</param> /// <returns></returns> private bool LoadCollectionFile(string filePath, bool keepCurrentCreatures = false, bool keepCurrentSelections = false) { Species selectedSpeciesInLibrary = null; if (listBoxSpeciesLib.SelectedIndex > 0 && listBoxSpeciesLib.SelectedItem.GetType() == typeof(Species)) { selectedSpeciesInLibrary = listBoxSpeciesLib.SelectedItem as Species; } if (!File.Exists(filePath)) { MessageBox.Show($"Save file with name \"{filePath}\" does not exist!", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } List <Creature> oldCreatures = null; if (keepCurrentCreatures) { oldCreatures = creatureCollection.creatures; } // for the case the collectionfile has no multipliers, keep the current ones ServerMultipliers oldMultipliers = creatureCollection.serverMultipliers; // Wait until the file is readable const int numberOfRetries = 5; const int delayOnRetry = 1000; FileStream fileStream = null; for (int i = 1; i <= numberOfRetries; ++i) { try { if (Path.GetExtension(filePath).ToLower() == ".xml") { using (fileStream = File.OpenRead(filePath)) { // use xml-serializer for old library-format XmlSerializer reader = new XmlSerializer(typeof(oldLibraryFormat.CreatureCollectionOld)); var creatureCollectionOld = (oldLibraryFormat.CreatureCollectionOld)reader.Deserialize(fileStream); List <Mod> mods = null; // first check if additional values are used, and if the according values-file is already available. // if not, abort conversion and first make sure the file is available, e.g. downloaded if (!string.IsNullOrEmpty(creatureCollectionOld.additionalValues)) { // usually the old filename is equal to the mod-tag bool modFound = false; string modTag = Path.GetFileNameWithoutExtension(creatureCollectionOld.additionalValues).Replace(" ", "").ToLower().Replace("gaiamod", "gaia"); foreach (KeyValuePair <string, ModInfo> tmi in Values.V.modsManifest.modsByTag) { if (tmi.Key.ToLower() == modTag) { modFound = true; MessageBox.Show("The library contains creatures of modded species. For a correct file-conversion the correct mod-values file is needed.\n\n" + "If the mod-value file is not loaded, the conversion may assign wrong species to your creatures.\n" + "If the mod-value file is not available locally, it will be tried to download it.", "Mod values needed", MessageBoxButtons.OK, MessageBoxIcon.Information); Values.V.LoadValues(); // reset values to default LoadModValueFiles(new List <string> { tmi.Value.mod.FileName }, true, true, out mods); break; } } if (!modFound && MessageBox.Show("The additional-values file in the library you're loading is unknown. You should first get a values-file in the new format for that mod.\n" + "If you're loading the library the conversion of some modded species to the new format may fail and the according creatures have to be imported again later.\n\n" + "Do you want to load the library and risk losing creatures?", "Unknown mod-file", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return(false); } } creatureCollection = oldLibraryFormat.FormatConverter.ConvertXml2Asb(creatureCollectionOld, filePath); creatureCollection.ModList = mods; if (creatureCollection == null) { throw new Exception("Conversion failed"); } string fileNameWOExt = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); // check if new fileName is not yet existing filePath = fileNameWOExt + COLLECTION_FILE_EXTENSION; if (File.Exists(filePath)) { int fi = 2; while (File.Exists(fileNameWOExt + "_" + fi + COLLECTION_FILE_EXTENSION)) { fi++; } filePath = fileNameWOExt + "_" + fi + COLLECTION_FILE_EXTENSION; } // save converted library SaveCollectionToFileName(filePath); } } else { using (fileStream = FileService.GetJsonFileStream(filePath)) { var ser = new DataContractJsonSerializer(typeof(CreatureCollection) , new DataContractJsonSerializerSettings() { UseSimpleDictionaryFormat = true } ); var tmpCC = (CreatureCollection)ser.ReadObject(fileStream); if (!Version.TryParse(tmpCC.FormatVersion, out Version ccVersion) || !Version.TryParse(CreatureCollection.CURRENT_FORMAT_VERSION, out Version currentVersion) || ccVersion > currentVersion) { throw new FormatException("Unhandled format version"); } creatureCollection = tmpCC; } } break; } catch (IOException) { // if file is not readable Thread.Sleep(delayOnRetry); } catch (FormatException) { // This FormatVersion is not understood, abort MessageBox.Show($"This library format is unsupported in this version of ARK Smart Breeding." + "\n\nTry updating to a newer version.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (InvalidOperationException e) { MessageBox.Show($"The library-file\n{filePath}\ncouldn\'t be opened, we thought you should know.\nErrormessage:\n\n{e.Message}" + (e.InnerException == null ? string.Empty : $"\n\nInnerException:\n\n{e.InnerException.Message}"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } finally { fileStream?.Close(); } } if (Values.V.loadedModsHash != 0 && Values.V.loadedModsHash != creatureCollection.modListHash) { // load original multipliers if they were changed if (!Values.V.LoadValues()) { creatureCollection = new CreatureCollection(); return(false); } if (speechRecognition != null) { speechRecognition.updateNeeded = true; } } if (creatureCollection.ModValueReloadNeeded && !LoadModValuesOfCollection(creatureCollection, false, false)) { creatureCollection = new CreatureCollection(); return(false); } if (creatureCollection.serverMultipliers == null) { creatureCollection.serverMultipliers = oldMultipliers ?? Values.V.serverMultipliersPresets.GetPreset(ServerMultipliersPresets.OFFICIAL); } if (speciesSelector1.LastSpecies != null && speciesSelector1.LastSpecies.Length > 0) { tamingControl1.SetSpecies(Values.V.SpeciesByBlueprint(speciesSelector1.LastSpecies[0])); } creatureCollection.FormatVersion = CreatureCollection.CURRENT_FORMAT_VERSION; ApplySettingsToValues(); bool creatureWasAdded = false; if (keepCurrentCreatures) { creatureWasAdded = creatureCollection.mergeCreatureList(oldCreatures); } else { currentFileName = filePath; fileSync.ChangeFile(currentFileName); creatureBoxListView.Clear(); } InitializeCollection(); filterListAllowed = false; SetLibraryFilter("Dead", creatureCollection.showFlags.HasFlag(CreatureFlags.Dead)); SetLibraryFilter("Unavailable", creatureCollection.showFlags.HasFlag(CreatureFlags.Unavailable)); SetLibraryFilter("Neutered", creatureCollection.showFlags.HasFlag(CreatureFlags.Neutered)); SetLibraryFilter("Obelisk", creatureCollection.showFlags.HasFlag(CreatureFlags.Obelisk)); SetLibraryFilter("Cryopod", creatureCollection.showFlags.HasFlag(CreatureFlags.Cryopod)); SetLibraryFilter("Mutated", creatureCollection.showFlags.HasFlag(CreatureFlags.Mutated)); checkBoxUseFiltersInTopStatCalculation.Checked = creatureCollection.useFiltersInTopStatCalculation; filterListAllowed = true; SetCollectionChanged(creatureWasAdded); // setCollectionChanged only if there really were creatures added from the old library to the just opened one ///// creatures loaded. // calculate creature values RecalculateAllCreaturesValues(); if (!keepCurrentSelections && creatureCollection.creatures.Count > 0) { tabControlMain.SelectedTab = tabPageLibrary; } creatureBoxListView.maxDomLevel = creatureCollection.maxDomLevel; UpdateCreatureListings(); // set sepcies in library if (selectedSpeciesInLibrary != null) { listBoxSpeciesLib.SelectedIndex = listBoxSpeciesLib.Items.IndexOf(selectedSpeciesInLibrary); } // apply last sorting listViewLibrary.Sort(); UpdateTempCreatureDropDown(); Properties.Settings.Default.LastSaveFile = filePath; lastAutoSaveBackup = DateTime.Now.AddMinutes(-10); return(true); }
private void loadCollectionFile(string fileName, bool keepCurrentCreatures = false) { XmlSerializer reader = new XmlSerializer(typeof(CreatureCollection)); if (!System.IO.File.Exists(fileName)) { MessageBox.Show("Save file with name \"" + fileName + "\" does not exist!", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } List<Creature> oldCreatures = null; if (keepCurrentCreatures) oldCreatures = creatureCollection.creatures; System.IO.FileStream file = System.IO.File.OpenRead(fileName); // for the case the collectionfile has no multipliers, keep the current ones double[][] oldMultipliers = creatureCollection.multipliers; try { creatureCollection = (CreatureCollection)reader.Deserialize(file); } catch (Exception e) { MessageBox.Show("File Couldn't be opened, we thought you should know.\nErrormessage:\n\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); file.Close(); return; } file.Close(); if (creatureCollection.multipliers == null) { creatureCollection.multipliers = oldMultipliers; if (creatureCollection.multipliers == null) creatureCollection.multipliers = Values.V.statMultipliers; } applyMultipliersToValues(); assignCollectionClasses(); if (keepCurrentCreatures) creatureCollection.creatures.AddRange(oldCreatures); else { currentFileName = fileName; fileSync.changeFile(currentFileName); creatureBoxListView.Clear(); } filterListAllowed = false; checkBoxShowDead.Checked = creatureCollection.showDeads; checkBoxShowUnavailableCreatures.Checked = creatureCollection.showUnavailable; checkBoxShowNeuteredCreatures.Checked = creatureCollection.showNeutered; filterListAllowed = true; setCollectionChanged(keepCurrentCreatures); // creatures loaded. creatureBoxListView.CreatureCollection = creatureCollection; for (int s = 0; s < 8; s++) { statIOs[s].cc = creatureCollection; testingIOs[s].cc = creatureCollection; } lastAutoSaveBackup = DateTime.Now.AddMinutes(-10); // calculate creature values recalculateAllCreaturesValues(); if (creatureCollection.creatures.Count > 0) tabControlMain.SelectedTab = tabPageLibrary; creatureBoxListView.maxDomLevel = creatureCollection.maxDomLevel; // pedigree pedigree1.Clear(); // breedingPlan breedingPlan1.Clear(); updateParents(creatureCollection.creatures); updateCreatureListings(); // apply last sorting this.listViewLibrary.Sort(); Properties.Settings.Default.LastSaveFile = fileName; }
public Settings(CreatureCollection cc) { initStuff(); this.cc = cc; loadSettings(cc); }
private void loadSettings(CreatureCollection cc) { if (cc.multipliers.Length > 7) { for (int s = 0; s < 8; s++) { if (cc.multipliers[s].Length > 3) { multSetter[s].Multipliers = cc.multipliers[s]; } } } numericUpDownHatching.Value = (decimal)cc.breedingMultipliers[0]; numericUpDownMaturation.Value = (decimal)cc.breedingMultipliers[1]; numericUpDownDomLevelNr.Value = cc.maxDomLevel; numericUpDownMaxBreedingSug.Value = cc.maxBreedingSuggestions; numericUpDownMaxWildLevel.Value = cc.maxWildLevel; numericUpDownImprintingM.Value = (decimal)cc.imprintingMultiplier; numericUpDownTamingSpeed.Value = (decimal)cc.tamingSpeedMultiplier; numericUpDownTamingFoodRate.Value = (decimal)cc.tamingFoodRateMultiplier; checkBoxAutoSave.Checked = Properties.Settings.Default.autosave; numericUpDownAutosaveMinutes.Value = Properties.Settings.Default.autosaveMinutes; chkExperimentalOCR.Checked = Properties.Settings.Default.OCR; chkCollectionSync.Checked = Properties.Settings.Default.syncCollection; if (Properties.Settings.Default.celsius) radioButtonCelsius.Checked = true; else radioButtonFahrenheit.Checked = true; }
public bool LoadModValues(List <string> modValueFiles, bool showResults, out List <Mod> mods) { loadedModsHash = 0; List <Values> modifiedValues = new List <Values>(); mods = new List <Mod>(); if (modValueFiles == null) { return(false); } foreach (string mf in modValueFiles) { string filename = FileService.GetJsonPath(Path.Combine("mods", 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.Add(sp); sp.Initialize(); sp.mod = modValues.mod; speciesAdded++; if (!blueprintToSpecies.ContainsKey(sp.blueprintPath)) { blueprintToSpecies.Add(sp.blueprintPath, sp); } } else { // species already exists, update all values which are not null bool updated = false; if (sp.TamedBaseHealthMultiplier != null) { originalSpecies.TamedBaseHealthMultiplier = sp.TamedBaseHealthMultiplier; updated = true; } if (sp.NoImprintingForSpeed != null) { originalSpecies.NoImprintingForSpeed = sp.NoImprintingForSpeed; updated = true; } if (sp.fullStatsRaw != null && sp.fullStatsRaw.Length > 0) { for (int s = 0; s < statsCount && s < sp.fullStatsRaw.Length; s++) { if (sp.fullStatsRaw[s] == null) { continue; } for (int si = 0; si < 5 && si < sp.fullStatsRaw[s].Length; si++) { if (sp.fullStatsRaw[s][si] == null) { continue; } originalSpecies.fullStatsRaw[s][si] = sp.fullStatsRaw[s][si]; updated = true; } } } if (!string.IsNullOrEmpty(sp.blueprintPath)) { originalSpecies.blueprintPath = sp.blueprintPath; updated = true; } if (updated) { speciesUpdated++; } } } } } loadedModsHash = CreatureCollection.CalculateModListId(mods); // sort new species OrderSpecies(); // fooddata TODO // default-multiplier TODO _V.loadAliases(); _V.updateSpeciesBlueprints(); if (showResults) { MessageBox.Show($"Species with changed stats: {speciesUpdated}\nSpecies added: {speciesAdded}", "Additional Values succesfully added", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); }
private void newCollection() { if (collectionDirty) { if (MessageBox.Show("Your Creature Collection has been modified since it was last saved, are you sure you want to discard your changes and quit without saving?", "Discard Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.No) return; } if (creatureCollection.multipliers == null) creatureCollection.multipliers = Values.V.statMultipliers; // use previously used multipliers again in the new file double[][] oldMultipliers = creatureCollection.multipliers; creatureCollection = new CreatureCollection(); creatureCollection.multipliers = oldMultipliers; pedigree1.Clear(); breedingPlan1.Clear(); applyMultipliersToValues(); assignCollectionClasses(); updateCreatureListings(); creatureBoxListView.Clear(); Properties.Settings.Default.LastSaveFile = ""; currentFileName = ""; fileSync.changeFile(currentFileName); setCollectionChanged(false); }
/// <summary> /// Loads the given creature collection file. /// </summary> /// <param name="filePath">File that contains the collection</param> /// <param name="keepCurrentCreatures">add the creatures of the loaded file to the current ones</param> /// <param name="keepCurrentSelections">don't change the species selection or tab, use if a synchronized library is loaded</param> /// <returns></returns> private bool LoadCollectionFile(string filePath, bool keepCurrentCreatures = false, bool keepCurrentSelections = false) { Species selectedSpecies = speciesSelector1.SelectedSpecies; Species selectedLibrarySpecies = listBoxSpeciesLib.SelectedItem as Species; if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { MessageBoxes.ShowMessageBox($"Save file with name \"{filePath}\" does not exist!", $"File not found"); return(false); } CreatureCollection previouslyLoadedCreatureCollection = _creatureCollection; // Wait until the file is readable const int numberOfRetries = 5; const int delayOnRetry = 1000; FileStream fileStream = null; for (int i = 1; i <= numberOfRetries; ++i) { // sometimes a synchronized file has only 0 bytes, i.e. it's not yet synchronized fully. In this case wait a bit and try again if (Properties.Settings.Default.syncCollection && new FileInfo(filePath).Length == 0) { Thread.Sleep(delayOnRetry); continue; } try { if (Path.GetExtension(filePath).ToLower() == ".xml") { // old format for backwards compatibility using (fileStream = File.OpenRead(filePath)) { // use xml-serializer for old library-format XmlSerializer reader = new XmlSerializer(typeof(oldLibraryFormat.CreatureCollectionOld)); var creatureCollectionOld = (oldLibraryFormat.CreatureCollectionOld)reader.Deserialize(fileStream); List <Mod> mods = null; // first check if additional values are used, and if the according values-file is already available. // if not, abort conversion and first make sure the file is available, e.g. downloaded if (!string.IsNullOrEmpty(creatureCollectionOld.additionalValues)) { // usually the old filename is equal to the mod-tag bool modFound = false; string modTag = Path.GetFileNameWithoutExtension(creatureCollectionOld.additionalValues).Replace(" ", "").ToLower().Replace("gaiamod", "gaia"); foreach (KeyValuePair <string, ModInfo> tmi in Values.V.modsManifest.modsByTag) { if (tmi.Key.ToLower() == modTag) { modFound = true; MessageBox.Show("The library contains creatures of modded species. For a correct file-conversion the correct mod-values file is needed.\n\n" + "If the mod-value file is not loaded, the conversion may assign wrong species to your creatures.\n" + "If the mod-value file is not available locally, it will be tried to download it.", $"Mod values needed - {Utils.ApplicationNameVersion}", MessageBoxButtons.OK, MessageBoxIcon.Information); if (Values.V.loadedModsHash != Values.NoModsHash) { LoadStatAndKibbleValues(false); // reset values to default } LoadModValueFiles(new List <string> { tmi.Value.mod.FileName }, true, true, out mods); break; } } if (!modFound && MessageBox.Show("The additional-values file in the library you're loading is unknown. You should first get a values-file in the new format for that mod.\n" + "If you're loading the library the conversion of some modded species to the new format may fail and the according creatures have to be imported again later.\n\n" + $"File:\n{filePath}\n" + $"unknown mod-file: {modTag}\n\n" + "Do you want to load the library and risk losing creatures?", $"Unknown mod-file - {Utils.ApplicationNameVersion}", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return(false); } } _creatureCollection = oldLibraryFormat.FormatConverter.ConvertXml2Asb(creatureCollectionOld, filePath); _creatureCollection.ModList = mods; if (_creatureCollection == null) { throw new Exception("Conversion failed"); } string fileNameWOExt = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)); // check if new fileName is not yet existing filePath = fileNameWOExt + CollectionFileExtension; if (File.Exists(filePath)) { int fi = 2; while (File.Exists(fileNameWOExt + "_" + fi + CollectionFileExtension)) { fi++; } filePath = fileNameWOExt + "_" + fi + CollectionFileExtension; } // save converted library SaveCollectionToFileName(filePath); } } else { // new json-format if (FileService.LoadJsonFile(filePath, out CreatureCollection readCollection, out string errorMessage)) { if (!Version.TryParse(readCollection.FormatVersion, out Version ccVersion) || !Version.TryParse(CreatureCollection.CurrentLibraryFormatVersion, out Version currentVersion) || ccVersion > currentVersion) { throw new FormatException($"Unhandled format version: {(readCollection.FormatVersion ?? "null")}"); } _creatureCollection = readCollection; } else { MessageBoxes.ShowMessageBox($"Error while trying to read the library-file\n{filePath}\n\n{errorMessage}"); return(false); } } break; }
public Settings(CreatureCollection cc) { initStuff(); this.cc = cc; loadSettings(cc); }