public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
 {
     if (ActiveOrder != null && ActiveOrder.MatchesItem(inventoryItem))
     {
         ActiveOrder = null;
         Trade.RemoveAllItems();
     }
     else
     {
         if (schemaItem.Defindex == TF2Value.SCRAP_DEFINDEX)
         {
             AmountAdded -= TF2Value.Scrap;
         }
         else if (schemaItem.Defindex == TF2Value.RECLAIMED_DEFINDEX)
         {
             AmountAdded -= TF2Value.Reclaimed;
         }
         else if (schemaItem.Defindex == TF2Value.REFINED_DEFINDEX)
         {
             AmountAdded -= TF2Value.Refined;
         }
         else if (schemaItem.Defindex == TF2Value.KEY_DEFINDEX)
         {
             AmountAdded -= TF2Value.Key;
         }
     }
 }
Beispiel #2
0
        public bool RunCommand(List <string> args, UserHandler handler, Action <string> sendChatMessage)
        {
            TF2Value total = TF2Value.Zero;

            try
            {
                handler.Bot.GetInventory();
                Inventory inv = handler.Bot.MyInventory;

                List <Inventory.Item> keys  = inv.GetItemsByDefindex(TF2Value.KEY_DEFINDEX);
                List <Inventory.Item> refi  = inv.GetItemsByDefindex(TF2Value.REFINED_DEFINDEX);
                List <Inventory.Item> rec   = inv.GetItemsByDefindex(TF2Value.RECLAIMED_DEFINDEX);
                List <Inventory.Item> scrap = inv.GetItemsByDefindex(TF2Value.SCRAP_DEFINDEX);

                total += TF2Value.Key * keys.Count;
                total += TF2Value.Refined * refi.Count;
                total += TF2Value.Reclaimed * rec.Count;
                total += TF2Value.Scrap * scrap.Count;
            }
            catch (Exception e)
            {
                handler.Log.Error("An error occurred during the {0} command: {1}", CommandName, e.Message);
                return(false);
            }

            sendChatMessage(string.Format("I currently have {0} in pure.", total.ToRefString()));
            return(true);
        }
Beispiel #3
0
        public TF2Value ReadRefs()
        {
            XDocument doc = XDocument.Load(fileName);
            XElement  name1, name2, name3;

            ReturnNextXElement(1, out name1);
            ReturnNextXElement(2, out name2);
            ReturnNextXElement(3, out name3);
            var    refelement1 = name1.Element("refs");
            var    refelement2 = name2.Element("refs");
            var    refelement3 = name3.Element("refs");
            string refs = "refs";
            string a, b, c = String.Empty;

            Indexer(refelement1, refs, out a);
            Indexer(refelement2, refs, out b);
            Indexer(refelement3, refs, out c);
            double x, y, z, d;

            x = Convert.ToDouble(a);
            y = Convert.ToDouble(b);
            z = Convert.ToDouble(c);
            d = (x + y + z);
            return(TF2Value.FromRef(d));
        }
Beispiel #4
0
        public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
        {
            var item = Trade.CurrentSchema.GetItem(schemaItem.Defindex);

            Log.Success("User removed: " + schemaItem.ItemName);
            if ((item.CraftClass == "weapon" || item.CraftMaterialType == "weapon") && !inventoryItem.IsNotCraftable)
            {
                userWepAdded--;
                UnverifiedAmount -= TF2Value.Scrap * 0.5;
            }
            else if (item.Defindex == 5000)
            {
                UnverifiedAmount -= TF2Value.Scrap;
            }
            else if (item.Defindex == 5001)
            {
                UnverifiedAmount -= TF2Value.Reclaimed;
            }
            else if (item.Defindex == 5002)
            {
                UnverifiedAmount -= TF2Value.Refined;
            }
            else
            {
                invalidItem--;
            }
            SendTradeMessage("I now owe you: {0} ref, {1} rec, and {2} scrap", UnverifiedAmount.RefinedPart, UnverifiedAmount.ReclaimedPart, UnverifiedAmount.ScrapPart);
        }
Beispiel #5
0
 public void DifferenceTest()
 {
     Assert.AreEqual(TF2Value.Zero, TF2Value.Difference(TF2Value.Refined, TF2Value.Refined));
     Assert.AreEqual(TF2Value.Scrap, TF2Value.Difference(TF2Value.Scrap * 8, TF2Value.Scrap * 9));
     Assert.AreEqual(TF2Value.Scrap, TF2Value.Difference(TF2Value.Scrap * 9, TF2Value.Scrap * 8));
     Assert.AreEqual(TF2Value.Refined, TF2Value.Difference(TF2Value.Scrap, TF2Value.Scrap + TF2Value.Refined));
 }
Beispiel #6
0
        public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
        {
            var item = Trade.CurrentSchema.GetItem(schemaItem.Defindex);

            Log.Success("User added: " + schemaItem.ItemName);
            if (invalidItem >= 4)
            {
                Trade.CancelTrade();
                Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Stop messing around. This bot is used for scrapbanking, and will only accept craftable weapons.");
            }
            else if ((item.CraftClass == "weapon" || item.CraftMaterialType == "weapon") && !inventoryItem.IsNotCraftable)
            {
                userWepAdded++;
                UnverifiedAmount += TF2Value.Scrap * 0.5;
            }
            else if (item.Defindex == 5000)
            {
                UnverifiedAmount += TF2Value.Scrap;
            }
            else if (item.Defindex == 5001)
            {
                UnverifiedAmount += TF2Value.Reclaimed;
            }
            else if (item.Defindex == 5002)
            {
                UnverifiedAmount += TF2Value.Refined;
            }
            else
            {
                Trade.SendMessage(schemaItem.ItemName + " is not a valid item! Please remove it from the trade.");
                invalidItem++;
            }
            SendTradeMessage("I now owe you: {0} ref, {1} rec, and {2} scrap", UnverifiedAmount.RefinedPart, UnverifiedAmount.ReclaimedPart, UnverifiedAmount.ScrapPart);
        }
Beispiel #7
0
        public void GetItemPartWorksWhenPassingSelfTest()
        {
            TF2Value keyPrice = 10 * TF2Value.Refined;
            TF2Value value    = 25 * TF2Value.Refined;

            Assert.AreEqual(2, value.GetPriceUsingItem(keyPrice, out value));
            Assert.AreEqual(5 * TF2Value.Refined, value);
        }
Beispiel #8
0
        public void GetItemPartNoRemainderTest()
        {
            TF2Value keyPrice = 10 * TF2Value.Refined;
            TF2Value remainder;

            Assert.AreEqual(2, (20 * TF2Value.Refined).GetPriceUsingItem(keyPrice, out remainder));
            Assert.AreEqual(TF2Value.Zero, remainder);
        }
Beispiel #9
0
        public void GetItemPartNoKeysTest()
        {
            TF2Value keyPrice = 10 * TF2Value.Refined;
            TF2Value remainder;

            Assert.AreEqual(0, (9 * TF2Value.Refined).GetPriceUsingItem(keyPrice, out remainder));
            Assert.AreEqual(9 * TF2Value.Refined, remainder);
        }
Beispiel #10
0
        public void MetalTotalGetterTest2()
        {
            TF2Value value = TF2Value.Scrap; //0.11 ref

            Assert.AreEqual(1.0 / 9, value.RefinedTotal, 0.01);
            Assert.AreEqual(1.0 / 3, value.ReclaimedTotal, 0.01);
            Assert.AreEqual(1, value.ScrapTotal);
        }
Beispiel #11
0
        public void MetalTotalGetterTest()
        {
            TF2Value value = TF2Value.Refined + TF2Value.Reclaimed * 2; //1.66 ref

            Assert.AreEqual(5.0 / 3, value.RefinedTotal, 0.01);
            Assert.AreEqual(5, value.ReclaimedTotal);
            Assert.AreEqual(15, value.ScrapTotal);
        }
Beispiel #12
0
        private void TestGetters(int refined, int reclaimed, int scrap, int grains)
        {
            TF2Value value = refined * TF2Value.Refined + reclaimed * TF2Value.Reclaimed + scrap * TF2Value.Scrap + grains * TF2Value.Grain;

            Assert.AreEqual(refined, value.RefinedPart);
            Assert.AreEqual(reclaimed, value.ReclaimedPart);
            Assert.AreEqual(scrap, value.ScrapPart);
            Assert.AreEqual(grains, value.GrainPart);
        }
Beispiel #13
0
        public void GetItemWorthStringHalfScrapTest()
        {
            TF2Value weaponValue = TF2Value.Scrap / 2;

            Assert.AreEqual("1 weapon", weaponValue.ToItemString(weaponValue, "weapon"));
            Assert.AreEqual("2 weapons", (weaponValue * 2).ToItemString(weaponValue, "weapon"));
            Assert.AreEqual("4 weapons", (weaponValue * 2 + TF2Value.Scrap).ToItemString(weaponValue, "weapon"));
            Assert.AreEqual("0 weapons", TF2Value.Zero.ToItemString(weaponValue, "weapon"));
        }
