/// <summary> /// Deserialize binary stream to this entity /// </summary> /// <param name="bytes">the binary to turn into an entity</param> /// <returns>the entity</returns> public override IEntity DeSerialize(byte[] bytes) { var entityBinaryConvert = new DataUtility.EntityFileData(bytes); var xDoc = entityBinaryConvert.XDoc; var backingData = new RoomData(); var newEntity = new Room(); var versionFormat = xDoc.Root.GetSafeAttributeValue <int>("formattingVersion"); //This block represents "version zero" stuff we get from the xml newEntity.BirthMark = xDoc.Root.GetSafeAttributeValue("Birthmark"); newEntity.Birthdate = xDoc.Root.GetSafeAttributeValue <DateTime>("Birthdate"); backingData.ID = xDoc.Root.Element("BackingData").GetSafeAttributeValue <long>("ID"); backingData.Name = xDoc.Root.Element("BackingData").GetSafeAttributeValue("Name"); backingData.LastRevised = xDoc.Root.Element("BackingData").GetSafeAttributeValue <DateTime>("LastRevised"); backingData.Created = xDoc.Root.Element("BackingData").GetSafeAttributeValue <DateTime>("Created"); //Add a fake entity to get the birthmark over to the next place foreach (var item in xDoc.Root.Element("ObjectsInRoom").Elements("Item")) { var obj = new Inanimate(); obj.BirthMark = item.Value; newEntity.ObjectsInRoom.Add(obj); } //Add a fake entity to get the birthmark over to the next place foreach (var item in xDoc.Root.Element("MobilesInside").Elements("Item")) { var obj = new Intelligence(); obj.BirthMark = item.Value; newEntity.MobilesInside.Add(obj); } //keywords is last newEntity.Keywords = xDoc.Root.Element("LiveData").GetSafeAttributeValue <string>("Keywords").Split(new char[] { ',' }); //Add new version transformations here, they are meant to be iterative, hence < 1 Transform_V1(backingData, newEntity, xDoc.Root, versionFormat < 1); newEntity.DataTemplate = backingData; return(newEntity); }
/// <summary> /// Executes this command /// </summary> public override void Execute() { var newObject = (IInanimateData)Subject; var sb = new List<string>(); IContains spawnTo; //No target = spawn to room you're in if (Target != null) spawnTo = (IContains)Target; else spawnTo = OriginLocation; var entityObject = new Inanimate(newObject, spawnTo); //TODO: keywords is janky, location should have its own identifier name somehow for output purposes - DISPLAY short/long NAME sb.Add(string.Format("{0} spawned to {1}", entityObject.DataTemplateName, spawnTo.Keywords[0])); var messagingObject = new MessageCluster(sb, new string[] { "You are ALIVE" }, new string[] { "You have been given $S$" }, new string[] { "$S$ appears in the $T$." }, new string[] { }); messagingObject.ExecuteMessaging(Actor, entityObject, spawnTo, OriginLocation, null); }
/// <summary> /// Deserialize binary stream to this entity /// </summary> /// <param name="bytes">the binary to turn into an entity</param> /// <returns>the entity</returns> public override IEntity DeSerialize(byte[] bytes) { var entityBinaryConvert = new DataUtility.EntityFileData(bytes); var xDoc = entityBinaryConvert.XDoc; var backingData = new NonPlayerCharacter(); var newEntity = new Intelligence(); var versionFormat = xDoc.Root.GetSafeAttributeValue <int>("formattingVersion"); newEntity.BirthMark = xDoc.Root.GetSafeAttributeValue("Birthmark"); newEntity.Birthdate = xDoc.Root.GetSafeAttributeValue <DateTime>("Birthdate"); backingData.ID = xDoc.Root.Element("BackingData").GetSafeAttributeValue <long>("ID"); backingData.Name = xDoc.Root.Element("BackingData").GetSafeAttributeValue("Name"); backingData.SurName = xDoc.Root.Element("BackingData").GetSafeAttributeValue("Surname"); backingData.LastRevised = xDoc.Root.Element("BackingData").GetSafeAttributeValue <DateTime>("LastRevised"); backingData.Created = xDoc.Root.Element("BackingData").GetSafeAttributeValue <DateTime>("Created"); backingData.Gender = xDoc.Root.Element("BackingData").GetSafeAttributeValue("Gender"); //Add a fake entity to get the birthmark over to the next place foreach (var item in xDoc.Root.Element("Inventory").Elements("Item")) { var obj = new Inanimate(); obj.BirthMark = item.Value; newEntity.Inventory.Add(obj); } //keywords is last newEntity.Keywords = xDoc.Root.Element("LiveData").GetSafeAttributeValue("Keywords").Split(new char[] { ',' }); //Add new version transformations here, they are meant to be iterative, hence < 1 Transform_V1(backingData, newEntity, xDoc.Root, versionFormat < 1); newEntity.DataTemplate = backingData; return(newEntity); }
private void Transform_V1(InanimateData backingData, Inanimate newEntity, XElement docRoot, bool older) { if (!older) { //We added dim mods in v1 var dimModelId = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeAttributeValue <long>("ID"); var dimModelLength = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeAttributeValue <int>("Length"); var dimModelHeight = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeAttributeValue <int>("Height"); var dimModelWidth = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeAttributeValue <int>("Width"); var dimModelJson = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeElementValue("ModellingData"); var dimModelCompJson = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeElementValue("MaterialCompositions"); backingData.Model = new DimensionalModel(dimModelLength, dimModelHeight, dimModelWidth, dimModelId, dimModelCompJson); newEntity.Model = new DimensionalModel(dimModelLength, dimModelHeight, dimModelWidth, dimModelJson, dimModelId, dimModelCompJson); } else //what if we're older { //Get it from the db var backD = DataWrapper.GetOne <InanimateData>(backingData.ID); backingData.Model = backD.Model; newEntity.Model = backD.Model; } }
/// <summary> /// Deserialize binary stream to this entity /// </summary> /// <param name="bytes">the binary to turn into an entity</param> /// <returns>the entity</returns> public override IEntity DeSerialize(byte[] bytes) { var entityBinaryConvert = new DataUtility.EntityFileData(bytes); var xDoc = entityBinaryConvert.XDoc; var newEntity = new Inanimate(); var versionFormat = xDoc.Root.GetSafeAttributeValue <int>("formattingVersion"); newEntity.BirthMark = xDoc.Root.GetSafeAttributeValue("Birthmark"); newEntity.Birthdate = xDoc.Root.GetSafeAttributeValue <DateTime>("Birthdate"); var internalCompositions = xDoc.Root.Element("BackingData").GetSafeAttributeValue("InternalComposition"); var backingData = new InanimateData(internalCompositions); backingData.ID = xDoc.Root.Element("BackingData").GetSafeAttributeValue <long>("ID"); backingData.Name = xDoc.Root.Element("BackingData").GetSafeAttributeValue("Name"); backingData.LastRevised = xDoc.Root.Element("BackingData").GetSafeAttributeValue <DateTime>("LastRevised"); backingData.Created = xDoc.Root.Element("BackingData").GetSafeAttributeValue <DateTime>("Created"); foreach (var item in xDoc.Root.Element("BackingData").Element("InanimateContainers").Elements("Item")) { var newContainer = new EntityContainerData <IInanimate>(); newContainer.CapacityVolume = item.GetSafeAttributeValue <long>("CapacityVolume"); newContainer.CapacityWeight = item.GetSafeAttributeValue <long>("CapacityWeight"); newContainer.Name = item.GetSafeAttributeValue("Name"); backingData.InanimateContainers.Add(newContainer); } //Add a fake entity to get the birthmark over to the next place foreach (var item in xDoc.Root.Element("BackingData").Element("MobileContainers").Elements("Item")) { var newContainer = new EntityContainerData <IMobile>(); newContainer.CapacityVolume = item.GetSafeAttributeValue <long>("CapacityVolume"); newContainer.CapacityWeight = item.GetSafeAttributeValue <long>("CapacityWeight"); newContainer.Name = item.GetSafeAttributeValue("Name"); backingData.MobileContainers.Add(newContainer); } //Add a fake entity to get the birthmark over to the next place foreach (var item in xDoc.Root.Element("MobilesInside").Elements("Item")) { var obj = new Intelligence(); obj.BirthMark = item.GetSafeAttributeValue("Birthmark"); var containerName = item.GetSafeAttributeValue("Container"); if (!String.IsNullOrWhiteSpace(containerName)) { newEntity.MobilesInside.Add(obj, containerName); } else { newEntity.MobilesInside.Add(obj); } } //Add a fake entity to get the birthmark over to the next place foreach (var item in xDoc.Root.Element("Contents").Elements("Item")) { var obj = new Inanimate(); obj.BirthMark = item.GetSafeAttributeValue("Birthmark"); var containerName = item.GetSafeAttributeValue("Container"); if (!String.IsNullOrWhiteSpace(containerName)) { newEntity.Contents.Add(obj, containerName); } else { newEntity.Contents.Add(obj); } } //Add new version transformations here, they are meant to be iterative, hence < 1 Transform_V1(backingData, newEntity, xDoc.Root, versionFormat < 1); newEntity.DataTemplate = backingData; //keywords is last newEntity.Keywords = xDoc.Root.Element("LiveData").Attribute("Keywords").Value.Split(new char[] { ',' }); return(newEntity); }