Ejemplo n.º 1
0
        public static Area Deserialize(dynamic data)
        {
            var area = new Area();

            EntitySerializer.Deserialize(data, area);


            Func <dynamic, Room> deserializeRoom = roomData => RoomManager.Deserialize(roomData);

            area.Rooms = new List <Room>(Enumerable.Select <dynamic, Room>(data.Rooms, deserializeRoom));

            return(area);
        }
Ejemplo n.º 2
0
        public static IDictionary <string, object> Serialize(Room room)
        {
            var data = EntitySerializer.Serialize(room);

            data.Add("Description", room.Description);
            data.Add("Exits", ExitSet.Serialize(room._exits));
            if (room.Resets != null)
            {
                data.Add("Resets", RoomReset.Serialize(room.Resets));
            }

            return(data);
        }
Ejemplo n.º 3
0
        public static IDictionary <string, object> Serialize(Character character)
        {
            var data = EntitySerializer.Serialize(character)
                       .AddIf("Inventory", character.Inventory, character.Inventory.Count > 0)
                       .AddIf("Equipment", character.Eq, character.Eq.Count > 0)

                       .AddIf("LoginAt", character.RoomId, character.RoomId != null)
                       .AddIf("RespawnAt", character.RespawnAtId, character.RespawnAtId != null)

                       .AddIf("Data", character.Data, character.Data != null && character.Data.Keys.Count > 0);

            data.Add("Stats", character.Stats.Serialize());

            return(data);
        }
Ejemplo n.º 4
0
        public static Room Deserialize(dynamic data)
        {
            var room = new Room {
                Description = data.Description
            };

            if (data.Exits != null)
            {
                room._exits = ExitSet.Deserialize(data.Exits);
            }

            if (data.Resets != null)
            {
                room.Resets = RoomReset.Deserialize(data.Resets);
            }
            EntitySerializer.Deserialize(data, room);
            return(room);
        }
Ejemplo n.º 5
0
        public static IDictionary <string, object> Serialize(Item item)
        {
            var data = EntitySerializer.Serialize(item)
                       .AddEx("WearLoc", item.WearLoc)
                       .AddEx("Flags", item.Flags)
                       .AddIf("Stack", item.Stack, item.Stack != null)
                       .AddEx("Cost", item.Cost);

            if (item.Stats != null)
            {
                data.Add("Stats", item.Stats.Serialize());
            }
            if (item.Weapon != null)
            {
                data.Add("Weapon", item.Weapon.Serialize());
            }
            return(data);
        }
Ejemplo n.º 6
0
        public static Character Deserialize(dynamic data)
        {
            var character = new Character();

            EntitySerializer.Deserialize(data, character);

            if (data.Stats != null)
            {
                character.Stats.Deserialize(data.Stats);
            }

            Func <dynamic, Item> deserializeItem = itemData => ItemManager.Deserialize(itemData);

            if (data.Inventory != null)
            {
                character.Inventory = new ItemSet(Enumerable.Select(data.Inventory, deserializeItem));
            }
            if (data.Equipment != null)
            {
                character.Eq = ItemManager.DeserializeEquipment(data.Equipment);
            }

            if (data.RespawnAt != null)
            {
                character.RespawnAtId = data.RespawnAt;
            }

            if (data.LoginAt != null)
            {
                character.RoomId = data.LoginAt;
            }

            if (data.Data != null)
            {
                Func <dynamic, string> keySelector   = item => item.Name;
                Func <dynamic, string> valueSelector = item => item.First;
                character.Data = Enumerable.ToDictionary(data.Data, keySelector, valueSelector);
            }

            return(character);
        }