Exemplo n.º 1
0
        /// <summary>
        /// Serialize this entity's live data to a binary stream
        /// </summary>
        /// <returns>the binary stream</returns>
        public override byte[] Serialize()
        {
            var settings = new XmlWriterSettings {
                OmitXmlDeclaration = true, Encoding = Encoding.UTF8
            };
            var charData = (IRoomData)DataTemplate;

            var entityData = new XDocument(
                new XElement("root",
                             new XAttribute("formattingVersion", liveDataVersion),
                             new XAttribute("Birthmark", BirthMark),
                             new XAttribute("Birthdate", Birthdate),
                             new XElement("BackingData",
                                          new XAttribute("ID", charData.ID),
                                          new XAttribute("Name", charData.Name),
                                          new XAttribute("Medium", charData.Medium.ID),
                                          new XAttribute("Zone", charData.ZoneAffiliation.ID),
                                          new XAttribute("LastRevised", charData.LastRevised),
                                          new XAttribute("Created", charData.Created),
                                          new XElement("Borders", charData.SerializeBorders())),
                             new XElement("LiveData",
                                          new XAttribute("Keywords", string.Join(",", Keywords)),
                                          new XElement("DimensionalModel",
                                                       new XAttribute("Length", Model.Length),
                                                       new XAttribute("Height", Model.Height),
                                                       new XAttribute("Width", Model.Width))),
                             new XElement("ObjectsInRoom"),
                             new XElement("MobilesInside")
                             ));

            foreach (var item in ObjectsInRoom.EntitiesContained())
            {
                entityData.Root.Element("ObjectsInRoom").Add(new XElement("Item", item.BirthMark));
            }

            foreach (var item in MobilesInside.EntitiesContained().Where(ent => ent.GetType() != typeof(Player)))
            {
                entityData.Root.Element("MobilesInside").Add(new XElement("Item", item.BirthMark));
            }

            //pathways will load themselves

            var entityBinaryConvert = new DataUtility.EntityFileData(entityData);

            using (var memoryStream = new MemoryStream())
                using (var xmlWriter = XmlWriter.Create(memoryStream, settings))
                {
                    entityData.WriteTo(xmlWriter);
                    xmlWriter.Flush();
                    entityBinaryConvert.XmlBinary = memoryStream.ToArray();
                }

            return(entityBinaryConvert.XmlBinary);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Move an entity out of this' named container
        /// </summary>
        /// <typeparam name="T">the type of entity to remove</typeparam>
        /// <param name="thing">the entity</param>
        /// <param name="containerName">the name of the container</param>
        /// <returns>errors</returns>
        public string MoveFrom <T>(T thing, string containerName)
        {
            var implimentedTypes = DataUtility.GetAllImplimentingedTypes(typeof(T));

            if (implimentedTypes.Contains(typeof(IInanimate)))
            {
                var obj = (IInanimate)thing;

                if (!ObjectsInRoom.Contains(obj, containerName))
                {
                    return("That is not in the container");
                }

                ObjectsInRoom.Remove(obj, containerName);
                obj.CurrentLocation = null;
                this.UpsertToLiveWorldCache();
                return(string.Empty);
            }


            if (implimentedTypes.Contains(typeof(IMobile)))
            {
                var obj = (IMobile)thing;

                if (!MobilesInside.Contains(obj, containerName))
                {
                    return("That is not in the container");
                }

                MobilesInside.Remove(obj, containerName);
                obj.CurrentLocation = null;
                this.UpsertToLiveWorldCache();
                return(string.Empty);
            }

            if (implimentedTypes.Contains(typeof(IPathway)))
            {
                var obj = (IPathway)thing;

                if (!Pathways.Contains(obj, containerName))
                {
                    return("That is not in the container");
                }

                Pathways.Remove(obj, containerName);
                obj.CurrentLocation = null;
                this.UpsertToLiveWorldCache();
                return(string.Empty);
            }

            return("Invalid type to move from container.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Move an entity into a named container in this
        /// </summary>
        /// <typeparam name="T">the type of the entity to add</typeparam>
        /// <param name="thing">the entity to add</param>
        /// <param name="containerName">the name of the container</param>
        /// <returns>errors</returns>
        public string MoveInto <T>(T thing, string containerName)
        {
            var implimentedTypes = DataUtility.GetAllImplimentingedTypes(typeof(T));

            if (implimentedTypes.Contains(typeof(IInanimate)))
            {
                var obj = (IInanimate)thing;

                if (ObjectsInRoom.Contains(obj, containerName))
                {
                    return("That is already in the container");
                }

                ObjectsInRoom.Add(obj, containerName);
                obj.CurrentLocation = this;
                this.UpsertToLiveWorldCache();
                return(string.Empty);
            }

            if (implimentedTypes.Contains(typeof(IMobile)))
            {
                var obj = (IMobile)thing;

                if (MobilesInside.Contains(obj, containerName))
                {
                    return("That is already in the container");
                }

                MobilesInside.Add(obj, containerName);
                obj.CurrentLocation = this;
                this.UpsertToLiveWorldCache();
                return(string.Empty);
            }

            if (implimentedTypes.Contains(typeof(IPathway)))
            {
                var obj = (IPathway)thing;

                if (Pathways.Contains(obj, containerName))
                {
                    return("That is already in the container");
                }

                Pathways.Add(obj, containerName);
                obj.CurrentLocation = this;
                this.UpsertToLiveWorldCache();
                return(string.Empty);
            }

            return("Invalid type to move to container.");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get all of the entities matching a type inside this
        /// </summary>
        /// <typeparam name="T">the type</typeparam>
        /// <returns>the contained entities</returns>
        public IEnumerable <T> GetContents <T>()
        {
            var implimentedTypes = DataUtility.GetAllImplimentingedTypes(typeof(T));

            var contents = new List <T>();

            if (implimentedTypes.Contains(typeof(IMobile)))
            {
                contents.AddRange(MobilesInside.EntitiesContained().Select(ent => (T)ent));
            }

            if (implimentedTypes.Contains(typeof(IInanimate)))
            {
                contents.AddRange(ObjectsInRoom.EntitiesContained().Select(ent => (T)ent));
            }

            if (implimentedTypes.Contains(typeof(IPathway)))
            {
                contents.AddRange(Pathways.EntitiesContained().Select(ent => (T)ent));
            }

            return(contents);
        }
Exemplo n.º 5
0
 public List <BaseObject> GetNonClueNonCorpseItems()
 {
     return(ObjectsInRoom.Where(obj => !(obj is Clue) && !(obj is CorpseNPCObject)).ToList());
 }