GetOtherInventory() public method

Gets the other's inventory and stores it in OtherInventory.
public GetOtherInventory ( ) : void
return void
Exemplo n.º 1
0
        public bool? TradeOfferMatches(UserHandler handler, TradeOffer offer)
        {
            handler.GetOtherInventory();
            handler.Bot.GetInventory();

            if (handler.OtherInventory == null)
            {
                handler.Log.Error("Inventory retrieval failed. Ignoring trade.");
                return null;
            }

            if (IsBuyOrder)
            {
                TF2Value paying = TF2Value.Zero;
                foreach (var asset in offer.Items.GetMyItems())
                {
                    Inventory.Item item = handler.Bot.MyInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                        paying += TF2Value.Scrap;
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                        paying += TF2Value.Reclaimed;
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                        paying += TF2Value.Refined;
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                        paying += TF2Value.Key;
                    else
                        return false; // I only pay in pure if it's a buy order.
                }
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.Trade.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                        paying -= TF2Value.Scrap;
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                        paying -= TF2Value.Reclaimed;
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                        paying -= TF2Value.Refined;
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                        paying -= TF2Value.Key;
                }

                if (paying > Price)
                {
                    return false;
                }

                bool hasWantedStuff = false;
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (!MatchesItem(item))
                    {
                        continue;
                    }

                    hasWantedStuff = true;
                    break;
                }

                return hasWantedStuff;
            }
            else
            {
                TF2Value paid = TF2Value.Zero;
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                        paid += TF2Value.Scrap;
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                        paid += TF2Value.Reclaimed;
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                        paid += TF2Value.Refined;
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                        paid += TF2Value.Key;
                }
                foreach (var asset in offer.Items.GetMyItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                        paid -= TF2Value.Scrap;
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                        paid -= TF2Value.Reclaimed;
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                        paid -= TF2Value.Refined;
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                        paid -= TF2Value.Key;
                }

                if (paid < Price)
                {
                    return false;
                }

                var myAssets = offer.Items.GetMyItems();
                if (myAssets.Count == 1)
                {
                    var asset = myAssets.First();
                    Inventory.Item item = handler.Bot.MyInventory.GetItem((ulong)asset.AssetId);

                    return MatchesItem(item);
                }
                return false;
            }
        }
Exemplo n.º 2
0
        public bool?TradeOfferMatches(UserHandler handler, TradeOffer offer)
        {
            handler.GetOtherInventory();
            handler.Bot.GetInventory();

            if (handler.OtherInventory == null)
            {
                handler.Log.Error("Inventory retrieval failed. Ignoring trade.");
                return(null);
            }

            if (IsBuyOrder)
            {
                TF2Value paying = TF2Value.Zero;
                foreach (var asset in offer.Items.GetMyItems())
                {
                    Inventory.Item item = handler.Bot.MyInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        paying += TF2Value.Scrap;
                    }
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        paying += TF2Value.Reclaimed;
                    }
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        paying += TF2Value.Refined;
                    }
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        paying += TF2Value.Key;
                    }
                    else
                    {
                        return(false);                        // I only pay in pure if it's a buy order.
                    }
                }
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.Trade.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        paying -= TF2Value.Scrap;
                    }
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        paying -= TF2Value.Reclaimed;
                    }
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        paying -= TF2Value.Refined;
                    }
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        paying -= TF2Value.Key;
                    }
                }

                if (paying > Price)
                {
                    return(false);
                }

                bool hasWantedStuff = false;
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (!MatchesItem(item))
                    {
                        continue;
                    }

                    hasWantedStuff = true;
                    break;
                }

                return(hasWantedStuff);
            }
            else
            {
                TF2Value paid = TF2Value.Zero;
                foreach (var asset in offer.Items.GetTheirItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        paid += TF2Value.Scrap;
                    }
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        paid += TF2Value.Reclaimed;
                    }
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        paid += TF2Value.Refined;
                    }
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        paid += TF2Value.Key;
                    }
                }
                foreach (var asset in offer.Items.GetMyItems())
                {
                    Inventory.Item item = handler.OtherInventory.GetItem((ulong)asset.AssetId);

                    if (item == null)
                    {
                        //handler.Log.Error("No item matching asset ID " + asset.AssetId.ToString());
                        continue;
                    }

                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        paid -= TF2Value.Scrap;
                    }
                    else if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        paid -= TF2Value.Reclaimed;
                    }
                    else if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        paid -= TF2Value.Refined;
                    }
                    else if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        paid -= TF2Value.Key;
                    }
                }

                if (paid < Price)
                {
                    return(false);
                }

                var myAssets = offer.Items.GetMyItems();
                if (myAssets.Count == 1)
                {
                    var            asset = myAssets.First();
                    Inventory.Item item  = handler.Bot.MyInventory.GetItem((ulong)asset.AssetId);

                    return(MatchesItem(item));
                }
                return(false);
            }
        }