Esempio n. 1
0
        public bool Apply(SaveObjectModel rootItem, SatisfactorySave saveGame)
        {
            var animalSpawners = rootItem.FindChild("BP_CreatureSpawner.BP_CreatureSpawner_C", false);

            if (animalSpawners == null)
            {
                MessageBox.Show("This save does not contain animals or it is corrupt.", "Cannot find animals", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            float offset          = -50000;
            var   hostPlayerModel = rootItem.FindChild("Char_Player.Char_Player_C", false);

            if (hostPlayerModel == null || hostPlayerModel.Items.Count < 1)
            {
                MessageBox.Show("This save does not contain a host player or it is corrupt.", "Cannot find host player", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            Vector3 playerPosition = ((SaveEntityModel)hostPlayerModel.Items[0]).Position;

            foreach (SaveObjectModel animalSpawner in animalSpawners.DescendantSelfViewModel)
            {
                // Some crab hatchers are marked as CreatureSpawner instead of EnemySpawner and there is no other trace of the difference between enemy and friendly in the savefile
                //if (animalSpawner.Title.ToLower().Contains("enemy"))
                //{
                ((SaveEntityModel)animalSpawner).Position.Z += offset; // Move the spawn under the map
                animalSpawner.FindField("mSpawnData", (ArrayPropertyViewModel arrayProperty) =>
                {
                    foreach (StructPropertyViewModel elem in arrayProperty.Elements)
                    {
                        ((Vector)((StructProperty)((DynamicStructDataViewModel)elem.StructData).Fields[0].Model).Data).Data.Z += offset; // Move the spawn point under the map
                        // Set WasKilled to true so they don't respawn after deleting them
                        ((BoolPropertyViewModel)((DynamicStructDataViewModel)elem.StructData).Fields[2]).Value = true;
                        // Set KilledOnDayNumber to a huge number (some far away animals respawn if the number is too small)
                        ((IntPropertyViewModel)((DynamicStructDataViewModel)elem.StructData).Fields[3]).Value = (int)(Distance(playerPosition, ((Vector)((StructProperty)((DynamicStructDataViewModel)elem.StructData).Fields[0].Model).Data).Data) / 10000);
                    }
                });
            }

            // Delete the already spawned enemies
            var enemies = rootItem.FindChild("Creature", false).FindChild("Enemy", false);

            rootItem.Remove(enemies);

            if (MessageBox.Show($"Deleted all spawned enemies, and all unspawned creatures (enemy & friendly). Would you like 3 tamed Lizzard Doggos as a compensation?", "Success", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                for (int i = 0; i < 3; i++)
                {
                    AddDoggo(rootItem, saveGame);
                }
            }
            return(true);
        }
Esempio n. 2
0
 private static double Distance(Vector3 a, Vector3 b)
 {
     return(Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y) + (a.Z - b.Z) * (a.Z - b.Z)));
 }