コード例 #1
0
        public void Test()
        {
            if (UserKeyAdded > 0)
            {
                //they are selling keys
                //check amount of keys user added (make into scrap)
                //see if currencies are the same
                //+/- if not
                TF2Currency tempCurn = new TF2Currency(0, 0, 0, (int)clsFunctions.KEY_BUY_VALUE.ToScrap() * UserKeyAdded);

                string TempCurnDebug = String.Format("UserStuff Ref Change {0} Rec Change {1} Scrap Change {2} Key Buy Price {3} Key Sell Price {4}", tempCurn.Refined, tempCurn.Reclaimed, tempCurn.Scrap, clsFunctions.KEY_BUY_VALUE.ToPrice(), clsFunctions.KEY_SELL_VALUE.ToPrice());

                TF2Currency change = tempCurn.GetChange(Bot.myCurrency);

                string DebugFormat = String.Format("Ref Change {0} Rec Change {1} Scrap Change {2} Key Buy Price {3} Key Sell Price {4}", change.Refined, change.Reclaimed, change.Scrap, clsFunctions.KEY_BUY_VALUE.ToPrice(), clsFunctions.KEY_SELL_VALUE.ToPrice());

                Bot.log.Success(DebugFormat);

                if (change.Neutral())
                {
                }
                else if (change.Positive())
                {
                    //+ change means user is overpaying and bot needs to add correct change.
                    #region Refined Adding

                    if (change.Refined > 0)
                    {
                        if (InventoryRef - Bot.myCurrency.Refined >= change.Refined)
                        {
                            uint RefAdded = Trade.AddAllItemsByDefindex(5002, (uint)change.Refined);
                            Bot.myCurrency.AddRef((int)RefAdded);
                            if (RefAdded == change.Refined)
                            {
                                Bot.log.Success(String.Format("Added {0} refined.", RefAdded));
                            }
                        }
                        else
                        {
                            Trade.SendMessage("I'm sorry. I don't seem to have enough refined!");
                        }
                    }

                    #endregion

                    #region Reclaimed Adding

                    if (change.Reclaimed > 0)
                    {
                        if (InventoryRec - Bot.myCurrency.Reclaimed >= change.Reclaimed)
                        {
                            if (Bot.myCurrency.Reclaimed == 2)
                            {
                                if (InventoryRef - Bot.myCurrency.Refined >= 1)
                                {
                                    uint rectoremove = 2;
                                    if (change.Reclaimed == 2)
                                    {
                                        rectoremove = 1;
                                    }
                                    uint RecRemoved = Trade.RemoveAllItemsByDefindex(5001, rectoremove);
                                    Bot.myCurrency.RemoveRec((int)RecRemoved);
                                    if (RecRemoved == rectoremove)
                                    {
                                        Bot.log.Success(String.Format("Removed {0} reclaimed", RecRemoved));
                                        uint RefAdded = Trade.AddAllItemsByDefindex(5002, 1);

                                        if (RefAdded == 1)
                                        {
                                            Bot.myCurrency.AddRef();
                                            Bot.log.Success("Added 1 refined.");
                                            change.RemoveRec();
                                        }
                                        else
                                        {
                                            Trade.CancelTrade();
                                            Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                            Bot.log.Error("Something went wrong removing 2 rec and adding a ref(adding ref part)");
                                        }
                                    }
                                }
                                else
                                {
                                    uint RecAdded = Trade.AddAllItemsByDefindex(5001, (uint)change.Reclaimed);
                                    Bot.myCurrency.AddRec((int)RecAdded);
                                    if (RecAdded == change.Reclaimed)
                                    {
                                        Bot.log.Success(String.Format("Added {0} rec", RecAdded));
                                    }
                                    else
                                    {
                                        Trade.CancelTrade();
                                        Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                        Bot.log.Error("Couldn't add reclaimed");
                                    }
                                }
                            }
                            else
                            {
                                uint RecAdded = Trade.AddAllItemsByDefindex(5001, (uint)change.Reclaimed);
                                Bot.myCurrency.AddRec((int)RecAdded);
                                if (RecAdded == change.Reclaimed)
                                {
                                    Bot.log.Success(String.Format("Added {0} rec", RecAdded));
                                }
                                else
                                {
                                    Trade.CancelTrade();
                                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                    Bot.log.Error("Couldn't add reclaimed");
                                }
                            }
                        }
                        else
                        {
                            Trade.SendMessage("Sorry. I do not have enough reclaimed!");
                        }
                    }
                    #endregion

                    #region Scrap Adding
                    if (change.Scrap > 0)
                    {
                        uint ScrapAdded = Trade.AddAllItemsByDefindex(5000, (uint)change.Scrap);
                        Bot.myCurrency.AddScrap((int)ScrapAdded);
                        if (ScrapAdded == change.Scrap)
                        {
                            Bot.log.Success(String.Format("Added {0} scrap", ScrapAdded));
                        }
                        else
                        {
                            Trade.CancelTrade();
                            Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                            Bot.log.Error("Couldn't add scrap");
                        }
                    }
                    #endregion
                }
                else if (change.Negative())
                {
                    change.MakePositive();
                    //- change means bot needs to remove items.

                    #region Refined Removing
                    if (change.Refined > 0)
                    {
                        if (Bot.myCurrency.Refined >= change.Refined)
                        {
                            uint RefRemoved = Trade.RemoveAllItemsByDefindex(5002, (uint)change.Refined);
                            Bot.myCurrency.RemoveRef((int)RefRemoved);
                            if (RefRemoved == change.Refined)
                            {
                                Bot.log.Success(String.Format("Removed {0} refined", RefRemoved));
                            }
                            else
                            {
                                Trade.CancelTrade();
                                Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                Bot.log.Error("Something went wrong removing ref");
                            }
                        }
                        else
                        {
                            Trade.CancelTrade();
                            Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                            Bot.log.Error("Something went wrong removing ref");
                        }
                    }
                    #endregion

                    #region Reclaimed Removeing
                    if (change.Reclaimed > 0)
                    {
                        if (Bot.myCurrency.Reclaimed >= change.Reclaimed)
                        {
                            uint RecRemoved = Trade.RemoveAllItemsByDefindex(5001, (uint)change.Reclaimed);
                            Bot.myCurrency.RemoveRec((int)RecRemoved);
                            if (RecRemoved == change.Reclaimed)
                            {
                                Bot.log.Success(String.Format("Removed {0} rec", RecRemoved));
                            }
                            else
                            {
                                Trade.CancelTrade();
                                Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                Bot.log.Error("Something went wrong removing rec");
                            }
                        }
                        else if (Bot.myCurrency.Refined >= change.Reclaimed / 3)
                        {
                            double reftoremove;
                            if (change.Reclaimed > 3)
                            {
                                reftoremove = Math.Abs(change.Reclaimed) / 3;
                            }
                            else
                            {
                                reftoremove = 1;
                            }
                            reftoremove = Math.Round(reftoremove, 0, MidpointRounding.AwayFromZero);
                            if (Bot.myCurrency.Refined >= reftoremove)
                            {
                                uint RefRemoved = Trade.RemoveAllItemsByDefindex(5002, (uint)reftoremove);
                                Bot.myCurrency.RemoveRef((int)RefRemoved);
                                if (RefRemoved == reftoremove)
                                {
                                    Bot.log.Success(String.Format("Removed {0} ref", RefRemoved));
                                    int  rectoadd = ((int)RefRemoved * 3) - change.Reclaimed;
                                    uint recadded = Trade.AddAllItemsByDefindex(5001, (uint)rectoadd);
                                    Bot.myCurrency.AddRec(rectoadd);
                                    if (recadded == rectoadd)
                                    {
                                        Bot.log.Success(String.Format("Added {0} rec.", recadded));
                                    }
                                }
                                else
                                {
                                    Trade.CancelTrade();
                                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                    Bot.log.Error("Something went wrong removing ref");
                                }
                            }
                        }
                    }
                    #endregion

                    #region Scrap Removing

                    if (change.Scrap > 0)
                    {
                        uint ScrapRemoved = Trade.RemoveAllItemsByDefindex(5000, (uint)change.Scrap);
                        Bot.myCurrency.RemoveScrap((int)ScrapRemoved);
                        if (ScrapRemoved == change.Scrap)
                        {
                            Bot.log.Warn(String.Format("Removed {0} scrap", ScrapRemoved));
                        }
                        else
                        {
                            Trade.CancelTrade();
                            Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                            Bot.log.Error("Couldn't remove scrap");
                        }
                    }
                    #endregion
                }
            }
            else if (UserKeyAdded == 0 && (Bot.myCurrency.Refined > 0 || Bot.myCurrency.Reclaimed > 0 || Bot.myCurrency.Scrap > 0))
            {
                uint MetalRemoved = Trade.RemoveAllItemsByDefindex(5002);
                Bot.myCurrency.RemoveRef((int)MetalRemoved);
                MetalRemoved = Trade.RemoveAllItemsByDefindex(5001);
                Bot.myCurrency.RemoveRec((int)MetalRemoved);
                MetalRemoved = Trade.RemoveAllItemsByDefindex(5000);
                Bot.myCurrency.RemoveScrap((int)MetalRemoved);
                Bot.log.Warn("Removed all metal as all keys were removed");
            }
            else
            {
                //they are buying keys
                //check metal they have added
                //divide by key selling price
                //if they have enough for one add (after checking # added

                int iUserKeyAfford = Bot.userCurrency.ToKeys(false);
                int iKeysToAdd     = iUserKeyAfford - KeyBotAdded;

                if (iKeysToAdd == 0)
                {
                }
                else if (iKeysToAdd > 0)
                {
                    while (iKeysToAdd > 0)
                    {
                        try
                        {
                            if (Trade.AddItem(KeyIDS[KeyBotAdded]))
                            {
                                KeyBotAdded++;
                                Bot.log.Success("Added a key.");
                                iKeysToAdd--;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Trade.SendMessage("I don't have enough keys!");
                            iKeysToAdd = 0;
                        }
                    }
                }
                else if (iKeysToAdd < 0)
                {
                    while (iKeysToAdd < 0)
                    {
                        try
                        {
                            if (Trade.RemoveItem(KeyIDS[KeyBotAdded--]))
                            {
                                KeyBotAdded--;
                                Bot.log.Success("Removed a key");
                                iKeysToAdd++;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            Trade.CancelTrade();
                            Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "I'm sorry. Something went wrong. Please try again.");
                            iKeysToAdd = 0;
                        }
                    }
                }
            }
        }
コード例 #2
0
        }//Stop()

        public void ScrapbankMethod()
        {
            while (bStarted)
            {
                Thread.Sleep(1000);

                TF2Currency change = Bot.userCurrency.GetChange(Bot.myCurrency);

                if (change.Neutral())
                {
                    return;//no change to remove or add
                }
                if (change.Positive())
                {
                    #region Refined Adding

                    if (change.Refined > 0)
                    {
                        if (InventoryRef - Bot.myCurrency.Refined >= change.Refined)
                        {
                            uint RefAdded = Bot.CurrentTrade.AddAllItemsByDefindex(5002, (uint)change.Refined);
                            Bot.myCurrency.AddRef((int)RefAdded);
                            if (RefAdded == change.Refined)
                            {
                                Bot.log.Success(String.Format("Added {0} refined.", RefAdded));
                            }
                        }
                        else
                        {
                            Bot.CurrentTrade.SendMessage("Sorry. I do not have enough refined!");
                        }
                    }

                    #endregion Refined Adding

                    #region Reclaimed Adding

                    if (change.Reclaimed > 0)
                    {
                        if (InventoryRec - Bot.myCurrency.Reclaimed > change.Reclaimed)
                        {
                            if (Bot.myCurrency.Reclaimed == 2)
                            {
                                if (InventoryRef - Bot.myCurrency.Refined - 1 >= 1)
                                {
                                    uint RecRemoved = Bot.CurrentTrade.RemoveAllItemsByDefindex(5001, 2);
                                    Bot.myCurrency.RemoveRec((int)RecRemoved);
                                    if (RecRemoved == 2)
                                    {
                                        Bot.log.Success(String.Format("Removed {0} reclaimed", RecRemoved));
                                        if (Bot.CurrentTrade.AddItemByDefindex(5002))
                                        {
                                            Bot.myCurrency.AddRef();
                                            Bot.log.Success("Added 1 refined.");
                                        }
                                        else
                                        {
                                            Bot.CurrentTrade.CancelTrade();
                                            Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                            Bot.log.Error("Something went wrong removing 2 rec and adding a ref(adding ref part)");
                                        }
                                    }
                                }
                                else
                                {
                                    uint RecAdded = Bot.CurrentTrade.AddAllItemsByDefindex(5001, (uint)change.Reclaimed);
                                    Bot.myCurrency.AddRec((int)RecAdded);
                                    if (RecAdded == change.Reclaimed)
                                    {
                                        Bot.log.Success(String.Format("Added {0} rec", RecAdded));
                                    }
                                    else
                                    {
                                        Bot.CurrentTrade.CancelTrade();
                                        Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                        Bot.log.Error("Couldn't add reclaimed");
                                    }
                                }
                            }
                            else
                            {
                                uint RecAdded = Bot.CurrentTrade.AddAllItemsByDefindex(5001, (uint)change.Reclaimed);
                                Bot.myCurrency.AddRec((int)RecAdded);
                                Bot.log.Success(String.Format("Added {0} rec", RecAdded));
                                if (RecAdded == change.Reclaimed)
                                {
                                    return;
                                }
                                else
                                {
                                    Bot.CurrentTrade.CancelTrade();
                                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                    Bot.log.Error("Couldn't add reclaimed");
                                }
                            }
                        }
                        else
                        {
                            Bot.CurrentTrade.SendMessage("Sorry. I do not have enough reclaimed!");
                        }
                    }

                    #endregion Reclaimed Adding

                    #region Scrap Adding

                    if (change.Scrap > 0)
                    {
                        if (InventoryScrap - Bot.myCurrency.Scrap >= change.Scrap)
                        {
                            if (Bot.myCurrency.Scrap == 2)
                            {
                                if (Bot.myCurrency.Reclaimed == 2)
                                {
                                    if (InventoryRef - Bot.myCurrency.Refined >= 1)
                                    {
                                        uint RecRemoved = Bot.CurrentTrade.RemoveAllItemsByDefindex(5001, 2);
                                        Bot.myCurrency.RemoveRec((int)RecRemoved);
                                        if (RecRemoved == 2)
                                        {
                                            Bot.log.Success(String.Format("Removed {0} reclaimed", RecRemoved));

                                            uint ScrapRemoved = Bot.CurrentTrade.RemoveAllItemsByDefindex(5000, 2);
                                            Bot.myCurrency.RemoveScrap((int)ScrapRemoved);
                                            if (ScrapRemoved == 2)
                                            {
                                                Bot.log.Success(String.Format("Removed {0} scrap.", ScrapRemoved));
                                                if (Bot.CurrentTrade.AddItemByDefindex(5002))
                                                {
                                                    Bot.myCurrency.AddRef();
                                                    Bot.log.Success("Added 1 refined.");
                                                }
                                                else
                                                {
                                                    Bot.CurrentTrade.CancelTrade();
                                                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                                    Bot.log.Error("Something went wrong removing 2 rec 2 scrap and adding a ref (adding ref part)");
                                                }
                                            }
                                            else
                                            {
                                                Bot.CurrentTrade.CancelTrade();
                                                Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                                Bot.log.Error("Something went wrong removing 2 scrap and adding a ref (removing 2 scrap)");
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (InventoryRec - Bot.myCurrency.Reclaimed >= 1)
                                    {
                                        uint ScrapRemoved = Bot.CurrentTrade.RemoveAllItemsByDefindex(5000, 2);
                                        Bot.myCurrency.RemoveScrap((int)ScrapRemoved);
                                        if (ScrapRemoved == 2)
                                        {
                                            Bot.log.Success(String.Format("Removed {0} scrap.", ScrapRemoved));

                                            if (Bot.CurrentTrade.AddItemByDefindex(5001))
                                            {
                                                Bot.myCurrency.AddRec();
                                                Bot.log.Success("Added 1 rec.");
                                            }
                                            else
                                            {
                                                Bot.CurrentTrade.CancelTrade();
                                                Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                                Bot.log.Error("Something went wrong removing 2 rec 2 scrap and adding a ref (adding ref part)");
                                            }
                                        }
                                        else
                                        {
                                            Bot.CurrentTrade.CancelTrade();
                                            Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                            Bot.log.Error("Something went wrong removing 2 scrap and adding a ref (removing 2 scrap)");
                                        }
                                    }
                                    else
                                    {
                                        Bot.CurrentTrade.SendMessage("I don't have enough reclaimed!");
                                    }
                                }
                            }
                            else
                            {
                                uint ScrapAdded = Bot.CurrentTrade.AddAllItemsByDefindex(5000, (uint)change.Scrap);
                                Bot.myCurrency.AddScrap((int)ScrapAdded);
                                if (ScrapAdded == change.Scrap)
                                {
                                    Bot.log.Success(String.Format("Added {0} scrap.", ScrapAdded));
                                }
                                else
                                {
                                    Bot.CurrentTrade.CancelTrade();
                                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                    Bot.log.Error("Something went wrong adding scrap.");
                                }
                            }
                        }
                        else
                        {
                            Bot.CurrentTrade.SendMessage("Sorry. I do not have enough scrap!");
                        }
                    }

                    #endregion Scrap Adding
                }
                else if (change.Negative())
                {
                    change.MakePositive();
                    if (Bot.myCurrency.Weapon > 0 && Bot.myCurrency.Refined == 0 & Bot.myCurrency.Reclaimed == 0 && Bot.myCurrency.Scrap == 0)
                    {
                        //user has items reserved so they haven't added enough metal yet.
                        return;
                    }
                    else if (Bot.myCurrency.Weapon >= 0 && (Bot.myCurrency.Refined > 0 || Bot.myCurrency.Reclaimed > 0 || Bot.myCurrency.Scrap > 0))
                    {
                        if (change.Refined > 0)
                        {
                            if (Bot.myCurrency.Refined >= change.Refined)
                            {
                                uint RefRemoved = Bot.CurrentTrade.RemoveAllItemsByDefindex(5002, (uint)change.Refined);
                                Bot.myCurrency.RemoveRef((int)RefRemoved);
                                if (RefRemoved == change.Refined)
                                {
                                    Bot.log.Success(String.Format("Removed {0} ref.", RefRemoved));
                                }
                                else
                                {
                                    Bot.CurrentTrade.CancelTrade();
                                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                    Bot.log.Error("Something went wrong removing ref");
                                }
                            }
                            else
                            {
                                Bot.CurrentTrade.CancelTrade();
                                Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                Bot.log.Error("Something went wrong removing ref");
                            }
                        }
                        if (change.Reclaimed > 0)
                        {
                            if (Bot.myCurrency.Refined >= change.Refined)
                            {
                                uint RecRemoved = Bot.CurrentTrade.RemoveAllItemsByDefindex(5001, (uint)change.Reclaimed);
                                Bot.myCurrency.RemoveRec((int)RecRemoved);
                                if (RecRemoved == change.Reclaimed)
                                {
                                    Bot.log.Success(String.Format("Removed {0} rec.", RecRemoved));
                                }
                                else
                                {
                                    Bot.CurrentTrade.CancelTrade();
                                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                    Bot.log.Error("Something went wrong removing rec");
                                }
                            }
                            else
                            {
                                Bot.CurrentTrade.CancelTrade();
                                Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                Bot.log.Error("Something went wrong removing rec");
                            }
                        }
                        if (change.Scrap > 0)
                        {
                            if (Bot.myCurrency.Scrap >= change.Scrap)
                            {
                                uint ScrapRemoved = Bot.CurrentTrade.RemoveAllItemsByDefindex(5000, (uint)change.Scrap);
                                Bot.myCurrency.RemoveScrap((int)ScrapRemoved);
                                if (ScrapRemoved == change.Scrap)
                                {
                                    Bot.log.Success(String.Format("Removed {0} scrap.", ScrapRemoved));
                                }
                                else
                                {
                                    Bot.CurrentTrade.CancelTrade();
                                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                    Bot.log.Error("Something went wrong removing scrap");
                                }
                            }
                            else
                            {
                                Bot.CurrentTrade.CancelTrade();
                                Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Sorry. Something went wrong. Please trade me again.");
                                Bot.log.Error("Something went wrong removing scrap");
                            }
                        }
                        return;
                    }//else if (Bot.myCurrency.Weapon >= 0 && (Bot.myCurrency.Refined > 0 || Bot.myCurrency.Reclaimed > 0 || Bot.myCurrency.Scrap > 0))
                }
            }
        }