Пример #1
0
        /// <summary>Gets an item chat link for this item.</summary>
        /// <returns>The <see cref="ChatLink"/>.</returns>
        public virtual ChatLink GetItemChatLink()
        {
            ItemChatLink chatLink;
            var item = this.Item;
            if (item == null)
            {
                chatLink = new ItemChatLink { ItemId = this.ItemId };
            }
            else
            {
                chatLink = (ItemChatLink)item.GetItemChatLink();
            }

            chatLink.Quantity = this.Count;
            return chatLink;
        }
Пример #2
0
        /// <summary>Decodes chat links.</summary>
        /// <param name="input">A chat link.</param>
        /// <exception cref="ArgumentNullException">The value of <paramref name="input"/> is a null reference.</exception>
        /// <returns>A decoded <see cref="ChatLink"/>.</returns>
        public ChatLink Decode(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            input = input.Trim('[', ']', '&');
            byte[] bytes = new byte[Size];
            Convert.FromBase64String(input).CopyTo(bytes, 0);
            var ptr  = Marshal.AllocHGlobal(Size);
            var link = new ChatLinkStruct();

            try
            {
                Marshal.Copy(bytes, 0, ptr, Size);
                Marshal.PtrToStructure(ptr, link);
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }

            switch (link.header)
            {
            case Header.Coin:
                return(new CoinChatLink {
                    Quantity = link.coin.count
                });

            case Header.Item:
                var chatLink = new ItemChatLink
                {
                    ItemId   = (int)link.item.itemId.Value,
                    Quantity = link.item.count,
                };

                var modifiers = new Stack <int>(3);
                modifiers.Push(link.item.modifier3);
                modifiers.Push(link.item.modifier2);
                modifiers.Push(link.item.modifier1);
                if (link.item.Modifiers.HasFlag(ItemModifiers.Skin))
                {
                    chatLink.SkinId = modifiers.Pop();
                }

                if (link.item.Modifiers.HasFlag(ItemModifiers.SuffixItem))
                {
                    chatLink.SuffixItemId = modifiers.Pop();
                }

                if (link.item.Modifiers.HasFlag(ItemModifiers.SecondarySuffixItem))
                {
                    chatLink.SecondarySuffixItemId = modifiers.Pop();
                }

                return(chatLink);

            case Header.Text:
                return(new DialogChatLink {
                    DialogId = link.text.dialogId
                });

            case Header.Map:
                return(new PointOfInterestChatLink {
                    PointOfInterestId = link.map.pointOfInterestId
                });

            case Header.Skill:
                return(new SkillChatLink {
                    SkillId = link.skill.skillId
                });

            case Header.Trait:
                return(new TraitChatLink {
                    TraitId = link.trait.traitId
                });

            case Header.Recipe:
                return(new RecipeChatLink {
                    RecipeId = link.recipe.recipeId
                });

            case Header.Skin:
                return(new SkinChatLink {
                    SkinId = link.skin.skinId
                });

            case Header.Outfit:
                return(new OutfitChatLink {
                    OutfitId = link.outfit.outfitId
                });

            default:
                return(null);
            }
        }