/// <summary> /// Saves the item definition /// </summary> /// <param name="writer">Xml writer handle</param> /// <returns>True if saved, or false</returns> public bool Save(XmlWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } writer.WriteStartElement("item"); writer.WriteAttributeString("name", Name); writer.WriteStartElement("tile"); writer.WriteAttributeString("name", TileSetName); writer.WriteAttributeString("inventory", TileID.ToString()); writer.WriteAttributeString("ground", GroundTileID.ToString()); writer.WriteAttributeString("incoming", IncomingTileID.ToString()); writer.WriteAttributeString("moveaway", ThrowTileID.ToString()); writer.WriteEndElement(); writer.WriteStartElement("type"); writer.WriteAttributeString("value", Type.ToString()); writer.WriteEndElement(); writer.WriteStartElement("damagetype"); writer.WriteAttributeString("value", DamageType.ToString()); writer.WriteEndElement(); writer.WriteStartElement("ac"); writer.WriteAttributeString("value", ArmorClass.ToString()); writer.WriteEndElement(); writer.WriteStartElement("slot"); writer.WriteAttributeString("value", Slot.ToString()); writer.WriteEndElement(); writer.WriteStartElement("classes"); writer.WriteAttributeString("value", AllowedClasses.ToString()); writer.WriteEndElement(); writer.WriteStartElement("weight"); writer.WriteAttributeString("value", Weight.ToString()); writer.WriteEndElement(); Damage.Save("damage", writer); DamageVsBig.Save("damagevsbig", writer); DamageVsSmall.Save("damagevssmall", writer); writer.WriteStartElement("critical"); writer.WriteAttributeString("min", Critical.X.ToString()); writer.WriteAttributeString("max", Critical.Y.ToString()); writer.WriteAttributeString("multiplier", CriticalMultiplier.ToString()); writer.WriteEndElement(); Script.Save("script", writer); if (IsCursed) { writer.WriteStartElement("iscursed"); writer.WriteAttributeString("value", IsCursed.ToString()); writer.WriteEndElement(); } if (IsIdentified) { writer.WriteStartElement("isidentified"); writer.WriteAttributeString("value", IsCursed.ToString()); writer.WriteEndElement(); } if (CanIdentify) { writer.WriteStartElement("canidentify"); writer.WriteAttributeString("value", IsCursed.ToString()); writer.WriteEndElement(); } if (IsBig) { writer.WriteStartElement("isbig"); writer.WriteAttributeString("value", IsBig.ToString()); writer.WriteEndElement(); } writer.WriteStartElement("allowedhands"); writer.WriteAttributeString("value", AllowedHands.ToString()); writer.WriteEndElement(); writer.WriteElementString("shortname", ShortName); writer.WriteElementString("identifiedname", IdentifiedName); writer.WriteStartElement("speed"); writer.WriteAttributeString("value", AttackSpeed.TotalMilliseconds.ToString()); writer.WriteEndElement(); writer.WriteEndElement(); return(true); }
/// <summary> /// Loads an item definition /// </summary> /// <param name="xml">Xml handle</param> /// <returns>True if loaded, or false</returns> public bool Load(XmlNode xml) { if (xml == null || xml.Name != "item") { return(false); } //ID = int.Parse(xml.Attributes["id"].Value); Name = xml.Attributes["name"].Value; foreach (XmlNode node in xml) { if (node.NodeType == XmlNodeType.Comment) { continue; } switch (node.Name.ToLower()) { case "script": { Script.Load(node); //ScriptName = node.Attributes["name"].Value; //InterfaceName = node.Attributes["interface"].Value; } break; case "type": { Type = (ItemType)Enum.Parse(typeof(ItemType), node.Attributes["value"].Value, true); } break; case "slot": { Slot |= (BodySlot)Enum.Parse(typeof(BodySlot), node.Attributes["value"].Value, true); } break; case "damagetype": { DamageType |= (DamageType)Enum.Parse(typeof(DamageType), node.Attributes["value"].Value, true); } break; case "weight": { Weight = int.Parse(node.Attributes["value"].Value); } break; case "damage": { Damage.Load(node); } break; case "damagevsbig": { DamageVsBig.Load(node); } break; case "damagevssmall": { DamageVsSmall.Load(node); } break; case "critical": { Critical = new Point(int.Parse(node.Attributes["min"].Value), int.Parse(node.Attributes["max"].Value)); CriticalMultiplier = int.Parse(node.Attributes["multiplier"].Value); } break; case "shortname": { ShortName = node.InnerText; } break; case "identifiedname": { IdentifiedName = node.InnerText; } break; case "isidentified": { IsIdentified = bool.Parse(node.Attributes["value"].Value); } break; case "isbig": { IsBig = true; } break; case "canidentify": { CanIdentify = bool.Parse(node.Attributes["value"].Value); } break; case "speed": { AttackSpeed = TimeSpan.FromMilliseconds(int.Parse(node.Attributes["value"].Value)); } break; case "ac": { ArmorClass = Byte.Parse(node.Attributes["value"].Value); } break; case "tile": { TileSetName = node.Attributes["name"].Value; TileID = int.Parse(node.Attributes["inventory"].Value); GroundTileID = int.Parse(node.Attributes["ground"].Value); IncomingTileID = int.Parse(node.Attributes["incoming"].Value); ThrowTileID = int.Parse(node.Attributes["moveaway"].Value); } break; case "classes": { AllowedClasses = (HeroClass)Enum.Parse(typeof(HeroClass), node.Attributes["value"].Value); } break; case "allowedhands": { AllowedHands = (HeroHand)Enum.Parse(typeof(HeroHand), node.Attributes["value"].Value); } break; case "cursed": { IsCursed = bool.Parse(node.Attributes["value"].Value); } break; case "twohanded": { TwoHanded = bool.Parse(node.Attributes["value"].Value); } break; } } return(true); }