Example #1
0
    public static SavedDungeon ConvertFrom(OverworldDungeon dungeon)
    {
        if (dungeon.dungeonData == null)
        {
            return new SavedDungeon()
                   {
                       location = SavedVector2.ConvertFrom(dungeon.position),
                       uuid     = dungeon.uuid
                   }
        }
        ;
        var output = new SavedDungeon {
            entered                     = true,
            location                    = SavedVector2.ConvertFrom(dungeon.position),
            numFloors                   = dungeon.dungeonData.numFloors,
            grid                        = dungeon.dungeonData.grid,
            maxSocialTier               = dungeon.dungeonData.maxSocialTier,
            maxDimensions               = dungeon.dungeonData.maxDimensions,
            encounterThemes             = dungeon.dungeonData.encounterThemes,
            seeds                       = dungeon.seeds,
            uuid                        = dungeon.uuid,
            lootSlotAffinities          = dungeon.dungeonData.lootSlotAffinities,
            lootPrimaryStatAffinities   = dungeon.dungeonData.lootPrimaryStatAffinities,
            lootSecondaryStatAffinities = dungeon.dungeonData.lootSecondaryStatAffinities,
            elementalAffinity           = dungeon.dungeonData.elementalAffinity,
            bossLootSlotAffinities      = dungeon.dungeonData.bossLootSlotAffinities
        };

        foreach (var kvp in dungeon.dungeonData.enemyStatBoosts)
        {
            output.enemyStatBoostEnemies.Add(kvp.Key);

            output.enemyStatBoostStats.Add(kvp.Value);
        }
        foreach (var kvp in dungeon.dungeonData.enemyBonusAbilities)
        {
            output.enemyBonusAbilityEnemies.Add(kvp.Key);
            output.enemyBonusAbilityAbilities.Add(SavedActiveAbility.ConvertFrom(kvp.Value));
        }
        foreach (var room in dungeon.dungeonData.rooms)
        {
            output.rooms.Add(SavedRoom.ConvertFrom(room));
        }
        foreach (var monster in dungeon.dungeonData.monsters)
        {
            output.monsters.Add(SavedMonsterData.ConvertFrom(monster));
        }
        foreach (var path in dungeon.dungeonData.paths)
        {
            output.paths.Add(SavedVaultPath.ConvertFrom(path));
        }
        return(output);
    }
Example #2
0
    public static SavedRoom ConvertFrom(Room room)
    {
        var output = new SavedRoom {
            uuid        = room.uuid,
            size        = room.size,
            grandiosity = room.grandiosity,
            x           = room.x,
            y           = room.y,
            floor       = room.floor,
            xSize       = room.xSize,
            ySize       = room.ySize
        };

        foreach (var entrance in room.entrances)
        {
            output.entrances.Add(SavedVector3.ConvertFrom(entrance));
        }
        foreach (var dressingLocation in room.dressingLocations)
        {
            output.dressingLocations.Add(SavedVector2.ConvertFrom(dressingLocation));
        }
        return(output);
    }
        //-------------Serialization for the world-----------------------------------------------
        public static void Serialize(SavedRoom sr, string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);

                try
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(fs, sr);
                }
                finally
                {
                    fs.Close();
                    Console.WriteLine("Saved!");
                }
        }
        //-----------------Functions dealing with saving and loading levels-----------------------------------
        // More specifically, these are the callbacks and functions related to the menu bar in the top.
        private void SaveRoom()
        {
            SavedRoom sr = new SavedRoom();
            sr.objects = world.Objects;
            sr.backgroundName = world.backgroundName;
            sr.musicName = world.musicName;
            foreach (PhysicsObject obj in world.Objects)
            {
                if (obj is DudeObject)
                {
                    sr.dude = (DudeObject)obj;
                }
                else if (obj is WinDoorObject)
                {
                    sr.winDoor = (WinDoorObject)obj;
                }
            }
            sr.objects.Remove(sr.dude);
            //sr.world.DestroyBody(sr.dude.Body);
            sr.objects.Remove(sr.winDoor);
            //sr.world.DestroyBody(sr.winDoor.Body);

            sr.world = world.World;

            Serializer.Serialize(sr, currentFileName);

            sr.objects.Add(sr.dude);
            sr.objects.Add(sr.winDoor);
        }