Beispiel #1
0
        public static void TryRemoveItems(Character activeCharacter, List <int> itemIds)
        {
            uint entityLowId = activeCharacter.Record.EntityLowId;

            if (!Asda2AuctionMgr.ItemsByOwner.ContainsKey(entityLowId))
            {
                activeCharacter.SendAuctionMsg("Failed to remove items from auction. Items not founded.");
            }
            else
            {
                bool?nullable1 = new bool?();
                List <Asda2ItemRecord> asda2ItemRecordList = new List <Asda2ItemRecord>();
                foreach (int itemId in itemIds)
                {
                    if (!Asda2AuctionMgr.ItemsByOwner[entityLowId].ContainsKey(itemId))
                    {
                        asda2ItemRecordList.Clear();
                        activeCharacter.SendAuctionMsg("Failed to remove items from auction. Item not founded.");
                        return;
                    }

                    Asda2ItemRecord asda2ItemRecord = Asda2AuctionMgr.ItemsByOwner[entityLowId][itemId];
                    if (!nullable1.HasValue)
                    {
                        nullable1 = new bool?(asda2ItemRecord.Template.IsShopInventoryItem);
                    }
                    bool?nullable2         = nullable1;
                    bool shopInventoryItem = asda2ItemRecord.Template.IsShopInventoryItem;
                    if ((nullable2.GetValueOrDefault() != shopInventoryItem ? 1 : (!nullable2.HasValue ? 1 : 0)) != 0)
                    {
                        activeCharacter.YouAreFuckingCheater(
                            "Trying to remove shop\not shop item in one auction buy request.", 1);
                        activeCharacter.SendAuctionMsg(
                            "Removing from auction failed cause founded shop\not shop items in one request.");
                    }

                    asda2ItemRecordList.Add(asda2ItemRecord);
                }

                if (nullable1.Value)
                {
                    if (activeCharacter.Asda2Inventory.FreeShopSlotsCount < asda2ItemRecordList.Count)
                    {
                        activeCharacter.SendAuctionMsg("Failed to delete items. Not enoght invntory space.");
                        return;
                    }
                }
                else if (activeCharacter.Asda2Inventory.FreeRegularSlotsCount < asda2ItemRecordList.Count)
                {
                    activeCharacter.SendAuctionMsg("Failed to delete items. Not enoght invntory space.");
                    return;
                }

                List <Asda2ItemTradeRef> asda2Items = new List <Asda2ItemTradeRef>();
                foreach (Asda2ItemRecord record in asda2ItemRecordList)
                {
                    Asda2AuctionMgr.UnRegisterItem(record);
                    int       amount          = record.Amount;
                    int       auctionId       = record.AuctionId;
                    Asda2Item asda2Item       = (Asda2Item)null;
                    Asda2Item itemToCopyStats = Asda2Item.CreateItem(record, (Character)null);
                    int       num             = (int)activeCharacter.Asda2Inventory.TryAdd(record.ItemId, record.Amount, true,
                                                                                           ref asda2Item, new Asda2InventoryType?(), itemToCopyStats);
                    record.DeleteLater();
                    asda2Items.Add(new Asda2ItemTradeRef()
                    {
                        Amount = amount,
                        Item   = asda2Item,
                        Price  = auctionId
                    });
                    Log.Create(Log.Types.ItemOperations, LogSourceType.Character, activeCharacter.EntryId)
                    .AddAttribute("source", 0.0, "removed_from_auction").AddItemAttributes(asda2Item, "").Write();
                }

                Asda2AuctionHandler.SendItemFromAukRemovedResponse(activeCharacter.Client, asda2Items);
            }
        }
Beispiel #2
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();
            }
        }