private void LoadAttributes(OtItemType itemType, XElement element) { foreach (var property in element.Elements("attribute")) { switch (property.Attribute("key").GetString()) { case "description": itemType.Description = property.Attribute("value").GetString(); break; case "type": switch (property.Attribute("value").GetString()) { case "container": itemType.Group = OtItemGroup.Container; break; case "key": itemType.Group = OtItemGroup.Key; break; case "magicfield": itemType.Group = OtItemGroup.MagicField; break; case "depot": itemType.Group = OtItemGroup.Depot; break; case "mailbox": itemType.Group = OtItemGroup.MailBox; break; case "trashholder": itemType.Group = OtItemGroup.TrashHolder; break; case "teleport": itemType.Group = OtItemGroup.Teleport; break; case "door": itemType.Group = OtItemGroup.Door; break; case "bed": itemType.Group = OtItemGroup.Bed; break; case "rune": itemType.Group = OtItemGroup.Rune; break; } break; } } }
public static OtItem Create(OtItemType type) { OtItem item = null; if (type.Group == OtItemGroup.Depot) { item = new OtDepot(type); } else if (type.Group == OtItemGroup.Container) { item = new OtContainer(type); } else if (type.Group == OtItemGroup.Teleport) { item = new OtTeleport(type); } else if (type.Group == OtItemGroup.MagicField) { item = new OtMagicField(type); } else if (type.Group == OtItemGroup.Door) { item = new OtDoor(type); } else if (type.Group == OtItemGroup.TrashHolder) { item = new OtTrashHolder(type); } else if (type.Group == OtItemGroup.MailBox) { item = new OtMailBox(type); } else { item = new OtItem(type); } return(item); }
public static OtItem Create(OtItemType type) { OtItem item = null; if (type.Group == OtItemGroup.Depot) item = new OtDepot(type); else if (type.Group == OtItemGroup.Container) item = new OtContainer(type); else if (type.Group == OtItemGroup.Teleport) item = new OtTeleport(type); else if (type.Group == OtItemGroup.MagicField) item = new OtMagicField(type); else if (type.Group == OtItemGroup.Door) item = new OtDoor(type); else if (type.Group == OtItemGroup.TrashHolder) item = new OtTrashHolder(type); else if (type.Group == OtItemGroup.MailBox) item = new OtMailBox(type); else item = new OtItem(type); return item; }
public void LoadOtb(string fileName) { if (!File.Exists(fileName)) { throw new Exception(string.Format("File not found {0}.", fileName)); } using (var reader = new OtFileReader(fileName)) { var node = reader.GetRootNode(); OtPropertyReader props = reader.GetPropertyReader(node); props.ReadByte(); //junk? props.ReadUInt32(); byte attr = props.ReadByte(); if ((RootAttr)attr == RootAttr.ROOT_ATTR_VERSION) { var datalen = props.ReadUInt16(); if (datalen != 140) { throw new Exception("Size of version header is invalid."); } MajorVersion = props.ReadUInt32(); MinorVersion = props.ReadUInt32(); BuildNumber = props.ReadUInt32(); } if (MajorVersion == 0xFFFFFFFF) { Trace.WriteLine("[Warning] items.otb using generic client version."); } else if (MajorVersion < 3) { throw new Exception("Old version of items.otb detected, a newer version of items.otb is required."); } else if (MajorVersion > 3) { throw new Exception("New version of items.otb detected, a newer version of the server is required."); } node = node.Child; while (node != null) { props = reader.GetPropertyReader(node); OtItemType item = new OtItemType(); byte itemGroup = (byte)node.Type; switch ((OtbItemGroup)itemGroup) { case OtbItemGroup.NONE: item.Group = OtItemGroup.None; break; case OtbItemGroup.GROUND: item.Group = OtItemGroup.Ground; break; case OtbItemGroup.SPLASH: item.Group = OtItemGroup.Splash; break; case OtbItemGroup.FLUID: item.Group = OtItemGroup.FluidContainer; break; case OtbItemGroup.CONTAINER: item.Group = OtItemGroup.Container; break; case OtbItemGroup.DEPRECATED: item.Group = OtItemGroup.Deprecated; break; default: break; } OtbItemFlags flags = (OtbItemFlags)props.ReadUInt32(); item.BlockObject = ((flags & OtbItemFlags.BLOCK_SOLID) == OtbItemFlags.BLOCK_SOLID); item.BlockProjectile = ((flags & OtbItemFlags.BLOCK_PROJECTILE) == OtbItemFlags.BLOCK_PROJECTILE); item.BlockPathFind = ((flags & OtbItemFlags.BLOCK_PATHFIND) == OtbItemFlags.BLOCK_PATHFIND); item.IsPickupable = ((flags & OtbItemFlags.PICKUPABLE) == OtbItemFlags.PICKUPABLE); item.IsMoveable = ((flags & OtbItemFlags.MOVEABLE) == OtbItemFlags.MOVEABLE); item.IsStackable = ((flags & OtbItemFlags.STACKABLE) == OtbItemFlags.STACKABLE); item.AlwaysOnTop = ((flags & OtbItemFlags.ALWAYSONTOP) == OtbItemFlags.ALWAYSONTOP); item.IsVertical = ((flags & OtbItemFlags.VERTICAL) == OtbItemFlags.VERTICAL); item.IsHorizontal = ((flags & OtbItemFlags.HORIZONTAL) == OtbItemFlags.HORIZONTAL); item.IsHangable = ((flags & OtbItemFlags.HANGABLE) == OtbItemFlags.HANGABLE); item.IsRotatable = ((flags & OtbItemFlags.ROTABLE) == OtbItemFlags.ROTABLE); item.IsReadable = ((flags & OtbItemFlags.READABLE) == OtbItemFlags.READABLE); item.HasUseWith = ((flags & OtbItemFlags.USEABLE) == OtbItemFlags.USEABLE); item.HasHeight = ((flags & OtbItemFlags.HAS_HEIGHT) == OtbItemFlags.HAS_HEIGHT); item.LookThrough = ((flags & OtbItemFlags.LOOKTHROUGH) == OtbItemFlags.LOOKTHROUGH); item.AllowDistRead = ((flags & OtbItemFlags.ALLOWDISTREAD) == OtbItemFlags.ALLOWDISTREAD); item.IsAnimation = ((flags & OtbItemFlags.ANIMATION) == OtbItemFlags.ANIMATION); item.WalkStack = ((flags & OtbItemFlags.WALKSTACK) == OtbItemFlags.WALKSTACK); while (props.PeekChar() != -1) { byte attribute = props.ReadByte(); UInt16 datalen = props.ReadUInt16(); switch ((OtbItemAttr)attribute) { case OtbItemAttr.ITEM_ATTR_SERVERID: if (datalen != sizeof(UInt16)) { throw new Exception("Unexpected data length of server id block (Should be 2 bytes)"); } item.Id = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_CLIENTID: if (datalen != sizeof(UInt16)) { throw new Exception("Unexpected data length of client id block (Should be 2 bytes)"); } item.SpriteId = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_WAREID: if (datalen != sizeof(UInt16)) { throw new Exception("Unexpected data length of ware id block (Should be 2 bytes)"); } item.WareId = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_SPEED: if (datalen != sizeof(UInt16)) { throw new Exception("Unexpected data length of speed block (Should be 2 bytes)"); } item.GroundSpeed = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_NAME: item.Name = new string(props.ReadChars(datalen)); break; case OtbItemAttr.ITEM_ATTR_SPRITEHASH: if (datalen != 16) { throw new Exception("Unexpected data length of sprite hash (Should be 16 bytes)"); } item.SpriteHash = props.ReadBytes(16); break; case OtbItemAttr.ITEM_ATTR_MINIMAPCOLOR: if (datalen != 2) { throw new Exception("Unexpected data length of minimap color (Should be 2 bytes)"); } item.MinimapColor = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_07: //read/write-able if (datalen != 2) { throw new Exception("Unexpected data length of attr 07 (Should be 2 bytes)"); } item.MaxReadWriteChars = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_08: //readable if (datalen != 2) { throw new Exception("Unexpected data length of attr 08 (Should be 2 bytes)"); } item.MaxReadChars = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_LIGHT2: if (datalen != sizeof(UInt16) * 2) { throw new Exception("Unexpected data length of item light (2) block"); } item.LightLevel = props.ReadUInt16(); item.LightColor = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_TOPORDER: if (datalen != sizeof(byte)) { throw new Exception("Unexpected data length of item toporder block (Should be 1 byte)"); } item.AlwaysOnTopOrder = props.ReadByte(); break; default: //skip unknown attributes props.ReadBytes(datalen); break; } } AddItem(item); node = node.Next; } } }
public void AddItem(OtItemType item) { serverItemMap[item.Id] = item; clientItemMap[item.SpriteId] = item; }
public OtDoor(OtItemType type) : base(type) { }
public OtMailBox(OtItemType type) : base(type) { }
public OtDepot(OtItemType type) : base(type) { }
protected OtItem(OtItemType type) { Type = type; }
public OtTeleport(OtItemType type) : base(type) { }
public void LoadOtb(string fileName) { if (!File.Exists(fileName)) throw new Exception(string.Format("File not found {0}.", fileName)); using (var reader = new OtFileReader(fileName)) { var node = reader.GetRootNode(); OtPropertyReader props = reader.GetPropertyReader(node); props.ReadByte(); //junk? props.ReadUInt32(); byte attr = props.ReadByte(); if ((RootAttr)attr == RootAttr.ROOT_ATTR_VERSION) { var datalen = props.ReadUInt16(); if (datalen != 140) throw new Exception("Size of version header is invalid."); MajorVersion = props.ReadUInt32(); MinorVersion = props.ReadUInt32(); BuildNumber = props.ReadUInt32(); } if (MajorVersion == 0xFFFFFFFF) Trace.WriteLine("[Warning] items.otb using generic client version."); else if (MajorVersion < 3) throw new Exception("Old version of items.otb detected, a newer version of items.otb is required."); else if (MajorVersion > 3) throw new Exception("New version of items.otb detected, a newer version of the server is required."); node = node.Child; while (node != null) { props = reader.GetPropertyReader(node); OtItemType item = new OtItemType(); byte itemGroup = (byte)node.Type; switch ((OtbItemGroup)itemGroup) { case OtbItemGroup.NONE: item.Group = OtItemGroup.None; break; case OtbItemGroup.GROUND: item.Group = OtItemGroup.Ground; break; case OtbItemGroup.SPLASH: item.Group = OtItemGroup.Splash; break; case OtbItemGroup.FLUID: item.Group = OtItemGroup.FluidContainer; break; case OtbItemGroup.CONTAINER: item.Group = OtItemGroup.Container; break; case OtbItemGroup.DEPRECATED: item.Group = OtItemGroup.Deprecated; break; default: break; } OtbItemFlags flags = (OtbItemFlags)props.ReadUInt32(); item.BlockObject = ((flags & OtbItemFlags.BLOCK_SOLID) == OtbItemFlags.BLOCK_SOLID); item.BlockProjectile = ((flags & OtbItemFlags.BLOCK_PROJECTILE) == OtbItemFlags.BLOCK_PROJECTILE); item.BlockPathFind = ((flags & OtbItemFlags.BLOCK_PATHFIND) == OtbItemFlags.BLOCK_PATHFIND); item.IsPickupable = ((flags & OtbItemFlags.PICKUPABLE) == OtbItemFlags.PICKUPABLE); item.IsMoveable = ((flags & OtbItemFlags.MOVEABLE) == OtbItemFlags.MOVEABLE); item.IsStackable = ((flags & OtbItemFlags.STACKABLE) == OtbItemFlags.STACKABLE); item.AlwaysOnTop = ((flags & OtbItemFlags.ALWAYSONTOP) == OtbItemFlags.ALWAYSONTOP); item.IsVertical = ((flags & OtbItemFlags.VERTICAL) == OtbItemFlags.VERTICAL); item.IsHorizontal = ((flags & OtbItemFlags.HORIZONTAL) == OtbItemFlags.HORIZONTAL); item.IsHangable = ((flags & OtbItemFlags.HANGABLE) == OtbItemFlags.HANGABLE); item.IsRotatable = ((flags & OtbItemFlags.ROTABLE) == OtbItemFlags.ROTABLE); item.IsReadable = ((flags & OtbItemFlags.READABLE) == OtbItemFlags.READABLE); item.HasUseWith = ((flags & OtbItemFlags.USEABLE) == OtbItemFlags.USEABLE); item.HasHeight = ((flags & OtbItemFlags.HAS_HEIGHT) == OtbItemFlags.HAS_HEIGHT); item.LookThrough = ((flags & OtbItemFlags.LOOKTHROUGH) == OtbItemFlags.LOOKTHROUGH); item.AllowDistRead = ((flags & OtbItemFlags.ALLOWDISTREAD) == OtbItemFlags.ALLOWDISTREAD); item.IsAnimation = ((flags & OtbItemFlags.ANIMATION) == OtbItemFlags.ANIMATION); item.WalkStack = ((flags & OtbItemFlags.WALKSTACK) == OtbItemFlags.WALKSTACK); while (props.PeekChar() != -1) { byte attribute = props.ReadByte(); UInt16 datalen = props.ReadUInt16(); switch ((OtbItemAttr)attribute) { case OtbItemAttr.ITEM_ATTR_SERVERID: if (datalen != sizeof(UInt16)) throw new Exception("Unexpected data length of server id block (Should be 2 bytes)"); item.Id = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_CLIENTID: if (datalen != sizeof(UInt16)) throw new Exception("Unexpected data length of client id block (Should be 2 bytes)"); item.SpriteId = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_WAREID: if (datalen != sizeof(UInt16)) throw new Exception("Unexpected data length of ware id block (Should be 2 bytes)"); item.WareId = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_SPEED: if (datalen != sizeof(UInt16)) throw new Exception("Unexpected data length of speed block (Should be 2 bytes)"); item.GroundSpeed = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_NAME: item.Name = new string(props.ReadChars(datalen)); break; case OtbItemAttr.ITEM_ATTR_SPRITEHASH: if (datalen != 16) throw new Exception("Unexpected data length of sprite hash (Should be 16 bytes)"); item.SpriteHash = props.ReadBytes(16); break; case OtbItemAttr.ITEM_ATTR_MINIMAPCOLOR: if (datalen != 2) throw new Exception("Unexpected data length of minimap color (Should be 2 bytes)"); item.MinimapColor = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_07: //read/write-able if (datalen != 2) throw new Exception("Unexpected data length of attr 07 (Should be 2 bytes)"); item.MaxReadWriteChars = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_08: //readable if (datalen != 2) throw new Exception("Unexpected data length of attr 08 (Should be 2 bytes)"); item.MaxReadChars = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_LIGHT2: if (datalen != sizeof(UInt16) * 2) throw new Exception("Unexpected data length of item light (2) block"); item.LightLevel = props.ReadUInt16(); item.LightColor = props.ReadUInt16(); break; case OtbItemAttr.ITEM_ATTR_TOPORDER: if (datalen != sizeof(byte)) throw new Exception("Unexpected data length of item toporder block (Should be 1 byte)"); item.AlwaysOnTopOrder = props.ReadByte(); break; default: //skip unknown attributes props.ReadBytes(datalen); break; } } AddItem(item); node = node.Next; } } }
public OtMagicField(OtItemType type) : base(type) { }
public OtContainer(OtItemType type) : base(type) { }
public OtTrashHolder(OtItemType type) : base(type) { }