Beispiel #14
0
        public void GetItemWorthStringOneScrapTest()
        {
            TF2Value emoteWorth = TF2Value.Scrap;

            Assert.AreEqual("1 emote", emoteWorth.ToItemString(emoteWorth, "emote"));
            Assert.AreEqual("2 emotes", (emoteWorth * 2).ToItemString(emoteWorth, "emote"));
            Assert.AreEqual("3 emotes", (emoteWorth * 2 + TF2Value.Scrap).ToItemString(emoteWorth, "emote"));
            Assert.AreEqual("0 emotes", TF2Value.Zero.ToItemString(emoteWorth, "emote"));
        }
 private void TestKeyOutputWithValue(TF2Value keyValue)
 {
     Assert.AreEqual("1 key", keyValue.ToItemString(keyValue, "key"));
     Assert.AreEqual("2 keys", (keyValue * 2).ToItemString(keyValue, "key"));
     Assert.AreEqual("2 keys + 0.11 ref", (keyValue * 2 + TF2Value.Scrap).ToItemString(keyValue, "key"));
     Assert.AreEqual("2 keys + 1 ref", (keyValue * 2 + TF2Value.Refined).ToItemString(keyValue, "key"));
     Assert.AreEqual("2 keys + 1.11 ref", (keyValue * 2 + TF2Value.Refined + TF2Value.Scrap).ToItemString(keyValue, "key"));
     Assert.AreEqual("0 keys", TF2Value.Zero.ToItemString(keyValue, "key"));
     Assert.AreEqual("1 ref", TF2Value.Refined.ToItemString(keyValue, "key"));
 }
Beispiel #16
0
 private void TestKeyOutputWithValue(TF2Value keyValue)
 {
     Assert.AreEqual("1 key", keyValue.ToItemString(keyValue, "key"));
     Assert.AreEqual("2 keys", (keyValue * 2).ToItemString(keyValue, "key"));
     Assert.AreEqual("2 keys + 0.11 ref", (keyValue * 2 + TF2Value.Scrap).ToItemString(keyValue, "key"));
     Assert.AreEqual("2 keys + 1 ref", (keyValue * 2 + TF2Value.Refined).ToItemString(keyValue, "key"));
     Assert.AreEqual("2 keys + 1.11 ref", (keyValue * 2 + TF2Value.Refined + TF2Value.Scrap).ToItemString(keyValue, "key"));
     Assert.AreEqual("0 keys", TF2Value.Zero.ToItemString(keyValue, "key"));
     Assert.AreEqual("1 ref", TF2Value.Refined.ToItemString(keyValue, "key"));
 }
Beispiel #17
0
        public void GetItemWorthStringFewScrapTest()
        {
            TF2Value cardWorth = TF2Value.Scrap * 4;

            Assert.AreEqual("1 card", cardWorth.ToItemString(cardWorth, "card"));
            Assert.AreEqual("2 cards", (cardWorth * 2).ToItemString(cardWorth, "card"));
            Assert.AreEqual("2 cards + 0.11 ref", (cardWorth * 2 + TF2Value.Scrap).ToItemString(cardWorth, "card"));
            Assert.AreEqual("0 cards", TF2Value.Zero.ToItemString(cardWorth, "card"));
            Assert.AreEqual("0.11 ref", TF2Value.Scrap.ToItemString(cardWorth, "card"));
        }
Beispiel #18
0
 public void MinTest()
 {
     Assert.AreEqual(TF2Value.Refined, TF2Value.Min(TF2Value.Refined, TF2Value.Refined));
     Assert.AreEqual(TF2Value.Scrap, TF2Value.Min(TF2Value.Refined, TF2Value.Scrap));
     Assert.AreEqual(TF2Value.Scrap, TF2Value.Min(TF2Value.Scrap, TF2Value.Refined));
     Assert.AreEqual(TF2Value.Zero, TF2Value.Min(TF2Value.Scrap, TF2Value.Zero));
     Assert.AreEqual(TF2Value.Zero, TF2Value.Min(TF2Value.Zero, TF2Value.Refined));
     Assert.AreEqual(TF2Value.Grain, TF2Value.Min(TF2Value.Scrap, TF2Value.Grain));
     Assert.AreEqual(TF2Value.Zero, TF2Value.Min(TF2Value.Zero, TF2Value.Grain));
 }
Beispiel #19
0
        public void NegativeValueThrowsTest()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                TF2Value value = TF2Value.Scrap - TF2Value.Reclaimed;
            });

            Assert.Throws <ArgumentException>(() =>
            {
                TF2Value value = TF2Value.Reclaimed - TF2Value.Refined;
            });
        }
Beispiel #20
0
        public void FloorTest()
        {
            Assert.AreEqual(TF2Value.Zero, TF2Value.Floor(TF2Value.Zero));
            Assert.AreEqual(TF2Value.Zero, TF2Value.Floor(TF2Value.Grain));
            Assert.AreEqual(TF2Value.Scrap, TF2Value.Floor(TF2Value.Scrap));
            Assert.AreEqual(TF2Value.Reclaimed, TF2Value.Floor(TF2Value.Reclaimed));
            Assert.AreEqual(TF2Value.Refined, TF2Value.Floor(TF2Value.Refined));

            Assert.AreEqual(TF2Value.Zero, TF2Value.Floor(TF2Value.Scrap / 2));
            Assert.AreEqual(TF2Value.Refined, TF2Value.Floor(TF2Value.Refined + TF2Value.Grain));
            Assert.AreEqual(TF2Value.Refined + TF2Value.Scrap, TF2Value.Floor(TF2Value.Refined + TF2Value.Scrap));
        }
Beispiel #21
0
        public void CeilingTest()
        {
            Assert.AreEqual(TF2Value.Zero, TF2Value.Ceiling(TF2Value.Zero));
            Assert.AreEqual(TF2Value.Scrap, TF2Value.Ceiling(TF2Value.Grain));
            Assert.AreEqual(TF2Value.Scrap, TF2Value.Ceiling(TF2Value.Scrap));
            Assert.AreEqual(TF2Value.Reclaimed, TF2Value.Ceiling(TF2Value.Reclaimed));
            Assert.AreEqual(TF2Value.Refined, TF2Value.Ceiling(TF2Value.Refined));

            Assert.AreEqual(TF2Value.Scrap, TF2Value.Ceiling(TF2Value.Scrap / 2));
            Assert.AreEqual(TF2Value.Refined + TF2Value.Scrap, TF2Value.Ceiling(TF2Value.Refined + TF2Value.Grain));
            Assert.AreEqual(TF2Value.Refined + TF2Value.Scrap, TF2Value.Ceiling(TF2Value.Refined + TF2Value.Scrap));
        }
Beispiel #22
0
 public Order(TF2Value price, Schema.Item item, int quality = 6, int maxStock = 5, bool craftable = true,
              bool allowKS = false, bool allowPaint = false, bool buyOrder = false)
 {
     PriceRef         = price.RefinedTotal;
     Defindex         = item.Defindex;
     Quality          = quality;
     MaxStock         = maxStock;
     Craftable        = craftable;
     AllowKillstreaks = allowKS;
     AllowPaint       = allowPaint;
     IsBuyOrder       = buyOrder;
 }
Beispiel #23
0
        public Order(TF2Value price, Schema.Item item, int quality = 6, int maxStock = 5, bool craftable = true, 
			bool allowKS = false, bool allowPaint = false, bool buyOrder = false)
        {
            PriceRef = price.RefinedTotal;
            Defindex = item.Defindex;
            Quality = quality;
            MaxStock = maxStock;
            Craftable = craftable;
            AllowKillstreaks = allowKS;
            AllowPaint = allowPaint;
            IsBuyOrder = buyOrder;
        }
