Example #1
0
        private static void SellItem(Character pChar, short nSlot, int nItemId, short nCount)
        {
            var pItem = InventoryManipulator.GetItem(pChar, ItemConstants.GetInventoryType(nItemId), nSlot);

            if (pItem is null)
            {
                pChar.SendMessage("Trying to sell null item.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.SellIncorrectRequest));
                return;
            }

            if (pItem.CashItem || pItem.NotSale)
            {
                pChar.SendMessage("Cannot trade cash items.");
                return;
            }

            var nCostPerItem = pItem.Template.Price;

            nCount = ItemConstants.is_treat_singly(nItemId) ? (short)1 : nCount;

            var nFinalCost = nCostPerItem * nCount;

            if (pItem.IsRechargeable)
            {
                var dUnitPrice = ((ConsumeItemTemplate)pItem.Template).UnitPrice;

                nFinalCost += (int)Math.Floor(dUnitPrice * pItem.nNumber);
            }

            if (pItem is GW_ItemSlotBundle && !pItem.IsRechargeable)
            {
                if (pItem.nNumber < nCount)
                {
                    pChar.SendMessage("Trying to sell more than you possess.");
                    pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.SellIncorrectRequest));
                    return;
                }

                if (nCount <= 0)
                {
                    pChar.SendMessage("Trying to sell negative amount.");
                    pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.SellIncorrectRequest));
                    return;
                }
            }
            else
            {
                nCount = -1;
            }

            pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.SellSuccess));

            //pChar.SendMessage("final price: " + nFinalCost);

            InventoryManipulator.RemoveFrom(pChar, pItem.InvType, nSlot, nCount);
            pChar.Modify.GainMeso(nFinalCost, false);
        }
        public void HandleAddItem(CInPacket p, Character pChar)
        {
            if (dwFirstLockerId == pChar.dwId || !acceptedInvite)
            {
                return;
            }

            var nTI         = (InventoryType)p.Decode1();
            var nCurInvSlot = p.Decode2(); // in inventory
            var nCount      = p.Decode2();
            var nTargetSlot = p.Decode1(); // in trade window

            var pItem = InventoryManipulator.GetItem(pChar, nTI, nCurInvSlot);

            var tempInv = GetTempInv(pChar);

            if (pItem is null || !tempInv.CanAddToSlot(nTargetSlot))
            {
                return;
            }

            if (ItemConstants.is_treat_singly(pItem.nItemID))
            {
                nCount = -1; // negative amount clears the slot
            }
            else
            {
                nCount = Math.Min(pItem.nNumber, Math.Abs(nCount));
            }

            InventoryManipulator.RemoveFrom(pChar, nTI, nCurInvSlot, nCount);

            if (pItem is GW_ItemSlotBundle pBundle && !pBundle.IsRechargeable)
            {
                pItem         = pItem.DeepCopy();
                pItem.nNumber = nCount;
            }

            var pTempItem = new TempItem(pItem, nCurInvSlot, nTargetSlot);

            tempInv.Add(pTempItem);

            Parent.SendPacket(AddItemPacket(pTempItem, !IsOwner(pChar)));
            Partner.SendPacket(AddItemPacket(pTempItem, IsOwner(pChar)));
        }
Example #3
0
        public static void Drop(Character pChar, InventoryType nInvType, short invSlot, short amount)
        {
            // validate raw input
            if (amount <= 0)
            {
                return;                          // PE
            }
            if ((byte)nInvType > 5)
            {
                return;                                 // cant drop things out of equipped inventories
            }
            var pItem = GetItem(pChar, nInvType, invSlot);

            if (pItem is null)
            {
                return;                            // PE or lag
            }
            if (amount < 1)
            {
                amount = 1;                         // not neccessarily PE
            }
            if (amount > pItem.nNumber)             // TODO maybe anticheat here
            {
                amount = pItem.nNumber;
            }

            if (ItemConstants.is_treat_singly(pItem.nItemID) || amount < 1)
            {
                RemoveFrom(pChar, nInvType, invSlot, -1);

                CDropFactory.CreateDropItem(pChar.Field, pChar.Position.CurrentXY.Clone(), pChar.dwId, pItem);
            }
            else
            {
                var cNewDropItem = pItem.DeepCopy();
                cNewDropItem.nNumber = amount;

                RemoveFrom(pChar, nInvType, invSlot, amount);

                CDropFactory.CreateDropItem(pChar.Field, pChar.Position.CurrentXY.Clone(), pChar.dwId, cNewDropItem);
            }
        }
