Exemple #1
0
        /**
         * Client sends cash item SN.
         * We index cash items by their serial number.
         * WZ files indexes cash items by a commodity ID.
         * The commodity ID (~12000 total) is not used for anything.
         */
        public static void Buy(WvsShopClient c, CInPacket p)
        {
            // validate packet length
            if (p.Available < 9)
            {
                return;
            }

            p.Decode1();             // 00
            var cashType     = (CashType)p.Decode4();
            var nCommoditySN = p.Decode4();

            var commodityInfo = MasterManager.CommodityProvider[nCommoditySN];

            if (commodityInfo == null)
            {
                return;
            }
            if (!commodityInfo.OnSale)
            {
                return;                                    // TODO proper error code/response
            }
            var item = MasterManager.CreateCashCommodityItem(nCommoditySN);

            if (item is null)
            {
                return;
            }

            if (!c.Account.HasCash(cashType, item.NXCost))
            {
                return;                                                        // TODO proper error code/response
            }
            if (ItemConstants.IsPet(item.nItemID) &&
                InventoryManipulator.GetItemByCashSN(c.Character, InventoryType.Cash, item.SN).Item2 != null)
            {
                return;                 // cant have two of the same pet cuz it screws up our indexing
            }
            c.CashLocker.Add(item);
#if DEBUG
            c.Account.ModifyCash(cashType, 10000);
            Log.Info($"{commodityInfo.CashItemSN}");
#else
            c.Account.ModifyCash(cashType, -commodityInfo.Price);
#endif
            item.dwAccountID   = c.Account.ID;
            item.dwCharacterID = c.dwCharId;

            c.SendPacket(CPacket.CCashShop.BuyResponse(item));
            // do best items/limited goods handling here
        }
Exemple #2
0
        /// <summary>
        /// Move an item from the character's storage to the character's account cash locker
        /// </summary>
        /// <param name="c"></param>
        /// <param name="p"></param>
        public static void MoveSToL(WvsShopClient c, CInPacket p)
        {
            if (p.Available < 9)
            {
                return;
            }

            var cashCommodityId = p.Decode8();
            var nTI             = (InventoryType)p.Decode1();

            var(itemSlot, item) = InventoryManipulator.GetItemByCashSN(c.Character, nTI, cashCommodityId);

            // unable to find item in inventory
            if (item is null)
            {
                return;
            }

            if (ItemConstants.IsRing(item.nItemID))
            {
                c.SendPacket(CPacket.CCashShop.RequestFailPacket(CashItemOps.CashItemRes_MoveStoL_Failed, CashItemFailed.NotAvailableTime));
                return;
            }

            var newItem = MasterManager.CreateCashCommodityItem(item.liCashItemSN);

            newItem.Item.nNumber     = item.nNumber;
            newItem.Item.liSN        = item.liSN;
            newItem.Item.tDateExpire = item.tDateExpire;
            //newItem.dwCharacterID = // TODO
            newItem.dwAccountID = c.Character.Account.ID;

            c.CashLocker.Add(newItem);
            InventoryManipulator.RemoveFrom(c.Character, nTI, itemSlot, -1);

            c.SendPacket(CPacket.CCashShop.MoveSToLResponse(c.CashLocker, newItem));
        }