Beispiel #24
0
        public bool RunCommand(List <string> args, UserHandler handler, Action <string> sendChatMessage)
        {
            try
            {
                handler.Bot.GetInventory();

                TF2Value total = TF2Value.Zero;
                foreach (Inventory.Item item in handler.Bot.MyInventory.Items)
                {
                    if (item.IsNotTradeable)
                    {
                        continue;
                    }

                    if (item.Defindex == TF2Value.KEY_DEFINDEX)
                    {
                        total += TF2Value.Key;
                    }
                    if (item.Defindex == TF2Value.REFINED_DEFINDEX)
                    {
                        total += TF2Value.Refined;
                    }
                    if (item.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    {
                        total += TF2Value.Reclaimed;
                    }
                    if (item.Defindex == TF2Value.SCRAP_DEFINDEX)
                    {
                        total += TF2Value.Scrap;
                    }

                    Order order = handler.Bot.Orders.SellOrders.FirstOrDefault((o) => o.MatchesItem(item));
                    if (order != null)
                    {
                        total += order.Price;
                        continue;
                    }
                }

                sendChatMessage("Net worth: " + total.ToRefString());

                return(true);
            }
            catch (Exception e)
            {
                handler.Log.Error("An error occurred during the {0} command: {1}", CommandName, e.Message);
                return(false);
            }
        }
Beispiel #25
0
        public void RoundTest()
        {
            Assert.AreEqual(TF2Value.Zero, TF2Value.Round(TF2Value.Zero));
            Assert.AreEqual(TF2Value.Zero, TF2Value.Round(TF2Value.Grain));
            Assert.AreEqual(TF2Value.Scrap, TF2Value.Round(TF2Value.Scrap));
            Assert.AreEqual(TF2Value.Reclaimed, TF2Value.Round(TF2Value.Reclaimed));
            Assert.AreEqual(TF2Value.Refined, TF2Value.Round(TF2Value.Refined));

            Assert.AreEqual(TF2Value.Zero, TF2Value.Round(TF2Value.Scrap / 2 - TF2Value.Grain));
            Assert.AreEqual(TF2Value.Scrap, TF2Value.Round(TF2Value.Scrap / 2));
            Assert.AreEqual(TF2Value.Scrap, TF2Value.Round(TF2Value.Scrap / 2 + TF2Value.Grain));

            Assert.AreEqual(TF2Value.Refined, TF2Value.Round(TF2Value.Refined + TF2Value.Scrap / 2 - TF2Value.Grain));
            Assert.AreEqual(TF2Value.Refined + TF2Value.Scrap, TF2Value.Round(TF2Value.Refined + TF2Value.Scrap / 2));
            Assert.AreEqual(TF2Value.Refined + TF2Value.Scrap, TF2Value.Round(TF2Value.Refined + TF2Value.Scrap / 2 + TF2Value.Grain));
        }
Beispiel #26
0
 public void FromRefStringTest()
 {
     Assert.AreEqual(1, TF2Value.FromRef("0.11").ScrapTotal);
     Assert.AreEqual(2, TF2Value.FromRef("0.22").ScrapTotal);
     Assert.AreEqual(3, TF2Value.FromRef("0.33").ScrapTotal);
     Assert.AreEqual(4, TF2Value.FromRef("0.44").ScrapTotal);
     Assert.AreEqual(5, TF2Value.FromRef("0.55").ScrapTotal);
     Assert.AreEqual(6, TF2Value.FromRef("0.66").ScrapTotal);
     Assert.AreEqual(7, TF2Value.FromRef("0.77").ScrapTotal);
     Assert.AreEqual(8, TF2Value.FromRef("0.88").ScrapTotal);
     Assert.AreEqual(9, TF2Value.FromRef("1").ScrapTotal);
     Assert.AreEqual(10, TF2Value.FromRef("1.11").ScrapTotal);
     Assert.AreEqual(11, TF2Value.FromRef("1.22").ScrapTotal);
     Assert.AreEqual(12, TF2Value.FromRef("1.33").ScrapTotal);
     Assert.AreEqual(20, TF2Value.FromRef("2.22").ScrapTotal);
 }
Beispiel #27
0
        public bool Validate()
        {
            AmountAdded = TF2Value.Zero;

            List <string> errors = new List <string> ();

            foreach (TradeUserAssets asset in Trade.OtherOfferedItems)
            {
                var item = Trade.OtherInventory.GetItem(asset.assetid);
                if (item.Defindex == 5000)
                {
                    AmountAdded += TF2Value.Scrap;
                }
                else if (item.Defindex == 5001)
                {
                    AmountAdded += TF2Value.Reclaimed;
                }
                else if (item.Defindex == 5002)
                {
                    AmountAdded += TF2Value.Refined;
                }
                else
                {
                    var schemaItem = Trade.CurrentSchema.GetItem(item.Defindex);
                    errors.Add("Item " + schemaItem.Name + " is not a metal.");
                }
            }

            if (AmountAdded == TF2Value.Zero)
            {
                errors.Add("You must put up at least 1 scrap.");
            }

            // send the errors
            if (errors.Count != 0)
            {
                SendTradeMessage("There were errors in your trade: ");
            }
            foreach (string error in errors)
            {
                SendTradeMessage(error);
            }

            return(errors.Count == 0);
        }
Beispiel #28
0
        public void FromRefTest()
        {
            Assert.AreEqual(1, TF2Value.FromRef(0.11).ScrapTotal);
            Assert.AreEqual(2, TF2Value.FromRef(0.22).ScrapTotal);
            Assert.AreEqual(3, TF2Value.FromRef(0.33).ScrapTotal);
            Assert.AreEqual(4, TF2Value.FromRef(0.44).ScrapTotal);
            Assert.AreEqual(5, TF2Value.FromRef(0.55).ScrapTotal);
            Assert.AreEqual(6, TF2Value.FromRef(0.66).ScrapTotal);
            Assert.AreEqual(7, TF2Value.FromRef(0.77).ScrapTotal);
            Assert.AreEqual(8, TF2Value.FromRef(0.88).ScrapTotal);
            Assert.AreEqual(9, TF2Value.FromRef(1).ScrapTotal);
            Assert.AreEqual(10, TF2Value.FromRef(1.11).ScrapTotal);
            Assert.AreEqual(11, TF2Value.FromRef(1.22).ScrapTotal);
            Assert.AreEqual(12, TF2Value.FromRef(1.33).ScrapTotal);
            Assert.AreEqual(20, TF2Value.FromRef(2.22).ScrapTotal);

            Assert.AreEqual(9000, TF2Value.FromRef(1000).ScrapTotal);
            Assert.AreEqual(9001, TF2Value.FromRef(1000.11).ScrapTotal);
        }
        public void AddPure(TF2Value orderPayment)
        {
            if (ActiveOrder == null)
            {
                Log.Error("Trade with user #{0}: SimpleUserHandler.ActiveOrder == null.", OtherSID.ToString());
                Trade.CancelTrade();
                SendChatMessage("I have encountered an error. Please send the trade again.");

                return;
            }

            SendTradeMessage("Removing items from previous trades...");
            Trade.RemoveAllItems();

            SendTradeMessage("Adding payment for this trade...");
            TF2Value myPayment = TF2Value.Zero;
            TF2Value currentIteration = TF2Value.Key;
            while (myPayment + currentIteration <= orderPayment)
            {
                if (!Trade.AddItemByDefindex(TF2Value.KEY_DEFINDEX))
                {
                    //Log.Warn("[TRADE-BUY] No more keys found. Moving on to refined metal.");
                    break;
                }

                Log.Debug("Added key in trade with user {0}.", OtherSID.ToString());
                myPayment += currentIteration;
            }

            currentIteration = TF2Value.Refined;
            while (myPayment + currentIteration <= orderPayment)
            {
                if (!Trade.AddItemByDefindex(TF2Value.REFINED_DEFINDEX))
                {
                    //Log.Warn("[TRADE-BUY] No more refined metal found. Moving on to reclaimed metal.");
                    break;
                }

                Log.Debug("Added refined metal in trade with user {0}.", OtherSID.ToString());
                myPayment += currentIteration;
            }

            currentIteration = TF2Value.Reclaimed;
            while (myPayment + currentIteration <= orderPayment)
            {
                if (!Trade.AddItemByDefindex(TF2Value.RECLAIMED_DEFINDEX))
                {
                    //Log.Warn("[TRADE-BUY] No more reclaimed metal found. Moving on to scrap metal.");
                    break;
                }

                Log.Debug("Added reclaimed metal in trade with user {0}.", OtherSID.ToString());
                myPayment += currentIteration;
            }

            currentIteration = TF2Value.Scrap;
            while (myPayment + currentIteration <= orderPayment)
            {
                if (!Trade.AddItemByDefindex(TF2Value.SCRAP_DEFINDEX))
                {
                    Log.Warn("[PAYMENT] No more scrap metal found.");
                    break;
                }

                Log.Debug("Added scrap metal in trade with user {0}.", OtherSID.ToString());
                myPayment += currentIteration;
            }

            if (myPayment != orderPayment)
            {
                Log.Error("Could not add correct amount of {0}. Instead added {1}.", ActiveOrder.Price.ToRefString(),
                    myPayment.ToRefString());
                Trade.CancelTrade();
                SendChatMessage("I have encountered an error. Please send the trade again.");
            }

            SendTradeMessage("Finished paying {0}.", myPayment.ToRefString());
        }
Beispiel #30
0
        private bool _ordersAdd(List <string> args, UserHandler handler, Action <string> sendChatMessage)
        {
            if (args.Count < 4)
            {
                sendChatMessage("Syntax: orders add {sell | buy} {defindex} {quality} {price}");
                return(false);
            }
            bool sell = args[0].ToLower() == "sell";

            string strDefindex = args[1];
            int    defindex;

            if (!int.TryParse(strDefindex, out defindex))
            {
                sendChatMessage("Invalid defindex: " + strDefindex);
                return(false);
            }
            Schema.Item item = Trade.CurrentSchema.GetItem(defindex);

            string strQuality = args[2];
            int    quality;

            if (!int.TryParse(strQuality, out quality))
            {
                sendChatMessage("Invalid quality id: " + strQuality);
                return(false);
            }

            string strPrice = args[3];
            double priceRef;

            if (!double.TryParse(strPrice, out priceRef))
            {
                sendChatMessage("Invalid price value: " + strPrice);
                return(false);
            }
            TF2Value price = TF2Value.FromRef(priceRef);

            if (sell)
            {
                Order so = handler.Bot.Orders.SellOrders.FirstOrDefault((o) => o.Defindex == defindex && o.Quality == quality);
                if (so != null)
                {
                    sendChatMessage("Order already exists selling for " + so.Price.ToRefString());
                    return(false);
                }

                Order added = new Order(price, item, quality, 3, true, false, false, false);
                handler.Bot.Orders.SellOrders.Add(added);
                sendChatMessage("Sell order added: " + added.ToString(Trade.CurrentSchema));
            }
            else
            {
                Order bo = handler.Bot.Orders.BuyOrders.FirstOrDefault((o) => o.Defindex == defindex && o.Quality == quality);
                if (bo != null)
                {
                    sendChatMessage("Order already exists buying for " + bo.Price.ToRefString());
                    return(false);
                }

                Order added = new Order(price, item, quality, 3, true, false, false, true);
                handler.Bot.Orders.BuyOrders.Add(added);
                sendChatMessage("Buy order added: " + added.ToString(Trade.CurrentSchema));
            }

            handler.Bot.Orders.SaveAll();
            return(true);
        }
Beispiel #31
0
 public void ReInit()
 {
     IgnoringBot = 0;
     NumKeys = 0;
     AdditionalRefined = TF2Value.Zero;
     UserMetalAdded = TF2Value.Zero;
     UserKeysAdded = 0;
     BotKeysAdded = 0;
     BotMetalAdded = TF2Value.Zero;
     RefinedAdded = 0;
     ReclaimedAdded = 0;
     ScrapAdded = 0;
     KeysToScrap = TF2Value.Zero;
     ValidateMetaltoKey = 0;
     PreviousKeys = 0;
     ExcessRefined = TF2Value.Zero;
     ChangeAdded = TF2Value.Zero;
     InvalidItem = 0;
     HasErrorRun = false;
     ChooseDonate = false;
     GaveChange = false;
     ChangeValidate = false;
     HasCounted = false;
     InventoryFailed = false;
 }
Beispiel #32
0
 public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
 {
     Schema.Item item = Trade.CurrentSchema.GetItem((int)schemaItem.Defindex);
     if (item.Defindex == 5000)
     {
         UserMetalAdded -= TF2Value.Scrap;
         Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " removed: " + item.ItemName);
     }
     else if (item.Defindex == 5001)
     {
         UserMetalAdded -= TF2Value.Reclaimed;
         Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " removed: " + item.ItemName);
     }
     else if (item.Defindex == 5002)
     {
         UserMetalAdded -= TF2Value.Refined;
         Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " removed: " + item.ItemName);
     }
     else if (item.Defindex == 5021)
     {
         UserKeysAdded--;
         KeysToScrap = UserKeysAdded * BuyPricePerKey;
         Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " removed: " + item.ItemName);
     }
     else
     {
         Bot.Log.Warn(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " removed: " + item.ItemName);
     }
     if ((double)UserKeysAdded < BotMetalAdded.GetPriceUsingItem(BuyPricePerKey))
     {
         bool RefIsDone = false;
         bool RecIsDone = false;
         bool ScrapIsDone = false;
         bool DoneAddingMetal = false;
         int WhileLoop = 0;
         while (!DoneAddingMetal)
         {
             WhileLoop++;
             if (TF2Value.Difference(BotMetalAdded, KeysToScrap) >= TF2Value.Refined && !RefIsDone)
             {
                 if (Trade.RemoveItemByDefindex(5002))
                 {
                     Bot.Log.Warn("I removed Refined Metal.");
                     BotMetalAdded -= TF2Value.Refined;
                     InventoryMetal += TF2Value.Refined;
                     Refined++;
                     RefinedAdded--;
                 }
                 else
                 {
                     RefIsDone = true;
                 }
             }
             else if (TF2Value.Difference(BotMetalAdded, KeysToScrap) < TF2Value.Refined && !RefIsDone)
             {
                 RefIsDone = true;
             }
             else if (TF2Value.Difference(BotMetalAdded, KeysToScrap) >= TF2Value.Reclaimed && RefIsDone && !RecIsDone)
             {
                 if (Trade.RemoveItemByDefindex(5001))
                 {
                     Bot.Log.Warn("I removed Reclaimed Metal.");
                     BotMetalAdded -= TF2Value.Reclaimed;
                     InventoryMetal += TF2Value.Reclaimed;
                     Reclaimed++;
                     ReclaimedAdded--;
                 }
                 else if (Trade.RemoveItemByDefindex(5002))
                 {
                     Bot.Log.Warn("I removed Refined Metal.");
                     BotMetalAdded -= TF2Value.Refined;
                     InventoryMetal += TF2Value.Refined;
                     Refined++;
                     RefinedAdded--;
                     for (int addareclaimed = 0; addareclaimed < 2; addareclaimed++)
                     {
                         if (Trade.AddItemByDefindex(5001))
                         {
                             Bot.Log.Warn("I added Reclaimed Metal.");
                             BotMetalAdded += TF2Value.Reclaimed;
                             InventoryMetal -= TF2Value.Reclaimed;
                             Reclaimed--;
                             ReclaimedAdded++;
                         }
                     }
                 }
             }
             else if (TF2Value.Difference(BotMetalAdded, KeysToScrap) < TF2Value.Reclaimed && !RecIsDone)
             {
                 RecIsDone = true;
             }
             else if (TF2Value.Difference(BotMetalAdded, KeysToScrap) >= TF2Value.Scrap && RefIsDone && RecIsDone && !ScrapIsDone)
             {
                 if (Trade.RemoveItemByDefindex(5000))
                 {
                     Bot.Log.Warn("I removed Scrap Metal.");
                     BotMetalAdded -= TF2Value.Scrap;
                     InventoryMetal += TF2Value.Scrap;
                     Scrap++;
                     ScrapAdded--;
                 }
                 else if (Trade.RemoveItemByDefindex(5001))
                 {
                     Bot.Log.Warn("I removed Reclaimed Metal.");
                     BotMetalAdded -= TF2Value.Reclaimed;
                     InventoryMetal += TF2Value.Reclaimed;
                     Reclaimed++;
                     ReclaimedAdded--;
                     for (int addascrap = 0; addascrap < 2; addascrap++)
                     {
                         if (Trade.AddItemByDefindex(5000))
                         {
                             Bot.Log.Warn("I added Scrap Metal.");
                             BotMetalAdded += TF2Value.Scrap;
                             InventoryMetal -= TF2Value.Scrap;
                             Scrap--;
                             ScrapAdded++;
                         }
                     }
                 }
                 else
                 {
                     ScrapIsDone = true;
                 }
             }
             else if (BotMetalAdded == KeysToScrap)
             {
                 DoneAddingMetal = true;
                 ScrapIsDone = true;
             }
             else if (ScrapIsDone && RecIsDone && RefIsDone)
             {
                 ScrapIsDone = false;
                 RecIsDone = false;
                 RefIsDone = false;
             }
             else if (WhileLoop > 100)
             {
                 SendTradeMessage("Error: I cannot remove metal at the moment. Either Steam is broken or I am broken!");
                 Bot.Log.Error("Error: Bot could not remove metal from a trade.");
                 break;
             }
         }
     }
     while (UserMetalAdded.GetPriceUsingItem(SellPricePerKey) < (double)BotKeysAdded)
     {
         if (Trade.RemoveItemByDefindex(5021))
         {
             Bot.Log.Warn("I removed Mann Co. Supply Crate Key.");
             SendTradeMessage("I removed a key.");
             BotKeysAdded--;
             InventoryKeys++;
             PreviousKeys = BotKeysAdded;
         }
         else
         {
             SendTradeMessage("Error: I cannot remove the key(s) at the moment. Either Steam is broken or I am broken!");
             Bot.Log.Error("Error: Bot could not remove a key from a trade.");
             break;
         }
     }
 }
