コード例 #1
0
        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);
            }
        }