Example #4
0
        public void AddItem(CInPacket p)
        {
            var nTI             = (InventoryType)p.Decode1();
            var nPOS            = p.Decode2();
            var nBundles        = Math.Max((short)1, p.Decode2());
            var nPricePerBundle = Math.Max((short)1, p.Decode2());
            var nPrice          = Math.Max(1, p.Decode4());

            var pItem = InventoryManipulator.GetItem(Parent, nTI, nPOS);

            if (pItem is null)
            {
                Parent.SendMessage("item is null u fucc");
                return;
            }

            var nQuantityRequested = -1; // negative so its removed completely from inventory

            if (!ItemConstants.is_treat_singly(pItem.nItemID))
            {
                nQuantityRequested = nBundles * nPricePerBundle;

                if (pItem.nNumber < nQuantityRequested)
                {
                    return; // f*****g retard
                }
            }

            InventoryManipulator.RemoveFrom(Parent, nTI, nPOS, (short)nQuantityRequested);
            Inventory.Add(new TempItem(pItem, nPrice, nPricePerBundle, nBundles));

            Refresh(Parent);

            Parent.SendMessage($"Bundles: {nBundles}, PricePerBundle: {nPricePerBundle}, Price: {nPrice}");

            // TODO packet editing checks
        }
Example #5
0
        private static void BuyItem(Character pChar, short nPos, int nItemId, short nCount)
        {
            var cShop = pChar.Socket.ActiveShop;

            // price is 0 for invis items
            if (!cShop.ContainsItem(nItemId) ||
                cShop.GetItemPrice(nItemId) <= 0 ||
                cShop.GetItemLevelLimited(nItemId) > pChar.Stats.nLevel)
            {
                pChar.SendMessage("Trying to buy an item that doesn't exist in the shop.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuyUnknown));
                return;
            }

            nCount = ItemConstants.is_treat_singly(nItemId) ? (short)1 : nCount;

            var nPricePerCount = cShop.GetItemPrice(nItemId);
            var nFinalPrice    = nPricePerCount * nCount;

            if (nFinalPrice > pChar.Stats.nMoney)
            {
                pChar.SendMessage("Trying to buy an item without enough money.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuyNoMoney));
                return;
            }

            var nInvType = ItemConstants.GetInventoryType(nItemId);

            if (InventoryManipulator.CountFreeSlots(pChar, nInvType) < 1)
            {
                pChar.SendMessage("Please make some space in your inventory.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuyUnknown));
                return;
            }

            var pItem = MasterManager.CreateItem(nItemId, false);

            var slotmax = pItem.SlotMax;

            if (pChar.Skills.Get(false,
                                 (int)Skills.NIGHTWALKER_JAVELIN_MASTERY,
                                 (int)Skills.ASSASSIN_JAVELIN_MASTERY) is SkillEntry se)
            {
                slotmax += (short)se.Y_Effect;
            }

            if (slotmax < nCount * cShop.GetItemQuantity(nItemId))
            {
                pChar.SendMessage("Unable to purchase more than one slot of items at a time.");
                pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuyUnknown));
                return;
            }

            pChar.SendPacket(CPacket.CShopDlg.ShopResult(ShopRes.BuySuccess));

            pItem.nNumber = (short)(pItem.IsRechargeable ? slotmax : nCount * cShop.GetItemQuantity(nItemId));

            pChar.SendMessage("final price: " + nFinalPrice);

            InventoryManipulator.InsertInto(pChar, pItem);
            pChar.Modify.GainMeso(-nFinalPrice, false);
        }