Beispiel #33
0
 public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
 {
     if (schemaItem != null && inventoryItem != null)
     {
         Schema.Item item = Trade.CurrentSchema.GetItem((int)schemaItem.Defindex);
         if (inventoryItem.AppId != 440)
         {
             SendTradeMessage("That's an item from the wrong game!");
         }
         if (!HasCounted)
         {
             SendTradeMessage("I haven't finished counting my inventory yet.");
             SendTradeMessage("Please remove any items you added, and then re-add them or there could be errors.");
         }
         else if (InvalidItem > 2)
         {
             Trade.CancelTrade();
             SendChatMessage("I am used for buying and selling keys only. I can only accept metal or keys as payment.");
             Bot.Log.Warn("Booted user for adding invalid items.");
             Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
         }
         else if (IgnoringBot > 3)
         {
             Trade.CancelTrade();
             SendChatMessage("It would appear that you haven't checked my inventory. I either do not have enough metal, or do not have enough keys to complete your trade.");
             Bot.Log.Warn("Booted user for ignoring the bot.");
             Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
         }
         else if (ScamAttempt > 2)
         {
             Trade.CancelTrade();
             ScamAttempt = 0;
             SendChatMessage("The trade isn't even. Are you trying to scam me? :(");
             Bot.Log.Warn("Booted user for trying to scam the bot.");
             Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
         }
         else if (item.Defindex == 5000)
         {
             UserMetalAdded += TF2Value.Scrap;
             Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " added: " + item.ItemName);
             WasBuying = true;
         }
         else if (item.Defindex == 5001)
         {
             UserMetalAdded += TF2Value.Reclaimed;
             Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " added: " + item.ItemName);
             WasBuying = true;
         }
         else if (item.Defindex == 5002)
         {
             UserMetalAdded += TF2Value.Refined;
             Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " added: " + item.ItemName);
             WasBuying = true;
         }
         else if (item.Defindex == 5021)
         {
             UserKeysAdded++;
             KeysToScrap = UserKeysAdded * BuyPricePerKey;
             WasBuying = false;
             Bot.Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " added: " + item.ItemName);
             if (!ChooseDonate)
             {
                 if (InventoryMetal < KeysToScrap)
                 {
                     SendTradeMessage("I only have " + InventoryMetal.ToRefString() + ".");
                     SendTradeMessage("I pay " + BuyPricePerKey.ToRefString() + " per key. You need to remove some keys.");
                     Bot.Log.Warn("I don't have enough metal for the user.");
                     IgnoringBot++;
                 }
                 else
                 {
                     SendTradeMessage("You have given me " + UserKeysAdded + " key(s).");
                     SendTradeMessage("I will give you " + KeysToScrap.ToRefString() + ".");
                     bool RefIsDone = false;
                     bool RecIsDone = false;
                     bool ScrapIsDone = false;
                     bool DoneAddingMetal = false;
                     bool RetriedOnce = false;
                     int WhileLoop = 0;
                     while (!DoneAddingMetal)
                     {
                         WhileLoop++;
                         if (TF2Value.Difference(BotMetalAdded, KeysToScrap) >= TF2Value.Refined && !RefIsDone)
                         {
                             if (Trade.AddItemByDefindex(5002))
                             {
                                 Bot.Log.Warn("I added Refined Metal.");
                                 BotMetalAdded += TF2Value.Refined;
                                 InventoryMetal -= TF2Value.Refined;
                                 Refined--;
                                 RefinedAdded++;
                             }
                             else
                             {
                                 RefIsDone = true;
                             }
                         }
                         else if (TF2Value.Difference(BotMetalAdded, KeysToScrap) < TF2Value.Refined && !RefIsDone)
                         {
                             RefIsDone = true;
                         }
                         else if (TF2Value.Difference(BotMetalAdded, KeysToScrap) >= TF2Value.Reclaimed && RefIsDone && !RecIsDone)
                         {
                             if (ReclaimedAdded == 2 && Refined > 0)
                             {
                                 for (int removed = 0; removed < 2; removed++)
                                 {
                                     if (Trade.RemoveItemByDefindex(5001))
                                     {
                                         Bot.Log.Warn("I removed Reclaimed Metal.");
                                         BotMetalAdded -= TF2Value.Reclaimed;
                                         InventoryMetal += TF2Value.Reclaimed;
                                         Reclaimed++;
                                         ReclaimedAdded--;
                                     }
                                 }
                                 if (Trade.AddItemByDefindex(5002))
                                 {
                                     Bot.Log.Warn("I added Refined Metal.");
                                     BotMetalAdded += TF2Value.Refined;
                                     InventoryMetal -= TF2Value.Refined;
                                     Refined--;
                                     RefinedAdded++;
                                 }
                                 else
                                 {
                                     RecIsDone = true;
                                 }
                             }
                             else if (Trade.AddItemByDefindex(5001))
                             {
                                 Bot.Log.Warn("I added Reclaimed Metal.");
                                 BotMetalAdded += TF2Value.Reclaimed;
                                 InventoryMetal -= TF2Value.Reclaimed;
                                 Reclaimed--;
                                 ReclaimedAdded++;
                             }
                             else
                             {
                                 RecIsDone = true;
                             }
                         }
                         else if (TF2Value.Difference(BotMetalAdded, KeysToScrap) < TF2Value.Reclaimed && !RecIsDone)
                         {
                             RecIsDone = true;
                         }
                         else if (TF2Value.Difference(BotMetalAdded, KeysToScrap) >= TF2Value.Scrap && RefIsDone && RecIsDone && !ScrapIsDone)
                         {
                             if (ScrapAdded == 2 && Reclaimed > 0)
                             {
                                 for (int removed2 = 0; removed2 < 2; removed2++)
                                 {
                                     if (Trade.RemoveItemByDefindex(5000))
                                     {
                                         Bot.Log.Warn("I removed Scrap Metal.");
                                         BotMetalAdded -= TF2Value.Scrap;
                                         InventoryMetal += TF2Value.Scrap;
                                         Scrap++;
                                         ScrapAdded--;
                                     }
                                 }
                                 if (Trade.AddItemByDefindex(5001))
                                 {
                                     Bot.Log.Warn("I added Reclaimed Metal.");
                                     BotMetalAdded += TF2Value.Reclaimed;
                                     InventoryMetal -= TF2Value.Reclaimed;
                                     Reclaimed--;
                                     ReclaimedAdded++;
                                 }
                             }
                             else if (Trade.AddItemByDefindex(5000))
                             {
                                 Bot.Log.Warn("I added Scrap Metal.");
                                 BotMetalAdded += TF2Value.Scrap;
                                 InventoryMetal -= TF2Value.Scrap;
                                 Scrap--;
                                 ScrapAdded++;
                             }
                             else
                             {
                                 ScrapIsDone = true;
                             }
                         }
                         else if (BotMetalAdded == KeysToScrap)
                         {
                             SendTradeMessage("Added enough metal (" + BotMetalAdded.ToRefString() + ").");
                             Bot.Log.Success("Gave user enough metal!");
                             DoneAddingMetal = true;
                             ScrapIsDone = true;
                         }
                         else if (ScrapIsDone && RecIsDone && RefIsDone && !RetriedOnce)
                         {
                             ScrapIsDone = false;
                             RecIsDone = false;
                             RefIsDone = false;
                             RetriedOnce = true;
                         }
                         else if (RefIsDone && RecIsDone && ScrapIsDone && BotMetalAdded < KeysToScrap)
                         {
                             SendTradeMessage("Sorry, but I don't have enough scrap or rec to give you!");
                             SendTradeMessage("Please close the trade and try again. The bot will immediately craft for you.");
                             Bot.Log.Warn("Couldn't add enough scrap or rec for the user!");
                             IgnoringBot++;
                             DoneAddingMetal = true;
                         }
                         else if (WhileLoop > 100)
                         {
                             SendTradeMessage("Error: I cannot add metal at the moment. Either Steam is broken or I am broken!");
                             Bot.Log.Error("Error: Bot could not add metal to a trade.");
                             break;
                         }
                     }
                 }
             }
         }
         else
         {
             SendTradeMessage("Sorry, I don't accept " + item.ItemName + "!");
             SendTradeMessage("I only accept metal/keys! Please remove it from the trade to continue.");
             Bot.Log.Warn(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " added:  " + item.ItemName);
             InvalidItem++;
         }
         if (!ChooseDonate && UserMetalAdded.ScrapTotal % SellPricePerKey.ScrapTotal >= 0.0 && UserMetalAdded.ScrapTotal > 0.0)
         {
             TF2Value excess;
             NumKeys = UserMetalAdded.GetPriceUsingItem(SellPricePerKey, out excess);
             TF2Value MetalForNextKey = SellPricePerKey - excess;
             if (NumKeys > 0 && NumKeys != PreviousKeys)
             {
                 SendTradeMessage("You put up enough metal for " + NumKeys + " key(s).");
                 SendTradeMessage("Add " + MetalForNextKey.ToRefString() + " to buy a key/another key.");
                 int AddNumKeys = NumKeys + 1;
                 int AddMoreNumKeys = NumKeys + 2;
                 TF2Value CurrentKeys = SellPricePerKey * NumKeys;
                 TF2Value PlusOneKey = SellPricePerKey * (NumKeys + 1);
                 TF2Value PlusTwoKeys = SellPricePerKey * (NumKeys + 2);
                 SendTradeMessage("For reference: " + CurrentKeys.ToPartsString(false) + " = " + NumKeys + " key(s),");
                 SendTradeMessage(PlusOneKey.ToPartsString(false) + " = " + AddNumKeys + " key(s),");
                 SendTradeMessage(PlusTwoKeys.ToPartsString(false) + " = " + AddMoreNumKeys + " key(s)...");
                 if (NumKeys > InventoryKeys)
                 {
                     SendTradeMessage("I only have " + InventoryKeys + " in my backpack.");
                     Bot.Log.Warn(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " wanted to buy " + NumKeys + " key(s), but I only have " + InventoryKeys + " key(s).");
                     SendTradeMessage("Please remove " + excess.ToRefString() + ".");
                     NumKeys = InventoryKeys;
                     IgnoringBot++;
                 }
                 for (int count = BotKeysAdded; count < NumKeys; count++)
                 {
                     Trade.AddItemByDefindex(5021);
                     Bot.Log.Warn("I am adding Mann Co. Supply Crate Key.");
                     BotKeysAdded++;
                 }
                 PreviousKeys = NumKeys;
                 return;
             }
         }
     }
     else
     {
         SendTradeMessage("Error adding item. Please remove it and try again, or restart trade.");
         SendTradeMessage("Is your inventory private? Making it public helps trades work.");
         Bot.Log.Error("Error while user was adding an item. Possibly private inventory.");
     }
 }
