Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 79.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SteamTrade;
  6. using SteamKit2;
  7. using System.Timers;
  8. using System.IO;
  9. using System.Windows.Forms;
  10. using System.Management;
  11. using System.Net.Mail;
  12. using System.Net;
  13. using System.Threading.Tasks;
  14.  
  15.  
  16. namespace SteamBot
  17. {
  18. public class CustomBot : UserHandler
  19. {
  20. #region "Universal Variables"
  21. BotSettings mySettings;
  22.  
  23. bool invalidSettings = false;
  24.  
  25. public int chatMode = 0;
  26. public const int STEAMCHAT = 0;
  27. public const int TRADECHAT = 1;
  28.  
  29. Schema currentSchema;
  30.  
  31. string botBasics = "AfredoBot All items";
  32. #endregion
  33. #region "SteamChat Variables"
  34.  
  35. //Used in On Friend Add
  36. string welcomeMessage = "Welcome to a automated trading experience! I buy kits.Type 'Stock' to see my metal in stock. And 'owner' to see who my owner is.";
  37.  
  38. bool autoSendTradeRequest = false;
  39.  
  40. static int inviteTimerInterval = 2000;
  41. System.Timers.Timer inviteMsgTimer = new System.Timers.Timer(inviteTimerInterval);
  42.  
  43. //Used in Messages
  44. public int mode = 0;
  45. public const int HELPMODE = 0;
  46. public const int BUYMODE = 1;
  47. public const int SELLMODE = 2;
  48. public const int TESTMODE = 3;
  49. public const int ADMINMODE = 4;
  50. public bool passcodeMode = false;
  51.  
  52. string ownerInfoMessage = "Here's a link to my owner's profile http://steamcommunity.com/profiles/76561198024335163/ ";
  53.  
  54.  
  55. int priceSwitch = 0;
  56. int removalSwitch = 0;
  57. int currentItemDefindex;
  58. string currentItemName;
  59. double currentItemSellPrice;
  60. double currentItemBuyPrice;
  61.  
  62. #endregion
  63. #region "Trade Variables"
  64.  
  65. bool isThinking;
  66. bool buyHats;
  67. bool remove;
  68.  
  69. string tradeStartMessage = "Follow the instructions: Type 'buy' to start buying items. Type the name of an item to get its current price. Type 'stock' to see how much metal I have and 'price' to see the price of all of my items.";
  70. string tradeSuccessMessage = "Trade was successful! Please join our group http://steamcommunity.com/groups/MindlessTradeBots I frequently empty my friends list so it will make it easy to find me again.";
  71. int UserMetalAdded, UserScrapAdded, UserRecAdded, UserRefAdded, UserKeysAdded, BotKeysAdded, BotMetalAdded, BotScrapAdded, BotRecAdded, BotRefAdded, InventoryMetal, InventoryScrap, InventoryRec, InventoryRef, InventoryKeys, OverpayNumKeys, ExcessInScrap, PreviousKeys, WhileLoop, InvalidItem = 0;
  72.  
  73. double ExcessRefined = 0.0;
  74. decimal userOwed;
  75. bool overPay = false, tooMuchOffered = false, InGroupChat, TimerEnabled, HasRun, HasErrorRun, buyingItems, ChooseDonate, AskOverpay, IsOverpaying, HasCounted = false;
  76. SteamID currentSID;
  77.  
  78. List<Schema.Item> myOffer;
  79. List<Inventory.Item> userOffer;
  80.  
  81.  
  82.  
  83. #endregion
  84.  
  85. public CustomBot(Bot bot, SteamID sid) : base(bot, sid) { }
  86. #region "Bot_Operations"
  87. #region "SteamChat"
  88. public override bool OnFriendAdd()
  89. {
  90. Bot.log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " (" + OtherSID.ToString() + ") added me!");
  91. inviteMsgTimer.Interval = inviteTimerInterval;
  92. inviteMsgTimer.Elapsed += (sender, e) => OnInviteTimerElapsed(sender, e, EChatEntryType.ChatMsg);
  93. inviteMsgTimer.Enabled = true;
  94. return true;
  95. }
  96.  
  97. public override void OnLoginCompleted()
  98. {
  99. mySettings = new BotSettings();
  100. mySettings = null;
  101.  
  102. if (File.Exists(Directory.GetCurrentDirectory() + "//botSettings.xml"))
  103. {
  104. try
  105. {
  106. mySettings = new BotSettings();
  107. mySettings = mySettings.loadBotSettings();
  108. }
  109. catch
  110. {
  111. mySettings = null;
  112. }
  113. }
  114. }
  115.  
  116. public override void OnChatRoomMessage(SteamID chatID, SteamID sender, string message)
  117. {
  118. }
  119.  
  120. public override void OnFriendRemove() { }
  121.  
  122. public override void OnMessage(string message, EChatEntryType type)
  123. {
  124. if (currentSchema == null)
  125. {
  126. currentSchema = new Schema();
  127. currentSchema = Schema.FetchSchema(Bot.apiKey);
  128. }
  129.  
  130. message = message.ToLower();
  131. if (message == "reset all settings")
  132. {
  133. mySettings = new BotSettings();
  134. mySettings = mySettings.generateBotSettings("s3cr3t", 7, new List<BotSettings.Item>());
  135. }
  136. if (mySettings == null)
  137. {
  138. try
  139. {
  140. mySettings = new BotSettings();
  141. mySettings = mySettings.loadBotSettings();
  142. }
  143. catch
  144. {
  145. invalidSettings = true;
  146. if (IsAdmin)
  147. {
  148. sendChatMessage("ERROR: Something is wrong with the BotSettings file. I will not open trades until this is fixed");
  149. sendChatMessage("Generate valid settings with the command 'reset all settings'");
  150. }
  151. else
  152. {
  153. sendChatMessage("This bot is not yet configured to trade items. Contact my owner for more info!");
  154. }
  155. }
  156. }
  157.  
  158. if (message.Equals("self.restart"))
  159. {
  160. if (IsAdmin)
  161. {
  162. var filename = System.Reflection.Assembly.GetExecutingAssembly().Location;
  163. System.Diagnostics.Process.Start(filename);
  164. Environment.Exit(0);
  165. }
  166. }
  167. else if (message.Equals("exit") || message.Equals("main menu") || message.Equals("menu") || message.Equals("Exit") || message.Equals("Home") || message.Equals("home"))
  168. {
  169. mode = HELPMODE;
  170. passcodeMode = false;
  171. }
  172. if (passcodeMode) //switch for if you are trying to login as an admin
  173. {
  174. if (message.Equals(mySettings.adminPassword)) //If the password is valid go to admin mode
  175. {
  176. mode = ADMINMODE;
  177. passcodeMode = false;
  178. priceSwitch = 0;
  179. removalSwitch = 0;
  180. sendChatMessage("You are now in admin mode. Valid commands include: set price, set password [newpassword] [confirmnewpassword], remove item, set key [price of keys in scrap], remove friends, craft scrap, craft rec, craft ref, block craft");
  181. }
  182. else
  183. {
  184. sendChatMessage("Sorry that passcode was invalid, please either try again or use 'menu' to get back to the main menu");
  185. return;
  186. }
  187. }
  188. switch (mode)
  189. {
  190. case HELPMODE:
  191. switch (message)
  192. {
  193. case "admin":
  194. case "administrator":
  195. case "login":
  196. if (IsAdmin)
  197. {
  198. sendChatMessage("Enter your admin passcode");
  199. passcodeMode = true;
  200. }
  201. else
  202. {
  203. sendChatMessage("Sorry, this steamID has not been added to the administrators list");
  204. }
  205. break;
  206. case "purchase":
  207. case "buy":
  208. case "sell":
  209. case "sale":
  210. case "prices":
  211. mySettings = new BotSettings();
  212. mySettings = mySettings.loadBotSettings();
  213. priceResponse(STEAMCHAT);
  214. break;
  215. case "test":
  216. mySettings = new BotSettings();
  217. mySettings = mySettings.loadBotSettings();
  218. sendChatMessage("Entering secret test mode, do your shiz");
  219. mode = TESTMODE;
  220. break;
  221. case "owner":
  222. sendChatMessage(ownerInfoMessage);
  223. break;
  224. case "stock":
  225. case "inventory":
  226. case "stocks":
  227. stockResponse(STEAMCHAT);
  228. break;
  229. default:
  230. mode = HELPMODE;
  231. sendChatMessage("Send me a trade request to start trading");
  232. sendChatMessage("Valid chat commands are: stock, owner");
  233. if (IsAdmin)
  234. {
  235. sendChatMessage("Psst. I noticed you are a registered admin. Type 'login' to access admin features.");
  236. }
  237. break;
  238. }
  239. break;
  240. case ADMINMODE:
  241. adminResponse(message);
  242. break;
  243. case TESTMODE:
  244. testResponse(message);
  245. break;
  246. default:
  247. mode = HELPMODE;
  248. sendChatMessage("Send me a trade request to start trading");
  249. sendChatMessage("Valid chat commands are: stock, owner");
  250. if (IsAdmin)
  251. {
  252. sendChatMessage("Psst. I noticed you are a registered admin. Type 'login' to access admin features.");
  253. }
  254. break;
  255. }
  256. }
  257. #endregion
  258. #region "Trade"
  259. public override bool OnTradeRequest()
  260. {
  261. if (currentSchema == null)
  262. {
  263. currentSchema = new Schema();
  264. currentSchema = Schema.FetchSchema(Bot.apiKey);
  265. }
  266. if (mySettings == null)
  267. {
  268. try
  269. {
  270. mySettings = new BotSettings();
  271. mySettings = mySettings.loadBotSettings();
  272. }
  273. catch
  274. {
  275. invalidSettings = true;
  276. if (IsAdmin)
  277. {
  278. sendChatMessage("ERROR: Something is wrong with the BotSettings file. I will not open trades until this is fixed");
  279. sendChatMessage("Generate valid settings with the command 'reset all settings'");
  280. }
  281. else
  282. {
  283. sendChatMessage("This bot is not yet configured to trade items. Contact my owner for more info!");
  284. }
  285. return false;
  286. }
  287. }
  288.  
  289. return true;
  290. }
  291.  
  292. public override void OnTradeError(string error)
  293. {
  294. Bot.SteamFriends.SendChatMessage(OtherSID,
  295. EChatEntryType.ChatMsg,
  296. "Error: " + error + "."
  297. );
  298. Bot.log.Warn(error);
  299. if (!HasErrorRun)
  300. {
  301. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "It looks like there was a error! Please check here steam might be down http://steamgaug.es/ ! Here is a link to my owner if you continue to have problems http://steamcommunity.com/profiles/76561198024335163 Please go to my profile and see FAQ for help before adding my owner!");
  302. HasErrorRun = true;
  303. }
  304. Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
  305. }
  306.  
  307. public override void OnTradeTimeout()
  308. {
  309. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg,
  310. "Sorry, but you were either AFK or took too long and the trade was canceled.");
  311. Bot.log.Warn("User was kicked because he was AFK.");
  312. Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
  313. }
  314.  
  315. public override void OnTradeInit()
  316. {
  317. ReInit();
  318. TradeCountInventory(false);
  319.  
  320. Bot.SteamFriends.SetPersonaState(EPersonaState.Busy);
  321. Trade.SendMessage("Welcome to ALFREDO's Mindless BOT.");
  322. Trade.SendMessage("Add your kit and I will add metal automatically.");
  323. }
  324.  
  325. public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem)
  326. {
  327. if (IsAdmin && mode == ADMINMODE)
  328. {
  329. Trade.SendMessage("Warning - I don't pay for items if you are in admin mode!");
  330. return;
  331. }
  332. if (!ChooseDonate)
  333. {
  334. Trade.SendMessage("You have added an item!");
  335. if (inventoryItem.AppId == 440)
  336. {
  337. userOffer.Add(inventoryItem);
  338. }
  339. else
  340. {
  341. Trade.SendMessage("That's an item from the wrong game. Remove it or I'll end up treating it like a donation since I don't know what it is!");
  342. }
  343. doPayment(buyingItems);
  344. }
  345. }
  346.  
  347. public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) {
  348. if (IsAdmin && mode == ADMINMODE)
  349. {
  350. return;
  351. }
  352. isThinking = true;
  353. if (inventoryItem.AppId == 440){
  354. userOffer.Remove(inventoryItem);
  355. Trade.SendMessage("You have removed an item! Recalculating offer value");
  356. Bot.log.Warn("User removed " + schemaItem.ItemName);
  357. }
  358. doPayment(buyingItems);
  359.  
  360. isThinking = false;
  361. }
  362.  
  363. bool quantitySwitch = false;
  364. int tradeBuySwitch = 0;
  365. int tradeGame;
  366. int tradeCard;
  367. string orderedItem = null;
  368. int itemID = 0;
  369. Dictionary<int, string> orders = new Dictionary<int, string>();
  370. public override void OnTradeMessage(string message)
  371. {
  372. message = message.ToLower();
  373. if (IsAdmin && mode == ADMINMODE) //Admins can do whatever to the bot, but only when they have logged in to their password
  374. {
  375. switch (message)
  376. {
  377. case "metal":
  378. case "dump metal":
  379. case "get metal":
  380. dumpMetal(); //lets you collect all of the bot's metal
  381. break;
  382. }
  383. switch (message)
  384. {
  385. case "items":
  386. case "dump items":
  387. case "get items":
  388. dumpItems(); //lets you collect all of the bot's items (by items, it means things on your list, not random weapons and crap you might be storing in the bot's inventory
  389. break;
  390. default:
  391. Trade.SendMessage("You are currently in admin mode. Normal trade operations are suspended. Any trade you make will be acceptable to the bot, use 'dump metal' to get all of the bot's currency and 'dump hats' to get all of the bot's hats");
  392. break;
  393. }
  394. return;
  395. }
  396. if (message == "exit")
  397. {
  398. tradeBuySwitch = 0;
  399. }
  400. else if (tradeBuySwitch > 0)
  401. {
  402. switch(tradeBuySwitch)
  403. {
  404. case 1:
  405. itemID = getItemId(message, TRADECHAT);
  406. Bot.log.Info("User is searching for " + getItemName(itemID));
  407. if (itemID != null && itemID > 0)
  408. {
  409. Trade.SendMessage("How many of " + getItemName(itemID) + " do you want to buy?");
  410. tradeBuySwitch = tradeBuySwitch + 1;
  411. return;
  412. }
  413. else
  414. {
  415. Trade.SendMessage("Please check your spelling. Go to my profile for help if needed.");
  416. return;
  417. }
  418. case 2:
  419. if (!IsNumeric(message))
  420. {
  421. Trade.SendMessage("Please enter a whole number only.");
  422. return;
  423. }
  424. else
  425. {
  426. if (Trade.AddAllItemsByDefindex(itemID, (uint)Int32.Parse(message)) < (uint)Int32.Parse(message))
  427. {
  428. Trade.SendMessage("Added as many of that item as I can.");
  429. }
  430. Trade.SendMessage("Added " + evaluateMyOffer(myOffer) + " scrap worth of items.");
  431. Trade.SendMessage("Done adding the requested items. Request another item now.");
  432. tradeBuySwitch = 1;
  433. itemID = 0;
  434. }
  435. return;
  436.  
  437. }
  438. }
  439. else if (message == "prices")
  440. {
  441. priceResponse(TRADECHAT);
  442. }
  443. else if (message == "stock")
  444. {
  445. stockResponse(TRADECHAT);
  446. }
  447. else if (message == "donate")
  448. {
  449. Trade.SendMessage("Thanks for donating, just put up your items to donate!");
  450. foreach (var item in Trade.MyInventory.Items) //so people can't use donate mode to trade
  451. {
  452. Trade.RemoveItem(item.Id);
  453. }
  454. myOffer = new List<Schema.Item>();
  455. ChooseDonate = true;
  456. return;
  457. }
  458. else if (message.Equals("continue"))
  459. {
  460. overPay = true;
  461. Trade.SendMessage("You have just enabled overpaying - if you set yourself as ready to trade while offering too much I will treat it as a donation. To disable this function use 'reset trade'");
  462. return;
  463. }
  464. else if (message.Equals("reset trade"))
  465. {
  466. if (overPay)
  467. {
  468. Trade.SendMessage("You have disabled overpaying. If you would like to overpay use 'overpay on'");
  469. overPay = false;
  470. }
  471. foreach (var item in Trade.MyInventory.Items) //so people can't use donate mode to trade
  472. {
  473. Trade.RemoveItem(item.Id);
  474. }
  475. myOffer = new List<Schema.Item>();
  476. Trade.SendMessage("Trade has been reset");
  477. return;
  478. }
  479. else if (message.Equals("help"))
  480. {
  481. if (buyHats)
  482. {
  483. Trade.SendMessage("You are currently in buy mode. Type the names of items you want to buy separated by comas or on different lines for me to add them to trade! Type '/info' to get information about prices");
  484. }
  485. else
  486. {
  487. Trade.SendMessage("Type 'buy' to enter buy mode.");
  488. Trade.SendMessage("Type 'stock' to see what metal I have and type 'prices' to see all of my prices and hats. Type donate if you want to donate items.");
  489. }
  490.  
  491. }
  492. else if (message.Equals("buy"))
  493. {
  494. tradeBuySwitch++;
  495. Trade.SendMessage("You are now in buy mode. To exit buy mode type 'exit' (without the quotes).");
  496. Trade.SendMessage("Enter part of the item name you want to buy");
  497. }
  498.  
  499. }
  500. public override void OnTradeReady(bool ready)
  501. {
  502. Trade.Poll();
  503. if (!ready)
  504. {
  505. Trade.SetReady(false);
  506. }
  507. else
  508. {
  509. if (isThinking)
  510. {
  511. Trade.SendMessage("Sorry, I need to reprocess your trade, uncheck trade ready to continue");
  512. return;
  513. }
  514. Bot.log.Success("User is ready to trade!");
  515. if ((Validate() && !isThinking && evaluateUserOffer(userOffer) > 0) || (IsAdmin && mode == ADMINMODE) || (ChooseDonate)) //check that the trade is fair, only allow unfair trades if in admin mode
  516. {
  517. Trade.SetReady(true);
  518. }
  519. else if (tooMuchOffered)
  520. {
  521. Trade.SendMessage("You have offered too much, use 'continue' and resend your trade requesti if you want to overpay");
  522. }
  523. else //if somethings up just recheck everything
  524. {
  525. Trade.SendMessage("Sorry, something about this trade is not right let me recheck everything real quick");
  526. doPayment(buyingItems);
  527. }
  528. }
  529. }
  530.  
  531. public override void OnTradeAccept()
  532. {
  533. bool didSomething = false;
  534. if ((Validate()) || (IsAdmin && mode == ADMINMODE) || ChooseDonate)
  535. {
  536. bool success = Trade.AcceptTrade();
  537. if (success) //makes sure trades were successfull, steam's a bitch about this and will still pretend the trade failed on some large trades, but everyone will get paid
  538. {
  539. Log.Success("Trade was successful!");
  540. sendChatMessage(tradeSuccessMessage);
  541. Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
  542. }
  543. else
  544. {
  545. Log.Warn("Trade might have failed.");
  546. Bot.SteamFriends.SetPersonaState(EPersonaState.LookingToTrade);
  547. }
  548. }
  549. OnTradeClose();
  550. if (InventoryScrap < 9)
  551. {
  552. ulong[] smelt = new ulong[1];
  553. Bot.SetGamePlaying(440);
  554. Bot.GetInventory();
  555. Inventory myInventory = Bot.MyInventory;
  556. foreach (Inventory.Item item in myInventory.Items)
  557. {
  558. if (item.Defindex == 5001)
  559. {
  560. smelt[0] = item.Id;
  561. SteamBot.TF2GC.Crafting.CraftItems(Bot, smelt);
  562. didSomething = true;
  563. break;
  564. }
  565. }
  566. if (!didSomething)
  567. {
  568. foreach (Inventory.Item item in Bot.MyInventory.Items)
  569. {
  570. if (item.Defindex == 5002)
  571. {
  572. smelt[0] = item.Id;
  573. SteamBot.TF2GC.Crafting.CraftItems(Bot, smelt);
  574. didSomething = true;
  575. break;
  576. }
  577. }
  578. }
  579. }
  580. Bot.SetGamePlaying(0);
  581. }
  582.  
  583. public bool Validate()
  584. {
  585. List<Inventory.Item> hypoOffer = new List<Inventory.Item>(); //hypothetical offer, let's check everything they offered again as if it were a new offer
  586. if (InvalidItem > 0)
  587. {
  588. Trade.SendMessage("You have invalid items, please remove them to complete the trade, scroll up to see which items they were.");
  589. return false;
  590. }
  591. foreach (ulong id in Trade.OtherOfferedItems)
  592. {
  593. hypoOffer.Add(Trade.OtherInventory.GetItem(id));
  594. }
  595. if (!overPay)
  596. {
  597. if (evaluateMyOffer(myOffer) == evaluateUserOffer(userOffer)) //if we are paying the right amount
  598. {
  599. if (evaluateUserOffer(userOffer) == evaluateUserOffer(hypoOffer)) //and they are giving the right amount of stuff
  600. {
  601.  
  602. return true;
  603. }
  604. }
  605. else if (evaluateMyOffer(myOffer) < evaluateUserOffer(userOffer))
  606. {
  607. if (evaluateUserOffer(userOffer) == evaluateUserOffer(hypoOffer)) //and they are giving the right amount of stuff
  608. {
  609.  
  610. tooMuchOffered = true;
  611. }
  612. }
  613. }
  614. if (overPay)
  615. {
  616. if (evaluateMyOffer(myOffer) <= evaluateUserOffer(userOffer)) //if our offer is less than theirs but they are overpaying than who cares
  617. {
  618. if (evaluateUserOffer(userOffer) == evaluateUserOffer(hypoOffer))//but be sure they aren't lying
  619. {
  620.  
  621. return true;
  622. }
  623. }
  624. }
  625. return false;
  626. }
  627.  
  628.  
  629. #endregion
  630. #endregion
  631. #region "Payment Operations"
  632. public void ReInit()
  633. {
  634. UserMetalAdded = 0;
  635. UserRefAdded = 0;
  636. UserRecAdded = 0;
  637. UserScrapAdded = 0;
  638. UserKeysAdded = 0;
  639. BotKeysAdded = 0;
  640. BotMetalAdded = 0;
  641. BotRefAdded = 0;
  642. BotRecAdded = 0;
  643. BotScrapAdded = 0;
  644. ExcessRefined = 0.0;
  645. WhileLoop = 0;
  646. InvalidItem = 0;
  647. HasErrorRun = false;
  648. OverpayNumKeys = 0;
  649. PreviousKeys = 0;
  650. ExcessInScrap = 0;
  651. ChooseDonate = false;
  652. AskOverpay = false;
  653. IsOverpaying = false;
  654. HasCounted = false;
  655. currentSID = OtherSID;
  656. buyingItems = false;
  657. userOwed = 0;
  658. userOffer = new List<Inventory.Item>();
  659. myOffer = new List<Schema.Item>();
  660. isThinking = false;
  661. tooMuchOffered = false;
  662. buyHats = false;
  663. remove = false;
  664. Bot.GetInventory();
  665. Bot.GetOtherInventory(OtherSID);
  666. }
  667.  
  668. public void TradeCountInventory(bool message)
  669. {
  670. // Let's count our inventory
  671. Inventory.Item[] inventory = Trade.MyInventory.Items;
  672. InventoryMetal = 0;
  673. InventoryKeys = 0;
  674. InventoryRef = 0;
  675. InventoryRec = 0;
  676. InventoryScrap = 0;
  677. foreach (Inventory.Item item in inventory)
  678. {
  679. var schemaItem = Trade.CurrentSchema.GetItem(item.Defindex);
  680. if (item.Defindex == 5000)
  681. {
  682. InventoryMetal++;
  683. InventoryScrap++;
  684. }
  685. else if (item.Defindex == 5001)
  686. {
  687. InventoryMetal += 3;
  688. InventoryRec++;
  689. }
  690. else if (item.Defindex == 5002)
  691. {
  692. InventoryMetal += 9;
  693. InventoryRef++;
  694. }
  695. else if (item.Defindex == 5021)
  696. {
  697. InventoryKeys++;
  698. }
  699. }
  700. if (message)
  701. {
  702. double MetalToRef = (InventoryMetal / 9.0) - 0.01;
  703. string refined = string.Format("{0:N2}", MetalToRef);
  704. Trade.SendMessage("I have " + refined + " ref (" + InventoryRef + " ref, " + InventoryRec + " rec, and " + InventoryScrap + " scrap) and " + InventoryKeys + " key(s) in my backpack.");
  705. Bot.log.Success("Current stock: I have " + refined + " ref (" + InventoryRef + " ref, " + InventoryRec + " rec, and " + InventoryScrap + " scrap) and " + InventoryKeys + " key(s) in my backpack.");
  706. }
  707. HasCounted = true;
  708. }
  709. public double evaluateMyOffer(List<Schema.Item> offer)
  710. {
  711. double totalValue = 0;
  712. if (mySettings == null)
  713. {
  714. mySettings.loadBotSettings();
  715. }
  716. foreach (ulong itemID in Trade.MyOfferedItems)
  717. {
  718. Inventory.Item item = Bot.MyInventory.GetItem(itemID);
  719. bool gotPrice = false;
  720. if (item.Defindex == 5021)
  721. {
  722. totalValue = totalValue + mySettings.scrapPerKey;
  723. gotPrice = true;
  724. }
  725. else if (item.Defindex == 5000)
  726. {
  727. totalValue = totalValue + 1;
  728. gotPrice = true;
  729. }
  730. else if (item.Defindex == 5001)
  731. {
  732. totalValue = totalValue + 3;
  733. gotPrice = true;
  734. }
  735. else if (item.Defindex == 5002)
  736. {
  737. totalValue = totalValue + 9;
  738. gotPrice = true;
  739. }
  740. else
  741. {
  742. foreach (BotSettings.Item price in mySettings.items)
  743. {
  744. if (price.defindex == item.Defindex)
  745. {
  746. gotPrice = true;
  747. totalValue = totalValue + price.sellPrice;
  748. }
  749. }
  750. }
  751. if (gotPrice == false)
  752. {
  753. if (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && (currentSchema.GetItem(item.Defindex).CraftClass == "weapon" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
  754. {
  755. totalValue = totalValue + .5;
  756. gotPrice = true;
  757. }
  758. else
  759. {
  760. Bot.log.Info("Added an Item I don't recognize");
  761. }
  762. // Trade.SendMessage("I will not pay for " + item.Name + " right now. Either remove or donate it.");
  763. }
  764. }
  765.  
  766. Bot.log.Info("Eavluate: My offer is worth " + totalValue + " scrap");
  767. return totalValue;
  768. }
  769.  
  770. public double evaluateUserOffer(List<Inventory.Item> offer)
  771. {
  772. InvalidItem = 0;
  773. double totalValue = 0;
  774. if (Bot.OtherInventory == null)
  775. {
  776. Bot.GetOtherInventory(OtherSID);
  777. }
  778. List<string> invalidItemName = new List<string>();
  779. foreach (ulong itemID in Trade.OtherOfferedItems)
  780. {
  781. Inventory.Item item = Bot.OtherInventory.GetItem(itemID);
  782. if (item.AppId == 440)
  783. {
  784. bool gotPrice = false;
  785. if (item.Defindex == 5021 && mySettings.scrapPerKey > 0)
  786. {
  787. totalValue = totalValue + mySettings.scrapPerKey;
  788. gotPrice = true;
  789. }
  790. if (item.Defindex == 5000)
  791. {
  792. totalValue = totalValue + 1;
  793. gotPrice = true;
  794. }
  795. if (item.Defindex == 5001)
  796. {
  797. totalValue = totalValue + 3;
  798. gotPrice = true;
  799. }
  800. if (item.Defindex == 5002)
  801. {
  802. totalValue = totalValue + 9;
  803. gotPrice = true;
  804. }
  805. else
  806. {
  807. try
  808. {
  809. if (!tooMuch(item.Defindex)) //this was the line I used to use to check for craft hats
  810. if (!isGifted(item)) //and it hasn't been gifted
  811. {
  812. foreach (BotSettings.Item match in mySettings.items)
  813. {
  814. if (match.defindex == item.Defindex)
  815. {
  816. if (!item.IsNotCraftable && currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && (currentSchema.GetItem(item.Defindex).CraftClass == "weapon" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
  817. {
  818. totalValue = totalValue + match.buyPrice;
  819. gotPrice = true;
  820. }
  821. else if (!(currentSchema.GetItem(item.Defindex).CraftClass == "weapon" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
  822. {
  823. totalValue = totalValue + match.buyPrice;
  824. gotPrice = true;
  825. }
  826. else
  827. {
  828. Trade.SendMessage("I only accept craftable items!");
  829. }
  830. }
  831.  
  832. }
  833. }
  834. else
  835. {
  836. Trade.SendMessage("I don't accept gifted items.");
  837. }
  838. }
  839. catch
  840. {
  841. }
  842. if (gotPrice == false)
  843. {
  844. if ((!item.IsNotCraftable && !isGifted(item)) && (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).ItemSlot == "melee" || currentSchema.GetItem(item.Defindex).ItemSlot == "primary" || currentSchema.GetItem(item.Defindex).ItemSlot == "secondary" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
  845. {
  846. totalValue = totalValue + .5;
  847. gotPrice = true;
  848. }
  849. else
  850. {
  851. InvalidItem++;
  852. invalidItemName.Add(currentSchema.GetItem(item.Defindex).Name);
  853. }
  854. }
  855. }
  856. }
  857. else
  858. {
  859. Trade.SendMessage("You have items from a game which is not tf2. Please remove them.");
  860. }
  861. }
  862. if (invalidItemName.Count == 1)
  863. {
  864. Trade.SendMessage("I am not buying " + invalidItemName[0] + " right now, please remove it or I will treat it as a donation.");
  865. }
  866. else if (invalidItemName.Count > 1)
  867. {
  868. Trade.SendMessage("I am not buying the following items. Please remove them or I will treat them as donations:");
  869. foreach (string itemName in invalidItemName)
  870. {
  871. Trade.SendMessage("...." + itemName);
  872. }
  873. }
  874. Bot.log.Info("User has made an offer worth " + totalValue + " scrap");
  875. return totalValue;
  876. }
  877.  
  878. public void doPayment(bool buyingItems)
  879. {
  880. int loopCount = 0;
  881. TradeCountInventory(false);
  882. double userOfferValue = evaluateUserOffer(userOffer);
  883. double myOfferValue = evaluateMyOffer(myOffer);
  884. Log.Info("My current offer value is " + myOfferValue + " scrap.");
  885. //actually pay
  886. if (myOfferValue > userOfferValue)
  887. {
  888. bool DoneAddingMetal = false;
  889. while (!DoneAddingMetal)
  890. {
  891. double BotValueAdded = evaluateMyOffer(myOffer);
  892. if (BotValueAdded - mySettings.scrapPerKey >= userOfferValue && Trade.RemoveItemByDefindex(5021))
  893. {
  894. Log.Warn("I removed a key");
  895. BotValueAdded = BotValueAdded - mySettings.scrapPerKey;
  896. myOffer.Remove(currentSchema.GetItem(5021));
  897. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  898. }
  899. else if (BotValueAdded - 9 >= userOfferValue && Trade.RemoveItemByDefindex(5002))
  900. {
  901. Log.Warn("I removed a ref");
  902. BotValueAdded = BotValueAdded - 9;
  903. myOffer.Remove(currentSchema.GetItem(5002));
  904. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  905. }
  906. else if (BotValueAdded - 3 >= userOfferValue && Trade.RemoveItemByDefindex(5001))
  907. {
  908. Log.Warn("I removed a rec");
  909. BotValueAdded = BotValueAdded - 3;
  910. myOffer.Remove(currentSchema.GetItem(5001));
  911. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  912. }
  913. else if (BotValueAdded -1 >= userOfferValue && Trade.RemoveItemByDefindex(5000))
  914. {
  915. Log.Warn("I removed a scrap");
  916. BotValueAdded = BotValueAdded - 1;
  917. myOffer.Remove(currentSchema.GetItem(5000));
  918. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  919. }
  920. else if (BotValueAdded - .5 >= userOfferValue && removeWeapon())
  921. {
  922. Log.Warn("I removed a weapon");
  923. BotValueAdded = BotValueAdded - .5;
  924. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  925. }
  926. if (BotValueAdded == userOfferValue)
  927. {
  928. consolidateOffer();
  929. Trade.SendMessage("Successfully matched offer value");
  930. Bot.log.Info("My offer is now worth " + BotValueAdded);
  931. return;
  932. }
  933. loopCount++;
  934. if (loopCount > 40)
  935. {
  936. if (BotValueAdded - .5 <= userOfferValue && removeWeapon())
  937. {
  938. Log.Warn("I removed a weapon");
  939. BotValueAdded = BotValueAdded - .5;
  940. Bot.log.Info("My offer is now worth " + BotValueAdded);
  941. }
  942. else if (BotValueAdded - 1 <= userOfferValue && Trade.RemoveItemByDefindex(5000))
  943. {
  944. Log.Warn("I removed a scrap");
  945. BotValueAdded = BotValueAdded - 1;
  946. myOffer.Remove(currentSchema.GetItem(5000));
  947. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  948. break;
  949. }
  950. else if (BotValueAdded - 3 <= userOfferValue && Trade.RemoveItemByDefindex(5001))
  951. {
  952. Log.Warn("I removed a rec");
  953. BotValueAdded = BotValueAdded - 3;
  954. myOffer.Remove(currentSchema.GetItem(5001));
  955. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  956. break;
  957. }
  958. else if (BotValueAdded - 9 <= userOfferValue && Trade.RemoveItemByDefindex(5002))
  959. {
  960. Log.Warn("I removed a ref");
  961. BotValueAdded = BotValueAdded - 9;
  962. myOffer.Remove(currentSchema.GetItem(5002));
  963. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  964. break;
  965. }
  966. else if (BotValueAdded - mySettings.scrapPerKey <= userOfferValue && Trade.RemoveItemByDefindex(5021))
  967. {
  968. Log.Warn("I removed a key");
  969. BotValueAdded = BotValueAdded - mySettings.scrapPerKey;
  970. myOffer.Remove(currentSchema.GetItem(5021));
  971. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  972. break;
  973. }
  974. }
  975. if (loopCount > 80)
  976. {
  977.  
  978. break;
  979. }
  980. }
  981. }
  982. myOfferValue = evaluateMyOffer(myOffer);
  983. if(myOfferValue < userOfferValue)
  984. {
  985. removeCurrency();
  986. bool DoneAddingMetal = false;
  987. while(!DoneAddingMetal)
  988. {
  989. double BotValueAdded = evaluateMyOffer(myOffer);
  990. if((mySettings.scrapPerKey > 0) && BotValueAdded + mySettings.scrapPerKey <= userOfferValue && Trade.AddItemByDefindex(5021)){
  991. Log.Warn("I added a key");
  992. BotValueAdded = BotValueAdded + mySettings.scrapPerKey;
  993. myOffer.Add(currentSchema.GetItem(5021));
  994. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  995. }
  996. else if(BotValueAdded + 9 <= userOfferValue && Trade.AddItemByDefindex(5002)){
  997. Log.Warn("I added a ref");
  998. BotValueAdded = BotValueAdded + 9;
  999. myOffer.Add(currentSchema.GetItem(5002));
  1000. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  1001. }
  1002. else if(BotValueAdded + 3 <= userOfferValue && Trade.AddItemByDefindex(5001)){
  1003. Log.Warn("I add a rec");
  1004.  
  1005. BotValueAdded = BotValueAdded + 3;
  1006. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  1007. myOffer.Add(currentSchema.GetItem(5001));
  1008. }
  1009. else if(BotValueAdded + 1 <= userOfferValue && Trade.AddItemByDefindex(5000)){
  1010. Log.Warn("I added a scrap");
  1011. BotValueAdded = BotValueAdded + 1;
  1012. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  1013. myOffer.Add(currentSchema.GetItem(5000));
  1014. }
  1015. else if (BotValueAdded + .5 <= userOfferValue && addWeapon())
  1016. {
  1017. Log.Warn("I added a weapon");
  1018. BotValueAdded = BotValueAdded + .5;
  1019. }
  1020. if(BotValueAdded == userOfferValue){
  1021. Trade.SendMessage("Successfully matched offer value");
  1022. Bot.log.Info("MY offer is now worth " + BotValueAdded);
  1023.  
  1024. return;
  1025. }
  1026. loopCount++;
  1027. if(loopCount > 40){
  1028. Trade.SendMessage("Sorry, I cannot match that offer exactly, please remove some items");
  1029. return;
  1030. }
  1031. }
  1032. }
  1033.  
  1034. }
  1035.  
  1036. public bool addWeapon()
  1037. {
  1038. foreach (Inventory.Item item in Bot.MyInventory.Items)
  1039. {
  1040. if (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && ((currentSchema.GetItem(item.Defindex).CraftClass == "weapon") || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
  1041. {
  1042. bool product = false;
  1043. foreach (BotSettings.Item name in mySettings.items)
  1044. {
  1045. if (name.defindex == item.Defindex)
  1046. {
  1047. product = true;
  1048. }
  1049. }
  1050. if (!product && Trade.AddItemByDefindex(item.Defindex))
  1051. {
  1052. return true;
  1053. }
  1054. }
  1055. }
  1056. return false;
  1057. }
  1058. public bool removeWeapon()
  1059. {
  1060. foreach (ulong itemID in Trade.MyOfferedSteamItems)
  1061. {
  1062. Schema.Item item = currentSchema.GetItem(Bot.MyInventory.GetItem(itemID).Defindex);
  1063. if (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && ((currentSchema.GetItem(item.Defindex).CraftClass == "weapon") || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
  1064. {
  1065. bool product = false;
  1066. foreach (BotSettings.Item name in mySettings.items)
  1067. {
  1068. if (name.defindex == item.Defindex)
  1069. {
  1070. product = true;
  1071. }
  1072. }
  1073. if (!product && Trade.RemoveItemByDefindex(item.Defindex))
  1074. {
  1075. return true;
  1076. }
  1077. }
  1078. }
  1079. return false;
  1080. }
  1081.  
  1082. public void removeCurrency()
  1083. {
  1084. Trade.RemoveAllItemsByDefindex(5000);
  1085. Trade.RemoveAllItemsByDefindex(5001);
  1086. Trade.RemoveAllItemsByDefindex(5002);
  1087. List<int> weaponDefindexes = new List<int>();
  1088. foreach (ulong itemID in Trade.MyOfferedSteamItems)
  1089. {
  1090. Schema.Item item = currentSchema.GetItem(Bot.MyInventory.GetItem(itemID).Defindex);
  1091. bool product = false;
  1092. foreach (BotSettings.Item name in mySettings.items)
  1093. {
  1094. if (name.defindex == item.Defindex)
  1095. {
  1096. product = true;
  1097. }
  1098. }
  1099. if (!product && Trade.AddItemByDefindex(item.Defindex))
  1100. {
  1101. if (currentSchema.GetItem(item.Defindex).ItemSlot != null && currentSchema.GetItem(item.Defindex).CraftClass != null && (currentSchema.GetItem(item.Defindex).CraftClass == "weapon" || currentSchema.GetItem(item.Defindex).ItemSlot == "pda"))
  1102. {
  1103. weaponDefindexes.Add(item.Defindex);
  1104. }
  1105. }
  1106.  
  1107. }
  1108. foreach (int defindex in weaponDefindexes)
  1109. {
  1110. Trade.RemoveAllItemsByDefindex(defindex);
  1111. }
  1112. }
  1113. public void consolidateOffer()
  1114. {
  1115. }
  1116. public bool isGifted(Inventory.Item item)
  1117. {
  1118.  
  1119. bool isGifted = false;
  1120. try
  1121. {
  1122. foreach (Inventory.ItemAttribute attribute in item.Attributes)
  1123. {
  1124. if (attribute.Defindex == 186)
  1125. {
  1126. isGifted = true;
  1127. }
  1128. }
  1129. }
  1130. catch
  1131. {
  1132. isGifted = false;
  1133. }
  1134. return isGifted;
  1135. }
  1136.  
  1137. public bool tooMuch(int defindex)
  1138. {
  1139. foreach (BotSettings.Item item in mySettings.items)
  1140. {
  1141.  
  1142. if (item.defindex == defindex)
  1143. {
  1144. if (Bot.MyInventory == null)
  1145. {
  1146. Bot.GetInventory();
  1147. }
  1148. if (Bot.MyInventory.GetItemsByDefindex(defindex).Count >= item.maxAmount || item.maxAmount == 0)
  1149. {
  1150. return true;
  1151. }
  1152. }
  1153. }
  1154. return false;
  1155. }
  1156. #endregion
  1157. #region "Message Handling"
  1158.  
  1159. #region "Universal"
  1160. //Sends a message via steam chat
  1161.  
  1162. public void sendChatMessage(string message)
  1163. {
  1164. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, message);
  1165. }
  1166.  
  1167. public bool IsNumeric(System.Object Expression)
  1168. {
  1169. if (Expression == null || Expression is DateTime)
  1170. return false;
  1171.  
  1172. if (Expression is Int16 || Expression is Int32 || Expression is Int64 || (((Expression is Double)) && (mode == ADMINMODE))/*|| Expression is Decimal|| Expression is Single /|| Expression is Double || Expression is Boolean*/)
  1173. return true;
  1174.  
  1175. try
  1176. {
  1177. if (Expression is string)
  1178. Int64.Parse(Expression as string);
  1179. else
  1180. Int64.Parse(Expression.ToString());
  1181. return true;
  1182. }
  1183. catch { } // just dismiss errors but return false
  1184. return false;
  1185. }
  1186.  
  1187. //Returns the number of instances of a particular item contained in a backpack with a particular item ID
  1188. public Int32[] getNumericItemInfo(string message, EChatEntryType type)
  1189. {
  1190. Int32[] itemCount = new int[3];
  1191. Int32 usualCount = 0;
  1192. Bot.GetInventory();
  1193. foreach (Inventory.Item item in Bot.MyInventory.Items)
  1194. {
  1195. if (item.Defindex == Int32.Parse(message))
  1196. {
  1197. itemCount[0] = usualCount + 1;
  1198. }
  1199. }
  1200. return itemCount;
  1201. }
  1202.  
  1203. public int getItemId(string message, int messageMode)
  1204. {
  1205. if (mode == ADMINMODE)
  1206. {
  1207. try
  1208. {
  1209. List<int> itemIds = new List<int>();
  1210. int itemId;
  1211. message = message.ToLower();
  1212. Bot.GetInventory();
  1213. Schema currentSchema = Schema.FetchSchema(Bot.apiKey);
  1214.  
  1215. foreach (Schema.Item item in currentSchema.GetItems())
  1216. {
  1217. string itemname = item.Name.ToLower();
  1218. if (itemname.Contains(message))
  1219. {
  1220. itemId = item.Defindex;
  1221. itemIds.Add(itemId);
  1222. }
  1223. if (itemname.Equals(message))
  1224. {
  1225. return item.Defindex;
  1226.  
  1227. }
  1228. }
  1229. if (itemIds.Count() > 1)
  1230. {
  1231. if (messageMode == STEAMCHAT)
  1232. {
  1233. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Found multiple matches for " + message + ", be more specific");
  1234. }
  1235. else
  1236. {
  1237. Trade.SendMessage("Found multiple matches for " + message + ", be more specific");
  1238. }
  1239. return -1;
  1240. }
  1241. else
  1242. {
  1243. try
  1244. {
  1245. return itemIds[0];
  1246. }
  1247. catch
  1248. {
  1249. if (messageMode == STEAMCHAT)
  1250. {
  1251. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Can not find a match for " + message + ", check your spelling? Go to my profile for help if needed.");
  1252. }
  1253. else
  1254. {
  1255. Trade.SendMessage("Can not find a match for " + message + ", check your spelling? Go to my profile for help if needed. ");
  1256. }
  1257. return -1;
  1258. }
  1259. }
  1260. }
  1261. catch (NullReferenceException ex)
  1262. {
  1263.  
  1264. List<int> itemIds = new List<int>();
  1265. return -1;
  1266. }
  1267. }
  1268. else
  1269. {
  1270. try
  1271. {
  1272. List<int> itemIds = new List<int>();
  1273. int itemId;
  1274. message = message.ToLower();
  1275. Bot.GetInventory();
  1276. if (mySettings == null)
  1277. {
  1278. mySettings.loadBotSettings();
  1279. }
  1280. foreach (BotSettings.Item itemSetting in mySettings.items)
  1281. {
  1282. string itemname = itemSetting.itemName.ToLower();
  1283. if (itemname.Contains(message))
  1284. {
  1285. itemId = itemSetting.defindex;
  1286. itemIds.Add(itemId);
  1287. }
  1288. if (itemname.Equals(message))
  1289. {
  1290. return itemSetting.defindex;
  1291.  
  1292. }
  1293. }
  1294. if (itemIds.Count() > 1)
  1295. {
  1296. if (messageMode == STEAMCHAT)
  1297. {
  1298. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Found multiple matches for " + message + ", be more specific");
  1299. }
  1300. else
  1301. {
  1302. Trade.SendMessage("Found multiple matches for " + message + ", be more specific");
  1303. }
  1304. return -1;
  1305. }
  1306. else
  1307. {
  1308. try
  1309. {
  1310. return itemIds[0];
  1311. }
  1312. catch
  1313. {
  1314. if (messageMode == STEAMCHAT)
  1315. {
  1316. Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Can not find a match for " + message + ", check your spelling? Go to my profile for help if needed. ");
  1317. }
  1318. else
  1319. {
  1320. Trade.SendMessage("Can not find a match for " + message + ", check your spelling? Go to my profile for help if needed.");
  1321. }
  1322. return -1;
  1323. }
  1324. }
  1325. }
  1326. catch (NullReferenceException ex)
  1327. {
  1328.  
  1329. List<int> itemIds = new List<int>();
  1330. return -1;
  1331. }
  1332. }
  1333. }
  1334.  
  1335. //gets the name of an item from its defindex
  1336. public string getItemName(int itemId)
  1337. {
  1338. if (mode == ADMINMODE)
  1339. {
  1340. try
  1341. {
  1342. Schema currentSchema = Schema.FetchSchema(Bot.apiKey);
  1343. foreach (Schema.Item item in currentSchema.GetItems())
  1344. {
  1345. if ((Int32)item.Defindex == itemId)
  1346. {
  1347. return item.Name;
  1348. }
  1349. }
  1350. return "Error in finding name 2";
  1351. }
  1352. catch
  1353. {
  1354. return "Error in finding name 3";
  1355. }
  1356. }
  1357. else{
  1358. try
  1359. {
  1360. if (mySettings == null)
  1361. {
  1362. mySettings = new BotSettings();
  1363. mySettings.loadBotSettings();
  1364. }
  1365.  
  1366. foreach (BotSettings.Item item in mySettings.items)
  1367. {
  1368. if ((Int32)item.defindex == itemId)
  1369. {
  1370. return item.itemName;
  1371. }
  1372. }
  1373. return "Error in finding name 2";
  1374.  
  1375. }
  1376. catch
  1377. {
  1378. return "Error in finding name 3";
  1379. }
  1380. }
  1381. }
  1382.  
  1383. public void priceResponse(int messageMode)
  1384. {
  1385. foreach (BotSettings.Item itemSetting in mySettings.items)
  1386. {
  1387. decimal SitemPrice = -999999999;
  1388. decimal BitemPrice = -999999999;
  1389. int itemCount = 0;
  1390. int thisItem;
  1391. thisItem = itemSetting.defindex;
  1392. Bot.GetInventory();
  1393. foreach (Inventory.Item item in Bot.MyInventory.Items)
  1394. {
  1395. if (item.Defindex == thisItem)
  1396. {
  1397. itemCount++;
  1398. }
  1399. }
  1400. SitemPrice = (decimal)itemSetting.sellPrice;
  1401. BitemPrice = (decimal)itemSetting.buyPrice;
  1402. SitemPrice = Math.Truncate(100 * (SitemPrice / 9)) / 100;
  1403. BitemPrice = Math.Truncate(100 * (BitemPrice / 9)) / 100;
  1404.  
  1405. if (SitemPrice == -999999999)
  1406. {
  1407. }
  1408. else
  1409. {
  1410. if (messageMode == STEAMCHAT)
  1411. {
  1412. sendChatMessage("I will buy " + getItemName(thisItem) + "s " + " at " + BitemPrice + " ref each.");
  1413. sendChatMessage("I have " + itemCount + " " + getItemName(thisItem) + "s " + " which I will sell at " + SitemPrice + " ref each.");
  1414. }
  1415. if(messageMode == TRADECHAT){
  1416. Trade.SendMessage("I will buy " + getItemName(thisItem) + "s " + " at " + BitemPrice + " ref each.");
  1417. Trade.SendMessage("I have " + itemCount + " " + getItemName(thisItem) + "s " + " which I will sell at " + SitemPrice + " ref each.");
  1418. }
  1419. }
  1420. }
  1421. }
  1422.  
  1423. public void stockResponse(int messageMode)
  1424. {
  1425. int keyCount = 0;
  1426. int refCount = 0;
  1427. int recCount = 0;
  1428. int scrapCount = 0;
  1429. int metalCount = 0;
  1430. Bot.GetInventory();
  1431. foreach(Inventory.Item item in Bot.MyInventory.Items)
  1432. {
  1433. if (item.Defindex == 5000)
  1434. {
  1435. scrapCount++;
  1436. metalCount++;
  1437. }
  1438. else if(item.Defindex == 5001){
  1439. recCount++;
  1440. metalCount = metalCount + 3;
  1441. }
  1442. else if(item.Defindex == 5002){
  1443. refCount++;
  1444. metalCount = metalCount + 9;
  1445. }
  1446. else if (item.Defindex == 5021)
  1447. {
  1448. keyCount++;
  1449. }
  1450. }
  1451. double MetalToRef = (metalCount / 9.0) - 0.01;
  1452. string refined = string.Format("{0:N2}", MetalToRef);
  1453. if (messageMode == STEAMCHAT)
  1454. {
  1455. sendChatMessage("I have " + refined + " ref (" + refCount + " ref, " + recCount + " rec, and " + scrapCount + " scrap) and " + keyCount + " key(s) in my backpack.");
  1456. }
  1457. else
  1458. {
  1459. Trade.SendMessage("I have " + refined + " ref (" + refCount + " ref, " + recCount + " rec, and " + scrapCount + " scrap) and " + keyCount + " key(s) in my backpack.");
  1460. }
  1461. }
  1462.  
  1463.  
  1464. public void dumpMetal()
  1465. {
  1466. foreach (var item in Trade.MyInventory.Items)
  1467. {
  1468. if ((item.Defindex == 5021 || item.Defindex == 5000 || item.Defindex == 5001 || item.Defindex == 5002 || item.Defindex == 5003))
  1469. {
  1470. Trade.AddItemByDefindex(item.Defindex);
  1471. }
  1472. }
  1473. }
  1474.  
  1475.  
  1476. public void dumpItems()
  1477. {
  1478. foreach (var item in Trade.MyInventory.Items)
  1479. {
  1480. try
  1481. {
  1482. if (Trade.CurrentSchema.GetItem(item.Defindex).ItemSlot.Equals("head") || Trade.CurrentSchema.GetItem(item.Defindex).ItemSlot.Equals("misc"))
  1483. {
  1484. Trade.AddItemByDefindex(item.Defindex);
  1485. }
  1486. }
  1487. catch { }
  1488. }
  1489. }
  1490.  
  1491. #endregion
  1492.  
  1493. #region "Add Friend"
  1494.  
  1495. private void OnInviteTimerElapsed(object source, ElapsedEventArgs e, EChatEntryType type)
  1496. {
  1497. sendChatMessage(welcomeMessage);
  1498. Bot.log.Success("Sent welcome message.");
  1499.  
  1500. if (autoSendTradeRequest)
  1501. {
  1502. Bot.OpenTrade(OtherSID);
  1503. }
  1504.  
  1505. Bot.log.Success("Sent trade invite.");
  1506. inviteMsgTimer.Enabled = false;
  1507. inviteMsgTimer.Stop();
  1508. }
  1509.  
  1510. #endregion
  1511.  
  1512. #region "Steam Message"
  1513.  
  1514. public void testResponse(string message) //If you ever want to test code do it here
  1515. {
  1516. return;
  1517. }
  1518.  
  1519. bool craftSwitch = false;
  1520. bool refSwitch = false;
  1521. bool recSwitch = false;
  1522. bool blockSwitch = false;
  1523. int currentItemMax = 0;
  1524. public void adminResponse(string message)
  1525. {
  1526. message = message.ToLower();
  1527. if (message.Equals("set price") || priceSwitch > 0)
  1528. {
  1529. switch (priceSwitch)
  1530. {
  1531. case 0:
  1532. sendChatMessage("Enter the defindex or name of the item you are trying to price. Type 'exit' to cancel");
  1533. priceSwitch++;
  1534. break;
  1535. case 1:
  1536. if (IsNumeric(message))
  1537. {
  1538. currentItemDefindex = Int32.Parse(message);
  1539. currentItemName = getItemName(currentItemDefindex);
  1540. if (currentItemName == null)
  1541. {
  1542. sendChatMessage("Could not find an item with that defindex, please try again or use 'restart' to return to the main admin menu");
  1543. return;
  1544. }
  1545. }
  1546. else{
  1547. currentItemDefindex = getItemId(message, STEAMCHAT);
  1548. if (currentItemDefindex == -1)
  1549. {
  1550. sendChatMessage("Couldn't find a specific match for that item");
  1551. return;
  1552. }
  1553. currentItemName = getItemName(currentItemDefindex);
  1554. }
  1555. sendChatMessage("Now enter the price in scrap that you would like the bot to pay for that item.");
  1556. priceSwitch++;
  1557. return;
  1558. case 2:
  1559. try
  1560. {
  1561. currentItemBuyPrice = Int32.Parse(message);
  1562. }
  1563. catch
  1564. {
  1565. try {
  1566. currentItemBuyPrice = Double.Parse(message);
  1567. }
  1568. catch
  1569. {
  1570. sendChatMessage("Something is wrong with that price, please try again.");
  1571. return;
  1572. }
  1573. }
  1574. sendChatMessage("Finally enter the price in scrap at which you want to sell the item.");
  1575. priceSwitch++;
  1576. return;
  1577. case 3:
  1578. try
  1579. {
  1580. currentItemSellPrice = Int32.Parse(message);
  1581. }
  1582. catch
  1583. {
  1584. try {
  1585. currentItemSellPrice = Double.Parse(message);
  1586. }
  1587. catch
  1588. {
  1589. sendChatMessage("Something is wrong with that price, please try again.");
  1590. return;
  1591. }
  1592. }
  1593. sendChatMessage("What is the maximum number of that item you want in your backpack, type 0 to allow infinite");
  1594. priceSwitch++;
  1595. return;
  1596. case 4:
  1597. try
  1598. {
  1599. currentItemMax = Int32.Parse(message);
  1600. }
  1601. catch
  1602. {
  1603. sendChatMessage("Sorry, please only type positive whole integers");
  1604. }
  1605. sendChatMessage("I have you wanting to add an entry for " + currentItemName + " at a buy price of " + currentItemBuyPrice + " and a sell price of " + currentItemSellPrice + " and a limit of " + currentItemMax +". If this is correct type 'yes' otherwise type 'no'");
  1606. priceSwitch++;
  1607. return;
  1608. case 5:
  1609. if (message.ToLower().Equals("yes"))
  1610. {
  1611. List<BotSettings.Item> copy = new List<BotSettings.Item>();
  1612. copy = mySettings.items.ToList<BotSettings.Item>();
  1613. foreach (BotSettings.Item item in copy)
  1614. {
  1615. if (item.defindex == currentItemDefindex)
  1616. {
  1617. sendChatMessage("Previous Entry Removed");
  1618. mySettings.items.Remove(item);
  1619. }
  1620. }
  1621. mySettings.addItem(currentItemName, currentItemDefindex, currentItemBuyPrice, currentItemSellPrice, currentItemMax);
  1622. priceSwitch = 0;
  1623. sendChatMessage("Price set.");
  1624. return;
  1625. }
  1626. else if (message.ToLower().Equals("no"))
  1627. {
  1628. sendChatMessage("Use 'add item' to start over");
  1629. priceSwitch = 0;
  1630. return;
  1631. }
  1632. else
  1633. {
  1634. sendChatMessage("Please respond with either 'yes' or 'no'");
  1635. }
  1636. break;
  1637. default:
  1638. priceSwitch = 0;
  1639. break;
  1640. }
  1641. }
  1642. else if (message.Contains("set password"))
  1643. {
  1644. parsePassword(message);
  1645. mySettings.saveBotSettings(mySettings);
  1646. }
  1647. else if (message.Equals("remove friends"))
  1648. {
  1649. int i = 0;
  1650. while (true)
  1651. {
  1652. try
  1653. {
  1654. SteamID toRemove = Bot.SteamFriends.GetFriendByIndex(i);
  1655. if (toRemove == OtherSID || Bot.Admins.Contains(toRemove.ConvertToUInt64()))
  1656. {
  1657. }
  1658. else
  1659. {
  1660. Bot.SteamFriends.RemoveFriend(toRemove);
  1661. if (toRemove.ConvertToUInt64() != 0)
  1662. {
  1663. Bot.log.Info("I removed " + toRemove.ConvertToUInt64() + " from my friend list");
  1664. }
  1665. }
  1666. i++;
  1667. }
  1668. catch { i++; }
  1669. if (i > 250)
  1670. {
  1671. break;
  1672. }
  1673. }
  1674. sendChatMessage("All non-admin steam friends removed");
  1675. Bot.log.Info("Current friend count " + Bot.SteamFriends.GetFriendCount());
  1676. }
  1677. else if (message.Contains("craft scrap") || craftSwitch)
  1678. {
  1679. if (craftSwitch)
  1680. {
  1681. if (IsNumeric(message))
  1682. {
  1683. int weaponsCrafted = Bot.craftAllWeapons(Int32.Parse(message));
  1684. sendChatMessage("I was able to craft a total of: " + weaponsCrafted + " scrap.");
  1685. craftSwitch = false;
  1686. }
  1687. else
  1688. {
  1689. sendChatMessage("Type the maximum number of scrap you want to craft");
  1690. }
  1691. }
  1692. else
  1693. {
  1694. sendChatMessage("Type the maximum number of scrap you want to craft. Type '0' (without quotes) if you want to craft all weapons into scrap.");
  1695. craftSwitch = true;
  1696. }
  1697. }
  1698. else if (message.Contains("craft rec" )|| recSwitch)
  1699. {
  1700. if (recSwitch)
  1701. {
  1702. if (IsNumeric(message))
  1703. {
  1704. int recCrafted = Bot.craftRec(Int32.Parse(message));
  1705. sendChatMessage("I was able to craft a total of: " + recCrafted + " rec.");
  1706. recSwitch = false;
  1707. }
  1708. else
  1709. {
  1710. sendChatMessage("Type the maximum number of rec you want to craft");
  1711. }
  1712. }
  1713. else
  1714. {
  1715. sendChatMessage("Type the maximum number of rec you want to craft. Type '0' (without quotes) if you want to craft all scrap into rec.");
  1716. recSwitch = true;
  1717. }
  1718. }
  1719. else if (message.Contains("craft ref") || refSwitch)
  1720. {
  1721. if (refSwitch)
  1722. {
  1723. if (IsNumeric(message))
  1724. {
  1725. int refCrafted = Bot.craftRef(Int32.Parse(message));
  1726. sendChatMessage("I was able to craft a total of: " + refCrafted + " ref.");
  1727. refSwitch = false;
  1728. }
  1729. else
  1730. {
  1731. sendChatMessage("Type the maximum number of scrap you want to craft");
  1732. }
  1733. }
  1734. else
  1735. {
  1736. sendChatMessage("Type the maximum number of ref you want to craft. Type '0' (without quotes) if you want to craft all rec into ref.");
  1737. refSwitch = true;
  1738. }
  1739. }
  1740. else if(message.Contains("block craft") || blockSwitch){
  1741. if(blockSwitch){
  1742. if (IsNumeric(message))
  1743. {
  1744. int defindex = Int32.Parse(message);
  1745. if (currentItemName == null)
  1746. {
  1747. sendChatMessage("Could not find an item with that defindex, please try again or use 'restart' to return to the main admin menu");
  1748. return;
  1749. }
  1750.  
  1751. else{
  1752. mySettings.noCraft.Add(currentItemDefindex);
  1753. mySettings.saveBotSettings(mySettings);
  1754. blockSwitch = false;
  1755. }
  1756. }
  1757. else
  1758. {
  1759. int defindex = getItemId(message, STEAMCHAT);
  1760. if (defindex == -1)
  1761. {
  1762. sendChatMessage("Couldn't find a specific match for that item");
  1763. return;
  1764. }
  1765. else{
  1766. mySettings.noCraft.Add(currentItemDefindex);
  1767. mySettings.saveBotSettings(mySettings);
  1768. blockSwitch = false;
  1769. }
  1770. }
  1771. }
  1772. else{
  1773. sendChatMessage("Type the name or defindex of the item you want to block from being crafted");
  1774. blockSwitch = true;
  1775. }
  1776. }
  1777. else if (message.Equals("remove item") || removalSwitch > 0)
  1778. {
  1779. switch (removalSwitch)
  1780. {
  1781. case 0:
  1782. sendChatMessage("Enter the name or defindex of the item you'd like to remove from the price settings");
  1783. removalSwitch++;
  1784. break;
  1785. case 1:
  1786. if (IsNumeric(message))
  1787. {
  1788. currentItemDefindex = Int32.Parse(message);
  1789. currentItemName = getItemName(currentItemDefindex);
  1790. if (currentItemName == null)
  1791. {
  1792. sendChatMessage("Could not find an item with that defindex, please try again or use 'restart' to return to the main admin menu");
  1793. return;
  1794. }
  1795. }
  1796. else
  1797. {
  1798. currentItemDefindex = getItemId(message, STEAMCHAT);
  1799. if (currentItemDefindex == -1)
  1800. {
  1801. sendChatMessage("Couldn't find a specific match for that item");
  1802. return;
  1803. }
  1804. currentItemName = getItemName(currentItemDefindex);
  1805. }
  1806. bool removedItem = false;
  1807. List<BotSettings.Item> copy = new List<BotSettings.Item>();
  1808. copy = mySettings.items.ToList<BotSettings.Item>();
  1809. foreach (BotSettings.Item item in copy)
  1810. {
  1811. if (item.defindex == currentItemDefindex)
  1812. {
  1813. sendChatMessage("Item Removed");
  1814. mySettings.items.Remove(item);
  1815. removedItem = true;
  1816. }
  1817. }
  1818. if (!removedItem)
  1819. {
  1820. sendChatMessage("Could not remove that item try a different name");
  1821. return;
  1822. }
  1823. mySettings.saveBotSettings(mySettings);
  1824. removalSwitch = 0;
  1825. break;
  1826. default:
  1827. //lol
  1828. break;
  1829. }
  1830. }
  1831. else if (message.Contains("set key"))
  1832. {
  1833. try
  1834. {
  1835. parseKeyPrice(message);
  1836. mySettings.saveBotSettings(mySettings);
  1837. }
  1838. catch
  1839. {
  1840. sendChatMessage("SYNTAX ERROR: be sure that you are including the proper spacing and that the price is in *scrap* (there should be no decimals in your input");
  1841. }
  1842. }
  1843. else
  1844. {
  1845. sendChatMessage("Valid commands include: set price, set password [newpassword] [confirmnewpassword], remove item, set key [price of keys in scrap], remove friends, craft scrap");
  1846. sendChatMessage("Use 'exit' to leave admin mode");
  1847. }
  1848. }
  1849.  
  1850. public void parsePassword(string message) //lets you change your admin password
  1851. {
  1852. string[] codes = message.Split(' ');
  1853. if (codes.Length > 4)
  1854. {
  1855. sendChatMessage("Remember, you cannot use spaces in your passwords");
  1856. }
  1857. if (codes.Length < 4)
  1858. {
  1859. sendChatMessage("You need to enter your new password followed by a space followed by your new password again");
  1860. }
  1861. else
  1862. {
  1863. if (codes[2] == codes[3])
  1864. {
  1865. mySettings.adminPassword = codes[3];
  1866. }
  1867. else
  1868. {
  1869. sendChatMessage("The two passwords didn't match");
  1870. }
  1871. }
  1872. }
  1873.  
  1874. public void parseKeyPrice(string message) //when you try to config the key price
  1875. {
  1876. int thisPrice;
  1877. string priceInfo = message.Substring(8);
  1878. if (IsNumeric(priceInfo))
  1879. {
  1880. thisPrice = Int32.Parse(priceInfo);
  1881. mySettings.scrapPerKey = thisPrice;
  1882. }
  1883. else
  1884. {
  1885. sendChatMessage("Sorry, I only understand numeric prices.");
  1886. thisPrice = -1;
  1887. return;
  1888. }
  1889. }
  1890. #endregion
  1891. #endregion
  1892.  
  1893.  
  1894. }
  1895. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement