Пример #1
0
        /// <summary>
        /// Player has started a buy transaction
        /// Create objects, send object to player for final validation.
        /// </summary>
        /// <param name="vendorid">GUID of Vendor</param>
        /// <param name="items">Item Profile, Ammount and ID</param>
        /// <param name="player"></param>
        public void BuyValidateTransaction(ObjectGuid vendorid, List <ItemProfile> items, Player player)
        {
            // que transactions.
            List <ItemProfile> filteredlist = new List <ItemProfile>();
            List <WorldObject> uqlist       = new List <WorldObject>();
            List <WorldObject> genlist      = new List <WorldObject>();

            uint goldcost = 0;

            // filter items out vendor no longer has in stock or never had in stock
            foreach (ItemProfile item in items)
            {
                // check default items for id
                if (defaultItemsForSale.ContainsKey(item.Guid))
                {
                    item.WeenieClassId = defaultItemsForSale[item.Guid].WeenieClassId;
                    filteredlist.Add(item);
                }

                // check unique items / add unique items to purchaselist / remove from vendor list
                if (uniqueItemsForSale.ContainsKey(item.Guid))
                {
                    if (uniqueItemsForSale.TryGetValue(item.Guid, out var wo))
                    {
                        uqlist.Add(wo);
                        uniqueItemsForSale.Remove(item.Guid);
                    }
                }
            }

            // convert profile to wold objects / stack logic does not include unique items.
            foreach (ItemProfile fitem in filteredlist)
            {
                genlist.AddRange(ItemProfileToWorldObjects(fitem));
            }

            // calculate price. (both unique and item profile)
            foreach (WorldObject wo in uqlist)
            {
                goldcost          = goldcost + (uint)Math.Ceiling((SellPrice ?? 1) * (wo.Value ?? 0) * (wo.StackSize ?? 1) - 0.1);
                wo.Value          = wo.Value;           // Also set the stack's value for unique items, using the builtin WO calculations
                wo.EncumbranceVal = wo.EncumbranceVal;  // Also set the stack's encumbrance for unique items, using the builtin WO calculations
            }

            foreach (WorldObject wo in genlist)
            {
                goldcost          = goldcost + (uint)Math.Ceiling((SellPrice ?? 1) * (wo.Value ?? 0) * (wo.StackSize ?? 1) - 0.1);
                wo.Value          = wo.Value;           // Also set the stack's value for stock items, using the builtin WO calculations
                wo.EncumbranceVal = wo.EncumbranceVal;  // Also set the stack's encumbrance for stock items, using the builtin WO calculations
            }

            // send transaction to player for further processing and.
            player.FinalizeBuyTransaction(this, uqlist, genlist, true, goldcost);
        }
Пример #2
0
        /// <summary>
        /// Handles validation for player buying items from vendor
        /// </summary>
        /// <param name="items">Item Profile, Ammount and ID</param>
        /// <param name="player"></param>
        public void BuyItems_ValidateTransaction(List <ItemProfile> items, Player player)
        {
            // queue transactions
            List <ItemProfile> filteredlist = new List <ItemProfile>();
            List <WorldObject> uqlist       = new List <WorldObject>();
            List <WorldObject> genlist      = new List <WorldObject>();

            uint goldcost = 0;

            // filter items out vendor no longer has in stock or never had in stock
            foreach (ItemProfile item in items)
            {
                // check default items for id
                if (DefaultItemsForSale.ContainsKey(new ObjectGuid(item.ObjectGuid)))
                {
                    item.WeenieClassId = DefaultItemsForSale[new ObjectGuid(item.ObjectGuid)].WeenieClassId;
                    item.Palette       = DefaultItemsForSale[new ObjectGuid(item.ObjectGuid)].PaletteTemplate;
                    item.Shade         = DefaultItemsForSale[new ObjectGuid(item.ObjectGuid)].Shade;
                    filteredlist.Add(item);
                }

                // check unique items / add unique items to purchaselist / remove from vendor list
                if (UniqueItemsForSale.ContainsKey(new ObjectGuid(item.ObjectGuid)))
                {
                    if (UniqueItemsForSale.TryGetValue(new ObjectGuid(item.ObjectGuid), out var wo))
                    {
                        uqlist.Add(wo);
                        UniqueItemsForSale.Remove(new ObjectGuid(item.ObjectGuid));
                    }
                }
            }

            // convert profile to world objects / stack logic does not include unique items.
            foreach (ItemProfile fitem in filteredlist)
            {
                genlist.AddRange(ItemProfileToWorldObjects(fitem));
            }

            // calculate price. (both unique and item profile)
            foreach (WorldObject wo in uqlist)
            {
                var sellRate = SellPrice ?? 1.0;
                if (wo.ItemType == ItemType.PromissoryNote)
                {
                    sellRate = 1.15;
                }

                goldcost += (uint)Math.Ceiling((wo.Value ?? 0) * sellRate - 0.1);
            }

            foreach (WorldObject wo in genlist)
            {
                var sellRate = SellPrice ?? 1.0;
                if (wo.ItemType == ItemType.PromissoryNote)
                {
                    sellRate = 1.15;
                }

                goldcost += (uint)Math.Ceiling((wo.Value ?? 0) * sellRate - 0.1);
            }

            // send transaction to player for further processing and.
            player.FinalizeBuyTransaction(this, uqlist, genlist, true, goldcost);
        }