Beispiel #34
0
 public override void OnMessage(string message, EChatEntryType type)
 {
     message = message.ToLower();
     if (message == "price")
     {
         SendChatMessage("I buy keys for " + BuyPricePerKey.ToRefString() + ", and sell keys for " + SellPricePerKey.ToRefString() + ".");
     }
     else if ((message.Contains("love") || message.Contains("luv") || message.Contains("<3")) && (message.Contains("y") || message.Contains("u")))
     {
         if (message.Contains("do"))
         {
             SendChatMessage("I love you lots. <3");
         }
         else
         {
             SendChatMessage("I love you too!");
         }
     }
     else if (message.Contains("<3"))
     {
         SendChatMessage("<3");
     }
     else if (message.Contains("thank"))
     {
         SendChatMessage("You're welcome!");
     }
     else if (message == "donate")
     {
         SendChatMessage("Please type that command into the trade window. And thanks!");
     }
     else if (message == "buy")
     {
         SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info.");
     }
     else if (message == "sell")
     {
         SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info.");
     }
     else if (message == "trade")
     {
         SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info.");
     }
     else if (message.Contains("stupid") || message.Contains("f**k") || message.Contains("can't") || message.Contains("cant") || message.Contains("what"))
     {
         SendChatMessage("Hey, do you need help? Type \"help\" for more info. Or else, are trades failing? Chances are that Steam is having the issues -- not me!");
     }
     else if (message.Contains("help"))
     {
         SendChatMessage("Type \"price\" to see my current prices. Type \"stock\" to see what I have. Then trade me, and put up your keys or metal and I will add my keys or exact price in metal automatically. You MUST put up exact metal if buying keys. Not having a private inventory is often helpful when trades fail. I also accept donations of either keys or metal. To donate, type \"donate\" in the trade window!");
     }
     else if (message == "commands")
     {
         SendChatMessage("Type \"price\" to see my current prices. Type \"stock\" to see what I have. Type \"info\" for more information on this bot via a link to the bot's TF2Outpost page. Type \"help\" for a guide on how to trade with the bot.  To donate, type \"donate\" in the trade window!");
     }
     else if (message == "info")
     {
         SendChatMessage("More information about this bot can be found here: http://www.tf2outpost.com/trade/25788259 .");
     }
     else if (message == "stock" || message == "inventory")
     {
         HasNonTradeCounted = false;
         CountInventory(true);
         if (NonTradeInventoryKeys == 0 && HasNonTradeCounted)
         {
             SendChatMessage("I don't have any keys to sell at the moment.");
             SendChatMessage("I can afford to buy " + NonTradeKeysCanBuy + " key(s). I am buying for " + BuyPricePerKey.ToRefString() + " each.");
         }
         else if (NonTradeInventoryKeys > 0 && HasNonTradeCounted)
         {
             if (NonTradeInventoryMetal < BuyPricePerKey)
             {
                 SendChatMessage("Currently I have " + NonTradeInventoryKeys + " key(s) for " + SellPricePerKey.ToRefString() + " each, but unfortunately I can not afford to buy keys from you at this time.");
             }
             else
             {
                 SendChatMessage("Currently I have " + NonTradeInventoryKeys + " key(s) for " + SellPricePerKey.ToRefString() + " each.");
                 SendChatMessage("I can afford to buy " + NonTradeKeysCanBuy + " key(s). I am buying for " + BuyPricePerKey.ToRefString() + " each.");
             }
         }
         else if (InventoryFailed)
         {
             SendChatMessage("Unable to check inventory due to being unable to get it from Steam. You can probably try again in a few moments if you like.");
             Bot.Log.Warn("Bot notified user of failure to count inventory due to failed Web Request.");
         }
         else
         {
             SendChatMessage("Oh no, I'm broke!");
         }
         if (NonTradeKeysCanBuy > 0 && BuyPricePerKey.ScrapPart > NonTradeScrap && BuyPricePerKey.ReclaimedPart > NonTradeReclaimed + (NonTradeScrap - BuyPricePerKey.ScrapPart) / 3)
         {
             SendChatMessage("I do not have exact change! Open and close a trade with me if you'd like me to make scrap/rec for you.");
             Bot.Log.Warn("Bot warned a user of a lack of scrap or rec during a stock request.");
         }
     }
     else if (IsAdmin)
     {
         if (message.StartsWith(".sell"))
         {
             double NewSellPrice = 0.0;
             SendChatMessage("Current selling price: " + SellPricePerKey.ToRefString() + ".");
             SellPricePerKey = TF2Value.Zero;
             if (message.Length >= 6)
             {
                 double.TryParse(message.Substring(5), out NewSellPrice);
                 Bot.Log.Success("Admin has requested that I set the new selling price to " + NewSellPrice + " ref.");
                 SellPricePerKey = TF2Value.FromRef(NewSellPrice);
                 SendChatMessage("Setting new selling price to: " + SellPricePerKey.ToRefString() + ".");
                 Bot.Log.Success("Successfully set new price.");
             }
             else
             {
                 SendChatMessage("I need more arguments. Current selling price: " + SellPricePerKey.ToRefString() + ".");
             }
         }
         else if (message.StartsWith(".buy"))
         {
             double NewBuyPrice = 0.0;
             SendChatMessage("Current buying price: " + BuyPricePerKey.ToRefString() + ".");
             BuyPricePerKey = TF2Value.Zero;
             if (message.Length >= 5)
             {
                 double.TryParse(message.Substring(4), out NewBuyPrice);
                 Bot.Log.Success("Admin has requested that I set the new buying price to " + NewBuyPrice + " ref.");
                 BuyPricePerKey = TF2Value.FromRef(NewBuyPrice);
                 SendChatMessage("Setting new buying price to: " + BuyPricePerKey.ToRefString() + ".");
                 Bot.Log.Success("Successfully set new price.");
             }
             else
             {
                 SendChatMessage("I need more arguments. Current buying price: " + BuyPricePerKey.ToRefString() + ".");
             }
         }
         else if (message.StartsWith(".play"))
         {
             if (message.Length >= 7)
             {
                 if (message.Substring(6) == "tf2")
                 {
                     Bot.SetGamePlaying(440);
                     Bot.Log.Success("Successfully simulated in-game status for TF2.");
                 }
                 Bot.SetGamePlaying(0);
                 Bot.Log.Success("Exited game simulation.");
             }
         }
         if (message.StartsWith(".removefriend"))
         {
             if (message.Substring(14) == "all")
             {
                 int friendCount = Bot.SteamFriends.GetFriendCount();
                 for (int x = 0; x < friendCount; x++)
                 {
                     SteamID DeletingFriendID = Bot.SteamFriends.GetFriendByIndex(x);
                     if (!Bot.Admins.Contains(DeletingFriendID))
                     {
                         Bot.SteamFriends.RemoveFriend(DeletingFriendID);
                     }
                     else
                     {
                         Bot.Log.Success("Skipped Admin " + Bot.SteamFriends.GetFriendPersonaName(DeletingFriendID) + ".");
                     }
                 }
                 Bot.Log.Success("Deleted all friends.");
             }
             else
             {
                 var EnteredID = Convert.ToUInt64(message.Substring(14));
                 var DeleteID = new SteamID(EnteredID);
                 if (InFriendsList(DeleteID))
                 {
                     Bot.SteamFriends.RemoveFriend(DeleteID);
                     Bot.Log.Success("Deleted " + Bot.SteamFriends.GetFriendPersonaName(DeleteID) + ".");
                 }
                 else
                 {
                     Bot.Log.Error("Failed to remove friend. You typed " + EnteredID + ".");
                 }
             }
         }
         else if (message == ".canceltrade")
         {
             if (Bot.CurrentTrade != null)
             {
                 SteamID LastTradedSID = Trade.OtherSID;
                 Trade.CancelTrade();
                 Bot.SteamFriends.SendChatMessage(LastTradedSID, EChatEntryType.ChatMsg, "Trade forcefully closed. Please retry as soon as you are ready to trade instead of whatever you were doing.");
                 Bot.Log.Warn("Trade with " + Bot.SteamFriends.GetFriendPersonaName(LastTradedSID) + " cancelled.");
                 Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
             }
             SendChatMessage("There is no current trade to cancel.");
         }
     }
     else
     {
         SendChatMessage(Bot.ChatResponse);
     }
 }
 public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
 {
     if (ActiveOrder != null && ActiveOrder.MatchesItem(inventoryItem))
     {
         ActiveOrder = null;
         Trade.RemoveAllItems();
     }
     else
     {
         if (schemaItem.Defindex == TF2Value.SCRAP_DEFINDEX)
             AmountAdded -= TF2Value.Scrap;
         else if (schemaItem.Defindex == TF2Value.RECLAIMED_DEFINDEX)
             AmountAdded -= TF2Value.Reclaimed;
         else if (schemaItem.Defindex == TF2Value.REFINED_DEFINDEX)
             AmountAdded -= TF2Value.Refined;
         else if (schemaItem.Defindex == TF2Value.KEY_DEFINDEX)
             AmountAdded -= TF2Value.Key;
     }
 }
        public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
        {
            Log.Info("Added item {0}{1} (defindex #{2}).", Order.GetQualityString(inventoryItem.Quality),
                     schemaItem.ItemName, schemaItem.Defindex);

            if (!schemaItem.IsPure())
            {
                Bot.GetInventory();

                bool found = false;
                foreach (Order o in Bot.Orders.BuyOrders)
                {
                    if (o.MatchesItem(inventoryItem))
                    {
                        found = true;

                        if (Bot.MyInventory.TotalPure() < o.Price)
                        {
                            Log.Warn("Out of metal for buy orders! Not enough metal to buy {0}.", schemaItem.ItemName);
                            SendTradeMessage("Unfortunately I am out of metal and cannot buy anything at the moment.");
                            SendTradeMessage("Enter 'buy' to get a list of the items I am selling.");
                        }
                        else if (Bot.MyInventory.GetItemsByDefindex(o.Defindex, o.Quality).Count >= o.MaxStock)
                        {
                            Log.Warn("Full stock for item {0}.", schemaItem.ItemName);
                            SendTradeMessage("Unfortunately I have full stock and cannot buy your {0}.", schemaItem.ItemName);
                            SendTradeMessage("Enter 'buy' to get a list of the items I am selling.");
                        }
                        else
                        {
                            ActiveOrder = o;
                            SendTradeMessage(o.ToString(Trade.CurrentSchema));

                            AddPure(ActiveOrder.Price);
                        }
                    }
                }

                if (!found)
                {
                    SendTradeMessage("I am currently not buying that item at the moment.");
                    SendTradeMessage("Enter 'buy' to get a list of the items I am selling.");
                }
            }
            else
            {
                if (schemaItem.Defindex == TF2Value.SCRAP_DEFINDEX)
                {
                    AmountAdded += TF2Value.Scrap;
                }
                else if (schemaItem.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                {
                    AmountAdded += TF2Value.Reclaimed;
                }
                else if (schemaItem.Defindex == TF2Value.REFINED_DEFINDEX)
                {
                    AmountAdded += TF2Value.Refined;
                }
                else if (schemaItem.Defindex == TF2Value.KEY_DEFINDEX)
                {
                    AmountAdded += TF2Value.Key;
                }
                else if (ActiveOrder != null)
                {
                    SendTradeMessage("Sorry, but I cannot accept any {0} as valid payment.",
                                     schemaItem.ItemName);
                }

                if (AmountAdded == ActiveOrder.Price)
                {
                    SendTradeMessage("You have paid the correct amount.");
                }
                else if (AmountAdded > ActiveOrder.Price)
                {
                    SendTradeMessage("You are paying too much! The price for the {0} is {1}.",
                                     ActiveOrder.GetSearchString(Trade.CurrentSchema), ActiveOrder.Price.ToRefString());
                }
            }
        }
Beispiel #37
0
 public override void OnMessage(string message, EChatEntryType type)
 {
     message = message.ToLower();
     if (message == "price")
     {
         SendChatMessage("I buy keys for " + BuyPricePerKey.ToRefString() + ", and sell keys for " + SellPricePerKey.ToRefString() + ".");
     }
     else if ((message.Contains("love") || message.Contains("luv") || message.Contains("<3")) && (message.Contains("y") || message.Contains("u")))
     {
         if (message.Contains("do"))
         {
             SendChatMessage("I love you lots. <3");
         }
         else
         {
             SendChatMessage("I love you too!");
         }
     }
     else if (message.Contains("<3"))
     {
         SendChatMessage("<3");
     }
     else if (message.Contains("thank"))
     {
         SendChatMessage("You're welcome!");
     }
     else if (message == "donate")
     {
         SendChatMessage("Please type that command into the trade window. And thanks!");
     }
     else if (message == "buy")
     {
         SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info.");
     }
     else if (message == "sell")
     {
         SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info.");
     }
     else if (message == "trade")
     {
         SendChatMessage("That's not a command. Please trade to begin and add keys or metal. Type 'help' for more info.");
     }
     else if (message.Contains("stupid") || message.Contains("f**k") || message.Contains("can't") || message.Contains("cant") || message.Contains("what"))
     {
         SendChatMessage("Hey, do you need help? Type \"help\" for more info. Or else, are trades failing? Chances are that Steam is having the issues -- not me!");
     }
     else if (message.Contains("help"))
     {
         SendChatMessage("Type \"price\" to see my current prices. Type \"stock\" to see what I have. Then trade me, and put up your keys or metal and I will add my keys or exact price in metal automatically. Type \"commands\" for a list of commands.");
     }
     else if (message == "commands")
     {
         SendChatMessage("Type \"price\" to see my current prices. Type \"stock\" to see what I have. Type \"confirm\" to have your trades confirmed if the bot does not do so. Type \"info\" for more information on this bot via a link to the bot's TF2Outpost page. Type \"help\" for a guide on how to trade with the bot. Type \"group\" to be invited to the group (WIP). To donate, type \"donate\" in the trade window!");
     }
     else if (message == "info")
     {
         SendChatMessage("More information about this bot can be found here: http://steamcommunity.com/groups/NarthsBots .");
     }
     else if (message == "group")
     {
         SendChatMessage("Coming soon...invite to group feature. But here is the group: http://steamcommunity.com/groups/NarthsBots .");
     }
     else if (message == "confirm")
     {
         Bot.AcceptAllMobileTradeConfirmations();
         SendChatMessage("Confirming all my trades. Message from owner: If this does not work, Steam failed to send a confirmation. Redo your trade. This is out of my control.");
     }
     else if (message == "stock" || message == "inventory")
     {
         HasNonTradeCounted = false;
         CountInventory(true);
         if (InventoryFailed)
         {
             SendChatMessage("I failed to start your trade because Steam is down. Try again later when Steam is working.");
             Bot.Log.Warn("I notified user of failure to count inventory due to failed Web Request.");
         }
         if (NonTradeInventoryKeys == 0 && HasNonTradeCounted)
         {
             SendChatMessage("I don't have any keys to sell at the moment.");
             SendChatMessage("I can afford to buy " + NonTradeKeysCanBuy + " key(s). I am buying for " + BuyPricePerKey.ToRefString() + " each.");
         }
         else if (NonTradeInventoryKeys > 0 && HasNonTradeCounted)
         {
             if (NonTradeInventoryMetal < BuyPricePerKey)
             {
                 SendChatMessage("Currently I have " + NonTradeInventoryKeys + " key(s) for " + SellPricePerKey.ToRefString() + " each, but unfortunately I can not afford to buy keys from you at this time.");
             }
             else
             {
                 SendChatMessage("Currently I have " + NonTradeInventoryKeys + " key(s) for " + SellPricePerKey.ToRefString() + " each.");
                 SendChatMessage("I can afford to buy " + NonTradeKeysCanBuy + " key(s). I am buying for " + BuyPricePerKey.ToRefString() + " each.");
             }
         }
         else
         {
             SendChatMessage("Oh no, I'm broke!");
         }
         if (NonTradeKeysCanBuy > 0 && BuyPricePerKey.ScrapPart > NonTradeScrap && BuyPricePerKey.ReclaimedPart > NonTradeReclaimed + (NonTradeScrap - BuyPricePerKey.ScrapPart) / 3)
         {
             SendChatMessage("I do not have exact change! Open and close a trade with me if you'd like me to make scrap/rec for you.");
             Bot.Log.Warn("I warned a user of a lack of scrap or rec during a stock request.");
         }
     }
     else if (IsAdmin)
     {
         if (message.StartsWith(".sell"))
         {
             double NewSellPrice = 0.0;
             SendChatMessage("Current selling price: " + SellPricePerKey.ToRefString() + ".");
             SellPricePerKey = TF2Value.Zero;
             if (message.Length >= 6)
             {
                 double.TryParse(message.Substring(5), out NewSellPrice);
                 Bot.Log.Success("Admin has requested that I set the new selling price to " + NewSellPrice + " ref.");
                 SellPricePerKey = TF2Value.FromRef(NewSellPrice);
                 SendChatMessage("Setting new selling price to: " + SellPricePerKey.ToRefString() + ".");
                 Bot.Log.Success("Successfully set new price.");
             }
             else
             {
                 SendChatMessage("I need more arguments. Current selling price: " + SellPricePerKey.ToRefString() + ".");
             }
         }
         else if (message.StartsWith(".buy"))
         {
             double NewBuyPrice = 0.0;
             SendChatMessage("Current buying price: " + BuyPricePerKey.ToRefString() + ".");
             BuyPricePerKey = TF2Value.Zero;
             if (message.Length >= 5)
             {
                 double.TryParse(message.Substring(4), out NewBuyPrice);
                 Bot.Log.Success("Admin has requested that I set the new buying price to " + NewBuyPrice + " ref.");
                 BuyPricePerKey = TF2Value.FromRef(NewBuyPrice);
                 SendChatMessage("Setting new buying price to: " + BuyPricePerKey.ToRefString() + ".");
                 Bot.Log.Success("Successfully set new price.");
             }
             else
             {
                 SendChatMessage("I need more arguments. Current buying price: " + BuyPricePerKey.ToRefString() + ".");
             }
         }
         else if (message.StartsWith(".play"))
         {
             if (message.Length >= 7)
             {
                 if (message.Substring(6) == "tf2")
                 {
                     Bot.SetGamePlaying(440);
                     Bot.Log.Success("Successfully simulated in-game status for TF2.");
                 }
                 Bot.SetGamePlaying(0);
                 Bot.Log.Success("Exited game simulation.");
             }
         }
         else if (message.StartsWith(".removefriend") || message.StartsWith(".deletefriend"))
         {
             if (message.Substring(14) == "all")
             {
                 int friendCount = Bot.SteamFriends.GetFriendCount();
                 for (int x = 0; x < friendCount; x++)
                 {
                     SteamID DeletingFriendID = Bot.SteamFriends.GetFriendByIndex(x);
                     if (!Bot.Admins.Contains(DeletingFriendID))
                     {
                         Bot.SteamFriends.RemoveFriend(DeletingFriendID);
                     }
                     else
                     {
                         Bot.Log.Success("Skipped Admin " + Bot.SteamFriends.GetFriendPersonaName(DeletingFriendID) + ".");
                     }
                 }
                 Bot.Log.Success("Deleting all friends.");
             }
             else
             {
                 string FriendID;
                 FriendID = message.Substring(14);
                 FriendDelete(FriendID);
             }
         }
         else if (message == ".canceltrade")
         {
             if (Bot.CurrentTrade != null)
             {
                 SteamID LastTradedSID = Trade.OtherSID;
                 Trade.CancelTrade();
                 Bot.SteamFriends.SendChatMessage(LastTradedSID, EChatEntryType.ChatMsg, "Trade forcefully closed. Please retry as soon as you are ready to trade instead of whatever you were doing.");
                 Bot.Log.Warn("Trade with " + Bot.SteamFriends.GetFriendPersonaName(LastTradedSID) + " cancelled.");
                 IgnoringBot += 4;
                 Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
             }
             else
             {
                 SendChatMessage("There is no current trade to cancel.");
             }
         }
         else if (message == ".auth")
         {
             Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, Bot.SteamGuardAccount.GenerateSteamGuardCode());
             Bot.Log.Warn("Generated code:" + Bot.SteamGuardAccount.GenerateSteamGuardCode() + ".");
         }
     }
     else
     {
         SendChatMessage(Bot.ChatResponse);
     }
 }
        public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
        {
            Log.Info("Added item {0}{1} (defindex #{2}).", Order.GetQualityString(inventoryItem.Quality),
                schemaItem.ItemName, schemaItem.Defindex);

            if (!schemaItem.IsPure())
            {
                Bot.GetInventory();

                bool found = false;
                foreach (Order o in Bot.Orders.BuyOrders)
                {
                    if (o.MatchesItem(inventoryItem))
                    {
                        found = true;

                        if (Bot.MyInventory.TotalPure() < o.Price)
                        {
                            Log.Warn("Out of metal for buy orders! Not enough metal to buy {0}.", schemaItem.ItemName);
                            SendTradeMessage("Unfortunately I am out of metal and cannot buy anything at the moment.");
                            SendTradeMessage("Enter 'buy' to get a list of the items I am selling.");
                        }
                        else if (Bot.MyInventory.GetItemsByDefindex(o.Defindex, o.Quality).Count >= o.MaxStock)
                        {
                            Log.Warn("Full stock for item {0}.", schemaItem.ItemName);
                            SendTradeMessage("Unfortunately I have full stock and cannot buy your {0}.", schemaItem.ItemName);
                            SendTradeMessage("Enter 'buy' to get a list of the items I am selling.");
                        }
                        else
                        {
                            ActiveOrder = o;
                            SendTradeMessage(o.ToString(Trade.CurrentSchema));

                            AddPure(ActiveOrder.Price);
                        }
                    }
                }

                if (!found)
                {
                    SendTradeMessage("I am currently not buying that item at the moment.");
                    SendTradeMessage("Enter 'buy' to get a list of the items I am selling.");
                }
            }
            else
            {
                if (schemaItem.Defindex == TF2Value.SCRAP_DEFINDEX)
                    AmountAdded += TF2Value.Scrap;
                else if (schemaItem.Defindex == TF2Value.RECLAIMED_DEFINDEX)
                    AmountAdded += TF2Value.Reclaimed;
                else if (schemaItem.Defindex == TF2Value.REFINED_DEFINDEX)
                    AmountAdded += TF2Value.Refined;
                else if (schemaItem.Defindex == TF2Value.KEY_DEFINDEX)
                    AmountAdded += TF2Value.Key;
                else if (ActiveOrder != null)
                {
                    SendTradeMessage("Sorry, but I cannot accept any {0} as valid payment.",
                        schemaItem.ItemName);
                }

                if (AmountAdded == ActiveOrder.Price)
                {
                    SendTradeMessage("You have paid the correct amount.");
                }
                else if (AmountAdded > ActiveOrder.Price)
                {
                    SendTradeMessage("You are paying too much! The price for the {0} is {1}.",
                        ActiveOrder.GetSearchString(Trade.CurrentSchema), ActiveOrder.Price.ToRefString());
                }
            }
        }
        public bool Validate()
        {
            AmountAdded = TF2Value.Zero;

            List<string> errors = new List<string> ();

            foreach (TradeUserAssets asset in Trade.OtherOfferedItems)
            {
                var item = Trade.OtherInventory.GetItem(asset.assetid);
                if (item.Defindex == 5000)
                    AmountAdded += TF2Value.Scrap;
                else if (item.Defindex == 5001)
                    AmountAdded += TF2Value.Reclaimed;
                else if (item.Defindex == 5002)
                    AmountAdded += TF2Value.Refined;
                else
                {
                    var schemaItem = Trade.CurrentSchema.GetItem (item.Defindex);
                    errors.Add ("Item " + schemaItem.Name + " is not a metal.");
                }
            }

            if (AmountAdded == TF2Value.Zero)
            {
                errors.Add ("You must put up at least 1 scrap.");
            }

            // send the errors
            if (errors.Count != 0)
                SendTradeMessage("There were errors in your trade: ");
            foreach (string error in errors)
            {
                SendTradeMessage(error);
            }

            return errors.Count == 0;
        }
        public bool Validate()
        {
            List <string> errors = new List <string>();
            TF2Value?     diff   = null;

            if (ActiveOrder == null)
            {
                if (Trade.OtherOfferedItems.Count() == 0)
                {
                    errors.Add("There is nothing you are offering.");
                }
                else
                {
                    errors.Add("I am currently not buying any of those items.");
                }
            }
            else
            {
                // in buy orders, assume the bot calculates the pricing correctly.
                if (!ActiveOrder.IsBuyOrder)
                {
                    if (HasNonPureInTrade())
                    {
                        errors.Add("You have non-pure items in payment.");
                    }

                    if (AmountAdded < ActiveOrder.Price)
                    {
                        errors.Add(string.Format("You have only paid {0}. You still have {2} to go to reach the price of {1}.",
                                                 AmountAdded.ToRefString(), ActiveOrder.Price.ToRefString(),
                                                 (ActiveOrder.Price - AmountAdded).ToRefString()));
                    }
                    else if (AmountAdded > ActiveOrder.Price)
                    {
                        diff = AmountAdded - ActiveOrder.Price;
                    }
                    else if (AmountAdded > ActiveOrder.Price + TF2Value.FromRef(1))
                    {
                        errors.Add(string.Format("You are paying too much. The price is {0}, but you have paid {1}.",
                                                 ActiveOrder.Price.ToRefString(), AmountAdded.ToRefString()));
                    }
                }
                else if (Trade.OtherOfferedItems.Count() > 1)
                {
                    errors.Add("You have other items in your trade besides the one I am buying.");
                }
            }

            if (errors.Count > 0)
            {
                SendTradeMessage("There were problems with your trade:");
                foreach (string e in errors)
                {
                    SendTradeMessage("> " + e);
                }
            }

            if (errors.Count == 0 && diff != null)
            {
                SendTradeMessage("Adding change...");
                AddPure(diff.Value);
            }

            return(errors.Count == 0);
        }
        public void AddPure(TF2Value orderPayment)
        {
            if (ActiveOrder == null)
            {
                Log.Error("Trade with user #{0}: SimpleUserHandler.ActiveOrder == null.", OtherSID.ToString());
                Trade.CancelTrade();
                SendChatMessage("I have encountered an error. Please send the trade again.");

                return;
            }

            SendTradeMessage("Removing items from previous trades...");
            Trade.RemoveAllItems();

            SendTradeMessage("Adding payment for this trade...");
            TF2Value myPayment        = TF2Value.Zero;
            TF2Value currentIteration = TF2Value.Key;

            while (myPayment + currentIteration <= orderPayment)
            {
                if (!Trade.AddItemByDefindex(TF2Value.KEY_DEFINDEX))
                {
                    //Log.Warn("[TRADE-BUY] No more keys found. Moving on to refined metal.");
                    break;
                }

                Log.Debug("Added key in trade with user {0}.", OtherSID.ToString());
                myPayment += currentIteration;
            }

            currentIteration = TF2Value.Refined;
            while (myPayment + currentIteration <= orderPayment)
            {
                if (!Trade.AddItemByDefindex(TF2Value.REFINED_DEFINDEX))
                {
                    //Log.Warn("[TRADE-BUY] No more refined metal found. Moving on to reclaimed metal.");
                    break;
                }

                Log.Debug("Added refined metal in trade with user {0}.", OtherSID.ToString());
                myPayment += currentIteration;
            }

            currentIteration = TF2Value.Reclaimed;
            while (myPayment + currentIteration <= orderPayment)
            {
                if (!Trade.AddItemByDefindex(TF2Value.RECLAIMED_DEFINDEX))
                {
                    //Log.Warn("[TRADE-BUY] No more reclaimed metal found. Moving on to scrap metal.");
                    break;
                }

                Log.Debug("Added reclaimed metal in trade with user {0}.", OtherSID.ToString());
                myPayment += currentIteration;
            }

            currentIteration = TF2Value.Scrap;
            while (myPayment + currentIteration <= orderPayment)
            {
                if (!Trade.AddItemByDefindex(TF2Value.SCRAP_DEFINDEX))
                {
                    Log.Warn("[PAYMENT] No more scrap metal found.");
                    break;
                }

                Log.Debug("Added scrap metal in trade with user {0}.", OtherSID.ToString());
                myPayment += currentIteration;
            }

            if (myPayment != orderPayment)
            {
                Log.Error("Could not add correct amount of {0}. Instead added {1}.", ActiveOrder.Price.ToRefString(),
                          myPayment.ToRefString());
                Trade.CancelTrade();
                SendChatMessage("I have encountered an error. Please send the trade again.");
            }

            SendTradeMessage("Finished paying {0}.", myPayment.ToRefString());
        }