Esempio n. 1
0
        public static void TryBuy(List <int> aucIds, Character chr)
        {
            if (aucIds.Count == 0)
            {
                return;
            }
            List <Asda2ItemRecord> asda2ItemRecordList = new List <Asda2ItemRecord>();
            uint amount1   = 0;
            bool?nullable1 = new bool?();

            foreach (int aucId in aucIds)
            {
                if (!Asda2AuctionMgr.AllAuctionItems.ContainsKey(aucId))
                {
                    chr.SendAuctionMsg("Can't found item you want to buy, may be some one already buy it.");
                    return;
                }

                Asda2ItemRecord allAuctionItem = Asda2AuctionMgr.AllAuctionItems[aucId];
                if (!nullable1.HasValue)
                {
                    nullable1 = new bool?(allAuctionItem.Template.IsShopInventoryItem);
                }
                bool?nullable2         = nullable1;
                bool shopInventoryItem = allAuctionItem.Template.IsShopInventoryItem;
                if ((nullable2.GetValueOrDefault() != shopInventoryItem ? 1 : (!nullable2.HasValue ? 1 : 0)) != 0)
                {
                    chr.YouAreFuckingCheater("Trying to buy shop\not shop item in one auction buy request.", 1);
                    chr.SendAuctionMsg("Buying from auction failed cause founded shop\not shop items in one request.");
                }

                asda2ItemRecordList.Add(allAuctionItem);
                amount1 += (uint)allAuctionItem.AuctionPrice;
            }

            if (chr.Money <= amount1)
            {
                chr.SendAuctionMsg("Failed to buy items. Not enoght money.");
            }
            else
            {
                if (nullable1.HasValue && nullable1.Value)
                {
                    if (chr.Asda2Inventory.FreeShopSlotsCount < asda2ItemRecordList.Count)
                    {
                        chr.SendAuctionMsg("Failed to buy items. Not enoght invntory space.");
                        return;
                    }
                }
                else if (chr.Asda2Inventory.FreeRegularSlotsCount < asda2ItemRecordList.Count)
                {
                    chr.SendAuctionMsg("Failed to buy items. Not enoght invntory space.");
                    return;
                }

                chr.SubtractMoney(amount1);
                List <Asda2ItemTradeRef> items = new List <Asda2ItemTradeRef>();
                foreach (Asda2ItemRecord record in asda2ItemRecordList)
                {
                    Asda2AuctionMgr.SendMoneyToSeller(record);
                    Asda2AuctionMgr.UnRegisterItem(record);
                    int       amount2         = record.Amount;
                    int       auctionId       = record.AuctionId;
                    Asda2Item asda2Item       = (Asda2Item)null;
                    Asda2Item itemToCopyStats = Asda2Item.CreateItem(record, (Character)null);
                    int       num             = (int)chr.Asda2Inventory.TryAdd(record.ItemId, record.Amount, true, ref asda2Item,
                                                                               new Asda2InventoryType?(), itemToCopyStats);
                    items.Add(new Asda2ItemTradeRef()
                    {
                        Amount = amount2,
                        Item   = asda2Item,
                        Price  = auctionId
                    });
                    record.DeleteLater();
                }

                Asda2AuctionHandler.SendItemsBuyedFromAukResponse(chr.Client, items);
                chr.SendMoneyUpdate();
            }
        }
Esempio n. 2
0
        public static void TryBuy(List <int> aucIds, Character chr)
        {
            if (aucIds.Count == 0)
            {
                return;
            }
            var  itemsToBuy  = new List <Asda2ItemRecord>();
            var  totalPrice  = 0u;
            bool?isShopItems = null;

            foreach (var aucId in aucIds)
            {
                if (!AllAuctionItems.ContainsKey(aucId))
                {
                    chr.SendAuctionMsg("Can't found item you want to buy, may be some one already buy it.");
                    return;
                }
                var item = AllAuctionItems[aucId];
                if (isShopItems == null)
                {
                    isShopItems = item.Template.IsShopInventoryItem;
                }
                if (isShopItems != item.Template.IsShopInventoryItem)
                {
                    chr.YouAreFuckingCheater("Trying to buy shop\not shop item in one auction buy request.");
                    chr.SendAuctionMsg("Buying from auction failed cause founded shop\not shop items in one request.");
                }
                itemsToBuy.Add(item);
                totalPrice += (uint)item.AuctionPrice;
            }
            if (chr.Money <= totalPrice)
            {
                chr.SendAuctionMsg("Failed to buy items. Not enoght money.");
                return;
            }
            if (isShopItems != null && isShopItems.Value)
            {
                if (chr.Asda2Inventory.FreeShopSlotsCount < itemsToBuy.Count)
                {
                    chr.SendAuctionMsg("Failed to buy items. Not enoght invntory space.");
                    return;
                }
            }
            else
            {
                if (chr.Asda2Inventory.FreeRegularSlotsCount < itemsToBuy.Count)
                {
                    chr.SendAuctionMsg("Failed to buy items. Not enoght invntory space.");
                    return;
                }
            }
            chr.SubtractMoney(totalPrice);
            var r = new List <Asda2ItemTradeRef>();

            foreach (var itemRec in itemsToBuy)
            {
                SendMoneyToSeller(itemRec);
                UnRegisterItem(itemRec);
                var       amount    = itemRec.Amount;
                var       auctionId = itemRec.AuctionId;
                Asda2Item addedItem = null;
                var       item      = Asda2Item.CreateItem(itemRec, (Character)null);
                chr.Asda2Inventory.TryAdd(itemRec.ItemId, itemRec.Amount, true, ref addedItem, null, item);
                r.Add(new Asda2ItemTradeRef {
                    Amount = amount, Item = addedItem, Price = auctionId
                });
                itemRec.DeleteLater();
            }
            Asda2AuctionHandler.SendItemsBuyedFromAukResponse(chr.Client, r);
            chr.SendMoneyUpdate();
        }