示例#1
0
        public override void Deserialize(OtFileReader fileReader, OtFileNode node, OtPropertyReader reader, OtItems items)
        {
            base.Deserialize(fileReader, node, reader, items);

            var itemNode = node.Child;

            while (itemNode != null)
            {
                if ((OtMap.OtMapNodeTypes)itemNode.Type != OtMap.OtMapNodeTypes.ITEM)
                {
                    throw new Exception("Invalid item node inside container.");
                }

                OtPropertyReader props = fileReader.GetPropertyReader(itemNode);

                var itemId   = props.ReadUInt16();
                var itemType = items.GetItem(itemId);
                if (itemType == null)
                {
                    throw new Exception("Unkonw item type " + itemId + " inside container.");
                }

                var item = OtItem.Create(itemType);
                item.Deserialize(fileReader, itemNode, props, items);

                Items.Add(item);

                itemNode = itemNode.Next;
            }
        }
示例#2
0
        public void AddItem(OtItem item)
        {
            if (item.Type.Group == OtItemGroup.Ground)
            {
                ground = item;
                mapColor = Misc.GetAutomapColor(item.Type.MinimapColor);
            }
            else
            {
                if (item.Type.AlwaysOnTop)
                {
                    bool inserted = false;

                    for (int i = downItemCount; i < ItemCount; i++)
                    {
                        if (Items[i].Type.AlwaysOnTopOrder < item.Type.AlwaysOnTopOrder)
                            continue;

                        Items.Insert(i, item);
                        inserted = true;
                        break;
                    }

                    if (!inserted)
                        Items.Add(item);
                }
                else if (item.Type.IsMoveable)
                {
                    bool inserted = false;

                    for (int i = downItemCount; i < ItemCount; i++)
                    {
                        if (Items[i].Type.AlwaysOnTopOrder < item.Type.AlwaysOnTopOrder)
                        {
                            Items.Insert(i, item);
                            inserted = true;
                            break;
                        }
                    }

                    if (!inserted)
                    {
                        Items.Add(item);
                    }
                }
                else
                {
                    Items.Insert(0, item);
                    ++downItemCount;
                }

                Color color = Misc.GetAutomapColor(item.Type.MinimapColor);
                if (color != Color.Black)
                    mapColor = color;
            }
        }
示例#3
0
        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);
        }
示例#4
0
        public void AddItem(OtItem item)
        {
            if (item.Type.Group == OtItemGroup.Ground)
            {
                ground   = item;
                mapColor = Misc.GetAutomapColor(item.Type.MinimapColor);
            }
            else
            {
                if (item.Type.AlwaysOnTop)
                {
                    bool inserted = false;

                    for (int i = downItemCount; i < ItemCount; i++)
                    {
                        if (Items[i].Type.AlwaysOnTopOrder < item.Type.AlwaysOnTopOrder)
                        {
                            continue;
                        }

                        Items.Insert(i, item);
                        inserted = true;
                        break;
                    }

                    if (!inserted)
                    {
                        Items.Add(item);
                    }
                }
                else if (item.Type.IsMoveable)
                {
                    bool inserted = false;

                    for (int i = downItemCount; i < ItemCount; i++)
                    {
                        if (Items[i].Type.AlwaysOnTopOrder < item.Type.AlwaysOnTopOrder)
                        {
                            Items.Insert(i, item);
                            inserted = true;
                            break;
                        }
                    }

                    if (!inserted)
                    {
                        Items.Add(item);
                    }
                }
                else
                {
                    Items.Insert(0, item);
                    ++downItemCount;
                }

                Color color = Misc.GetAutomapColor(item.Type.MinimapColor);
                if (color != Color.Black)
                {
                    mapColor = color;
                }
            }
        }
示例#5
0
        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;
        }
示例#6
0
        private void ParseTileArea(OtFileReader reader, OtFileNode otbNode, bool replaceTiles, ISet <ulong> tileLocations)
        {
            OtPropertyReader props = reader.GetPropertyReader(otbNode);

            int baseX = props.ReadUInt16();
            int baseY = props.ReadUInt16();
            int baseZ = props.ReadByte();

            OtFileNode nodeTile = otbNode.Child;

            while (nodeTile != null)
            {
                if (nodeTile.Type == (long)OtMapNodeTypes.TILE ||
                    nodeTile.Type == (long)OtMapNodeTypes.HOUSETILE)
                {
                    props = reader.GetPropertyReader(nodeTile);

                    var tileLocation = new Location(baseX + props.ReadByte(), baseY + props.ReadByte(), baseZ);

                    var tile = new OtTile(tileLocation);

                    if (nodeTile.Type == (long)OtMapNodeTypes.HOUSETILE)
                    {
                        tile.HouseId = props.ReadUInt32();
                    }

                    while (props.PeekChar() != -1)
                    {
                        byte attribute = props.ReadByte();
                        switch ((OtMapAttribute)attribute)
                        {
                        case OtMapAttribute.TILE_FLAGS:
                        {
                            tile.Flags = props.ReadUInt32();
                            break;
                        }

                        case OtMapAttribute.ITEM:
                        {
                            ushort itemId = props.ReadUInt16();

                            var itemType = Items.GetItem(itemId);
                            if (itemType == null)
                            {
                                throw new Exception("Unkonw item type " + itemId + " in position " + tileLocation + ".");
                            }

                            var item = OtItem.Create(itemType);
                            tile.InternalAddItem(item);

                            break;
                        }

                        default:
                            throw new Exception(string.Format("{0} Unknown tile attribute.", tileLocation));
                        }
                    }

                    OtFileNode nodeItem = nodeTile.Child;

                    while (nodeItem != null)
                    {
                        if (nodeItem.Type == (long)OtMapNodeTypes.ITEM)
                        {
                            props = reader.GetPropertyReader(nodeItem);

                            ushort itemId = props.ReadUInt16();

                            var itemType = Items.GetItem(itemId);
                            if (itemType == null)
                            {
                                throw new Exception("Unkonw item type " + itemId + " in position " + tileLocation + ".");
                            }

                            var item = OtItem.Create(itemType);
                            item.Deserialize(reader, nodeItem, props, Items);

                            tile.InternalAddItem(item);
                        }
                        else
                        {
                            throw new Exception(string.Format("{0} Unknown node type.", tileLocation));
                        }
                        nodeItem = nodeItem.Next;
                    }

                    var index   = tileLocation.ToIndex();
                    var hasTile = HasTile(index);

                    if (!hasTile)
                    {
                        SetTile(tile);
                        tileLocations.Add(tileLocation.ToIndex());
                    }
                    else if (replaceTiles)
                    {
                        SetTile(tile);
                    }
                }

                nodeTile = nodeTile.Next;
            }
        }