Esempio n. 1
0
 private void PutOnSellingItems(Object source, ElapsedEventArgs e)
 {
     if (Monitor.TryEnter(putOnSaleLocker))
     {
         try
         {
             SQLHelper sqlHelper = SQLHelper.getInstance();
             GenericInventory myInventory = new GenericInventory(SteamWeb);
             List<long> contexts = new List<long>();
             List<ItemOnCsgotm> itemsOnCsgotm = CsgotmAPI.GetTrades();
             contexts.Add(2);
             myInventory.load(730, contexts, Bot.SteamUser.SteamID);
             //TODO test what's faster this
             List<ItemOnCsgotm> itemsSelling = ItemsByStatus(itemsOnCsgotm, ItemOnCsgotmStatus.Selling);
             List<ItemOnCsgotm> itemsToSend = ItemsByStatus(itemsOnCsgotm, ItemOnCsgotmStatus.SendToCsgotmbot);
             List<ItemOnCsgotm> sellingAndSendingItems = itemsSelling.Concat(itemsToSend).ToList();
             /*
     items in my inventory that we're able to sell on csgo.tm
         */
             /*items in bot's inventory
     for which we have a record in sql. If in inventory we find class_instance, for which we don't have a record
     in sql - we skip this item.
     */
             //TODO I think I can create on request to SQL to retreive all items from it.
             foreach (var description in myInventory.descriptions)
             {
                 if (description.Value.tradable)
                 {
                     ItemInSQL itemInSql = sqlHelper.Select(description.Key); 
                     if (itemInSql != null)
                     {
                         var itemsInInventory =
                             myInventory.items.Where(item => item.Value.descriptionid == description.Key);
                         var csgotmItems =
                             sellingAndSendingItems.Where(
                                 item => (item.ClassId + "_" + item.InstanceId) == description.Key);
                         if (!csgotmItems.Any())
                         {
                             //probably we've got a weapon with instance_id !=0, so trying to find items only by class
                             csgotmItems = sellingAndSendingItems.Where(
                                 item => (item.ClassId  == description.Value.classid));
                         }
                         if (itemsInInventory.Count() > csgotmItems.Count())
                         {
                             int numberOfItemsToSell = itemsInInventory.Count() - csgotmItems.Count();
                             for (int i = 0; i < numberOfItemsToSell; i++)
                             {
                                 CsgotmAPI.SellItem(itemInSql);
                             }
                         }
                         if (itemsInInventory.Count() < csgotmItems.Count())
                         {
                             int numberOfItemsToDelete = csgotmItems.Count() - itemsInInventory.Count();
                             var numerator = csgotmItems.GetEnumerator();
                             for (int i = 0; i < numberOfItemsToDelete; i++)
                             {
                                 numerator.MoveNext();
                                 CsgotmAPI.StopSellingItem(numerator.Current);
                             }
                         }
                         //Update price for items
                         foreach (var item in csgotmItems)
                         {
                             CsgotmAPI.RenewPriceOnSellingItem(item);
                         }
                     }
                 }
             }
         }
         finally
         {
             Monitor.Exit(putOnSaleLocker);
         }
     }
 }
        public override void OnMessage(string message, EChatEntryType type)
        {
            //var inventory = OtherInventory;
            //var jsonIventory = JsonConvert.SerializeObject(inventory);
            //var inventory2 = JsonConvert.DeserializeObject<TF2Inventory>(jsonIventory);
            //Log.Info(jsonIventory);
            //Console.WriteLine("test");
            //SendChatMessage(Bot.ChatResponse);
            /**                         **/
            //var rand = new Random();
            //Bot.GetInventory();
            //var inventory = Bot.MyInventory.Items;
            //var randomItem = inventory[rand.Next(inventory.Length)];
            //var tradeOffer = Bot.NewTradeOffer(OtherSID);
            //tradeOffer.Items.AddMyItem(randomItem.AppId, randomItem.ContextId, (long) randomItem.Id);

            //string tradeId;
            //tradeOffer.Send(out tradeId);

            var rand = new Random();

            List<long> contextId = new List<long>();
            //contextId.Add(6);
            contextId.Add(2);

            var genericInv = new GenericInventory(Bot.SteamWeb);
            genericInv.load(730, contextId, OtherSID);

            var inventory = genericInv.items;
            foreach (var item in genericInv.items)
            {
                Log.Info(genericInv.getDescription(item.Key).name);

            }

            //var randomItem = inventory[rand.Next(inventory.Length)];
            //var tradeOffer = Bot.NewTradeOffer(OtherSID);
            //tradeOffer.Items.AddMyItem(randomItem.AppId, randomItem.ContextId, (long)randomItem.Id);

            //string tradeId;
            //tradeOffer.Send(out tradeId);
        }