public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { string ItemRemovedMsg = String.Format("User added {0} {1} {2} {3}", inventoryItem.IsNotCraftable.ToString().ToLower() == "true" ? "NonCraftable" : "Craftable", clsFunctions.ConvertQualityToString(schemaItem.ItemQuality), schemaItem.ItemName, schemaItem.CraftMaterialType); //ready ItemRemovedMsg Bot.log.Warn("User removed: " + ItemRemovedMsg); }
public override void OnTradeAccept() { if (Validate() || IsAdmin) { Bot.log.Success("Accepting trade..."); try { Trade.AcceptTrade(); if (!IsAdmin) { string fileDirectory = "Donation"; string fileName = OtherSID.ConvertToUInt64().ToString(); string fullPath = Path.Combine(fileDirectory, fileName + ".log"); fullPath = FileToCreate; string sPastDonation = string.Empty; string sSpacer = @"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"; if (File.Exists(fullPath)) { TextReader reader = new StreamReader(fullPath); sPastDonation = reader.ReadToEnd(); reader.Close(); } else { File.Create(fullPath); } StreamWriter writer = new StreamWriter(fullPath, false); writer.WriteLine(sSpacer); List <Inventory.Item> items = new List <Inventory.Item>(); foreach (TradeUserAssets id in Trade.OtherOfferedItems) { if (id.appid == 440) { items.Add(Trade.OtherInventory.GetItem(id.assetid));//Get item } }//foreach (ulong id in Trade.OtherOfferedItems) foreach (Inventory.Item id in items) { Schema schema = Trade.CurrentSchema; Inventory inventory = Trade.OtherInventory; Schema.Item schemaItem = schema.GetItem(id.Defindex); string ItemAddedMsg = String.Format("User added {0} {1} {2} {3}", id.IsNotCraftable.ToString().ToLower() == "true" ? "NonCraftable" : "Craftable", clsFunctions.ConvertQualityToString(schemaItem.ItemQuality), schemaItem.ItemName, schemaItem.CraftMaterialType); //ready ItemRemovedMsg writer.WriteLine("Donated: " + ItemAddedMsg); } writer.WriteLine(Bot.SteamFriends.GetFriendPersonaName(OtherSID)); writer.WriteLine(OtherSID.ConvertToUInt64().ToString()); writer.WriteLine(System.DateTime.Now.ToShortTimeString()); if (sPastDonation != null) { writer.Write(sPastDonation); } writer.Close(); Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Thank you for donating!"); Bot.SteamFriends.SendChatMessage(clsFunctions.BotsOwnerID, EChatEntryType.ChatMsg, "A user just donated!"); } Log.Success("Trade Complete!"); } catch (System.Exception ex) { Log.Warn("The trade might have failed, but we can't be sure."); Log.Warn(ex.Message); } } Bot.SteamFriends.SetPersonaState(EPersonaState.Online); OnTradeClose(); }
public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { Log.Info("Item Removed"); Log.Info("Appid: {0}", inventoryItem.AppId); Log.Info("Id: {0}", inventoryItem.Id); }
public abstract void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem);
public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { // whatever. }
string GetItemName(Schema.Item schemaItem, Inventory.Item inventoryItem, out string price, bool id = false) { price = "Unknown"; bool isGifted = false; bool isUnusual = false; var currentItem = Trade.CurrentSchema.GetItem(schemaItem.Defindex); string name = ""; var type = Convert.ToInt32(inventoryItem.Quality.ToString()); if (QualityToName(type) != "Unique") { name += QualityToName(type) + " "; } name += currentItem.ItemName; if (QualityToName(type) == "Unusual") { isUnusual = true; try { for (int count = 0; count < inventoryItem.Attributes.Length; count++) { if (inventoryItem.Attributes[count].Defindex == 134) { name += " (Effect: " + EffectToName(inventoryItem.Attributes[count].FloatValue) + ")"; price = Util.GetPrice(schemaItem.Defindex, type, inventoryItem, false, (int)inventoryItem.Attributes[count].FloatValue); } } } catch (Exception) { } } if (currentItem.CraftMaterialType == "supply_crate") { for (int count = 0; count < inventoryItem.Attributes.Length; count++) { name += " #" + (inventoryItem.Attributes[count].FloatValue); } } name += " (Level " + inventoryItem.Level + ")"; try { int size = inventoryItem.Attributes.Length; for (int count = 0; count < size; count++) { if (inventoryItem.Attributes[count].Defindex == 261) { string paint = ShowBackpack.PaintToName(inventoryItem.Attributes[count].FloatValue); name += " (Painted: " + paint + ")"; } if (inventoryItem.Attributes[count].Defindex == 186) { isGifted = true; name += " (Gifted)"; } } } catch { // Item has no attributes... or something. } if (inventoryItem.IsNotCraftable) { name += " (Uncraftable)"; } if (currentItem.Name == "Wrapped Gift") { isGifted = true; // Untested! try { int size = inventoryItem.Attributes.Length; for (int count = 0; count < size; count++) { var containedItem = Trade.CurrentSchema.GetItem(inventoryItem.ContainedItem.Defindex); var containedName = GetItemName(containedItem, inventoryItem.ContainedItem, out price, false); price = Util.GetPrice(inventoryItem.ContainedItem.Defindex, Convert.ToInt32(inventoryItem.ContainedItem.Quality.ToString()), inventoryItem, true); name += " (Contains: " + containedName + ")"; } } catch { // Item has no attributes... or something. } } if (id) { name += " :" + inventoryItem.Id; } if (!isGifted && !isUnusual) { price = Util.GetPrice(currentItem.Defindex, type, inventoryItem); ListBackpack.Add(name, inventoryItem.Defindex, currentItem.ImageURL, price); } else { ListBackpack.Add(name, inventoryItem.Defindex, currentItem.ImageURL, price); } return(name); }
public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { var item = Trade.CurrentSchema.GetItem(schemaItem.Defindex); if (!HasCounted) { Trade.SendMessage("ERROR: I haven't finished counting my inventory yet! Please remove any items you added, and then re-add them or there could be errors."); } else if (InvalidItem >= 4) { Trade.CancelTrade(); Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "Please stop messing around. I am used for buying and selling keys only. I can only accept metal or keys as payment."); Bot.log.Warn("Booted user for messing around."); Bot.SteamFriends.SetPersonaState(EPersonaState.Online); } else if (item.Defindex == 5000) { // Put up scrap metal UserMetalAdded++; UserScrapAdded++; Bot.log.Success("User added: " + item.ItemName); } else if (item.Defindex == 5001) { // Put up reclaimed metal UserMetalAdded += 3; UserRecAdded++; Bot.log.Success("User added: " + item.ItemName); } else if (item.Defindex == 5002) { // Put up refined metal UserMetalAdded += 9; UserRefAdded++; Bot.log.Success("User added: " + item.ItemName); } else if (item.Defindex == 5021) { // Put up keys UserKeysAdded++; Bot.log.Success("User added: " + item.ItemName); // USER IS SELLING KEYS if (!ChooseDonate) { // BOT ADDS METAL int KeysToScrap = UserKeysAdded * BuyPricePerKey; if (InventoryMetal < KeysToScrap) { Trade.SendMessage("I only have " + InventoryMetal + " scrap. You need to remove some keys."); Bot.log.Warn("I don't have enough metal for the user."); } else { Trade.SendMessage("You have given me " + UserKeysAdded + " key(s). I will give you " + KeysToScrap + " scrap."); Bot.log.Success("User gave me " + UserKeysAdded + " key(s). I will now give him " + KeysToScrap + " scrap."); // Put up required metal bool DoneAddingMetal = false; while (!DoneAddingMetal) { if (InventoryRef > 0 && BotMetalAdded + 9 <= KeysToScrap) { Trade.AddItemByDefindex(5002); Bot.log.Warn("I added Refined Metal."); BotMetalAdded += 9; BotRefAdded++; InventoryRef--; } else if (InventoryRec > 0 && BotMetalAdded + 3 <= KeysToScrap) { Trade.AddItemByDefindex(5001); Bot.log.Warn("I added Reclaimed Metal."); BotMetalAdded += 3; BotRecAdded++; InventoryRec--; } else if (InventoryScrap > 0 && BotMetalAdded + 1 <= KeysToScrap) { Trade.AddItemByDefindex(5000); Bot.log.Warn("I added Scrap Metal."); BotMetalAdded++; BotScrapAdded++; InventoryScrap--; } else if (InventoryScrap == 0 && BotMetalAdded + 2 == KeysToScrap) { Trade.SendMessage("Sorry, but I don't have enough scrap metal to give you! Please remove some keys or add two keys."); Bot.log.Warn("Couldn't add enough metal for the user!"); DoneAddingMetal = true; } else if (InventoryScrap == 0 && BotMetalAdded + 1 == KeysToScrap) { Trade.SendMessage("Sorry, but I don't have enough scrap metal to give you! Please remove some keys or add a key."); Bot.log.Warn("Couldn't add enough metal for the user!"); DoneAddingMetal = true; } else if (BotMetalAdded == KeysToScrap) { Trade.SendMessage("Added enough metal. " + BotRefAdded + " ref, " + BotRecAdded + " rec, " + BotScrapAdded + " scrap."); Bot.log.Success("Gave user enough metal!"); DoneAddingMetal = true; } } } } } else if (item.Defindex == 5049 || item.Defindex == 5067 || item.Defindex == 5072 || item.Defindex == 5073 || item.Defindex == 5079 || item.Defindex == 5081 || item.Defindex == 5628 || item.Defindex == 5631 || item.Defindex == 5632) { Trade.SendMessage("I'm sorry but I can't accept " + item.ItemName + "! This key used to be a special key such as a winter key that has turned back into a normal one. Unfortunately the ID is different and I am not coded to handle them at the moment. Please remove it and exchange it for a normal key!"); Bot.log.Warn("User added a special key, but I cannot accept it."); } else { // Put up other items Trade.SendMessage("Sorry, I don't accept " + item.ItemName + "! I only accept metal/keys. Please remove it from the trade to continue."); Bot.log.Warn("User added: " + item.ItemName); InvalidItem++; } // USER IS BUYING KEYS if (!ChooseDonate) { if (UserMetalAdded % SellPricePerKey >= 0 && UserMetalAdded > 0) { // Count refined and convert to keys -- X scrap per key int NumKeys = UserMetalAdded / SellPricePerKey; if (NumKeys > 0 && NumKeys != PreviousKeys) { Trade.SendMessage("You put up enough metal for " + NumKeys + " key(s). Adding your keys now."); Bot.log.Success("User put up enough metal for " + NumKeys + " key(s)."); if (NumKeys > InventoryKeys) { double excess = ((NumKeys - BotKeysAdded) * SellPricePerKey) / 9.0; string refined = string.Format("{0:N2}", excess); Trade.SendMessage("I only have " + InventoryKeys + " in my backpack. :("); Bot.log.Warn("User wanted to buy " + NumKeys + " key(s), but I only have " + InventoryKeys + " key(s)."); Trade.SendMessage("Please remove " + refined + " ref."); NumKeys = InventoryKeys; } // Add the keys to the trade window for (int count = BotKeysAdded; count < NumKeys; count++) { Trade.AddItemByDefindex(5021); Bot.log.Warn("I am adding Mann Co. Supply Crate Key."); BotKeysAdded++; //BUG FIX KEYS 1/2 //InventoryKey--; } Trade.SendMessage("I have added " + BotKeysAdded + " key(s) for you."); Bot.log.Success("I have added " + BotKeysAdded + " key(s) for the user."); PreviousKeys = NumKeys; } } } }
public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { Log.Info("Admin added item to trade: " + schemaItem.ItemName); }
string GetItemName(Schema.Item schemaItem, Inventory.Item inventoryItem, out string price, bool id = false) { price = "Unknown"; bool isGifted = false; bool isUnusual = false; var currentItem = Trade.CurrentSchema.GetItem(schemaItem.Defindex); string name = ""; var type = Convert.ToInt32(inventoryItem.Quality.ToString()); if (Util.QualityToName(type) != "Unique") { name += Util.QualityToName(type) + " "; } name += currentItem.ItemName; name += " (" + SteamTrade.Trade.CurrentItemsGame.GetItemRarity(schemaItem.Defindex.ToString()) + ")"; if (Util.QualityToName(type) == "Unusual") { isUnusual = true; try { for (int count = 0; count < inventoryItem.Attributes.Length; count++) { if (inventoryItem.Attributes[count].Defindex == 134) { name += " (Effect: " + Trade.CurrentSchema.GetEffectName(inventoryItem.Attributes[count].FloatValue) + ")"; } } } catch (Exception) { } } if (currentItem.CraftMaterialType == "supply_crate") { for (int count = 0; count < inventoryItem.Attributes.Length; count++) { name += " #" + (inventoryItem.Attributes[count].FloatValue); } } try { int size = inventoryItem.Attributes.Length; for (int count = 0; count < size; count++) { if (inventoryItem.Attributes[count].Defindex == 261) { string paint = ShowBackpack.PaintToName(inventoryItem.Attributes[count].FloatValue); name += " (Painted: " + paint + ")"; } if (inventoryItem.Attributes[count].Defindex == 186) { isGifted = true; name += " (Gifted)"; } } } catch { // Item has no attributes... or something. } if (inventoryItem.IsNotCraftable) { name += " (Uncraftable)"; } if (!string.IsNullOrWhiteSpace(inventoryItem.CustomName)) { name += " (Custom Name: " + inventoryItem.CustomName + ")"; } if (!string.IsNullOrWhiteSpace(inventoryItem.CustomDescription)) { name += " (Custom Desc.: " + inventoryItem.CustomDescription + ")"; } if (id) { name += " :" + inventoryItem.Id; } if (!isGifted && !isUnusual) { ListBackpack.Add(name, inventoryItem.Defindex, currentItem.ImageURL, price); } else { ListBackpack.Add(name, inventoryItem.Defindex, currentItem.ImageURL, price); } return(name); }
public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { throw new NotImplementedException(); }
string GetItemName(Schema.Item schemaItem, Inventory.Item inventoryItem, bool id = false) { var currentItem = Trade.CurrentSchema.GetItem(schemaItem.Defindex); string name = ""; var type = Convert.ToInt32(inventoryItem.Quality.ToString()); if (Util.QualityToName(type) != "Unique") { name += Util.QualityToName(type) + " "; } name += currentItem.ItemName; name += " (" + SteamTrade.Trade.CurrentItemsGame.GetItemRarity(schemaItem.Defindex.ToString()) + ")"; if (Util.QualityToName(type) == "Unusual") { try { for (int count = 0; count < inventoryItem.Attributes.Length; count++) { if (inventoryItem.Attributes[count].Defindex == 134) { name += " (Effect: " + EffectToName(inventoryItem.Attributes[count].FloatValue) + ")"; } } } catch (Exception) { } } if (currentItem.CraftMaterialType == "supply_crate") { for (int count = 0; count < inventoryItem.Attributes.Length; count++) { name += " #" + (inventoryItem.Attributes[count].FloatValue); } } try { int size = inventoryItem.Attributes.Length; for (int count = 0; count < size; count++) { if (inventoryItem.Attributes[count].Defindex == 261) { string paint = ShowBackpack.PaintToName(inventoryItem.Attributes[count].FloatValue); name += " (Painted: " + paint + ")"; } if (inventoryItem.Attributes[count].Defindex == 186) { name += " (Gifted)"; } } } catch { // Item has no attributes... or something. } if (currentItem.Name == "Wrapped Gift") { // Untested! try { int size = inventoryItem.Attributes.Length; for (int count = 0; count < size; count++) { var containedItem = Trade.CurrentSchema.GetItem(inventoryItem.ContainedItem.Defindex); var containedName = GetItemName(containedItem, inventoryItem.ContainedItem); name += " (Contains: " + containedName + ")"; } } catch { // Item has no attributes... or something. } } if (!string.IsNullOrWhiteSpace(inventoryItem.CustomName)) { name += " (Custom Name: " + inventoryItem.CustomName + ")"; } if (!string.IsNullOrWhiteSpace(inventoryItem.CustomDescription)) { name += " (Custom Desc.: " + inventoryItem.CustomDescription + ")"; } if (id) { name += " :" + inventoryItem.Id; } return(name); }
public bool RunCommand(List <string> args, UserHandler handler, Action <string> sendChatMessage) { string itemname = null; if (args.Count > 0) { itemname = string.Join(" ", args).ToLower(); } try { handler.Bot.GetInventory(); Schema schema = Trade.CurrentSchema; List <_stockInfo> stock = new List <_stockInfo>(); foreach (Inventory.Item i in handler.Bot.MyInventory.Items) { if (i.IsNotTradeable) { continue; } if (i.Defindex == TF2Value.SCRAP_DEFINDEX || i.Defindex == TF2Value.RECLAIMED_DEFINDEX || i.Defindex == TF2Value.REFINED_DEFINDEX || i.Defindex == TF2Value.KEY_DEFINDEX) { continue; } Schema.Item item = schema.GetItem(i.Defindex); _stockInfo inf = stock.FirstOrDefault((_i) => _i.Item == item); if (inf != null) { inf.Count++; } else { Order b = handler.Bot.Orders.BuyOrders.FirstOrDefault((_o) => _o.Defindex == item.Defindex); Order s = handler.Bot.Orders.SellOrders.FirstOrDefault((_o) => _o.Defindex == item.Defindex); stock.Add(new _stockInfo(item, i.Quality, 1, b, s)); } } if (itemname == null) { sendChatMessage("I currently have the following items in stock:"); foreach (_stockInfo inf in stock) { sendChatMessage("> " + inf.ToString()); } } else { stock.RemoveAll((si) => !si.FullName.ToLower().Contains(itemname)); if (stock.Count == 0) { sendChatMessage("I do not have any items in stock that fit your search query."); } else { sendChatMessage("I currently have the following items in stock matching '" + itemname + "':"); foreach (_stockInfo inf in stock) { sendChatMessage("> " + inf.ToString()); } } } return(true); } catch (Exception e) { handler.Log.Error("An error occurred during the {0} command: {1}", CommandName, e.Message); return(false); } }
public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { Log.Info("Admin removed item from trade: " + schemaItem.ItemName); }
public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { Log.Info("Added item {0}{1} (defindex #{2}).", Order.GetQualityString(inventoryItem.Quality), schemaItem.ItemName, schemaItem.Defindex); if (!schemaItem.IsPure()) { Bot.GetInventory(); bool found = false; foreach (Order o in Bot.Orders.BuyOrders) { if (o.MatchesItem(inventoryItem)) { found = true; if (Bot.MyInventory.TotalPure() < o.Price) { Log.Warn("Out of metal for buy orders! Not enough metal to buy {0}.", schemaItem.ItemName); SendTradeMessage("Unfortunately I am out of metal and cannot buy anything at the moment."); SendTradeMessage("Enter 'buy' to get a list of the items I am selling."); } else if (Bot.MyInventory.GetItemsByDefindex(o.Defindex, o.Quality).Count >= o.MaxStock) { Log.Warn("Full stock for item {0}.", schemaItem.ItemName); SendTradeMessage("Unfortunately I have full stock and cannot buy your {0}.", schemaItem.ItemName); SendTradeMessage("Enter 'buy' to get a list of the items I am selling."); } else { ActiveOrder = o; SendTradeMessage(o.ToString(Trade.CurrentSchema)); AddPure(ActiveOrder.Price); } } } if (!found) { SendTradeMessage("I am currently not buying that item at the moment."); SendTradeMessage("Enter 'buy' to get a list of the items I am selling."); } } else { if (schemaItem.Defindex == TF2Value.SCRAP_DEFINDEX) { AmountAdded += TF2Value.Scrap; } else if (schemaItem.Defindex == TF2Value.RECLAIMED_DEFINDEX) { AmountAdded += TF2Value.Reclaimed; } else if (schemaItem.Defindex == TF2Value.REFINED_DEFINDEX) { AmountAdded += TF2Value.Refined; } else if (schemaItem.Defindex == TF2Value.KEY_DEFINDEX) { AmountAdded += TF2Value.Key; } else if (ActiveOrder != null) { SendTradeMessage("Sorry, but I cannot accept any {0} as valid payment.", schemaItem.ItemName); } if (AmountAdded == ActiveOrder.Price) { SendTradeMessage("You have paid the correct amount."); } else if (AmountAdded > ActiveOrder.Price) { SendTradeMessage("You are paying too much! The price for the {0} is {1}.", ActiveOrder.GetSearchString(Trade.CurrentSchema), ActiveOrder.Price.ToRefString()); } } }
public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { var item = Trade.CurrentSchema.GetItem(schemaItem.Defindex); if (item.Defindex == 5000) { // Removed scrap metal UserMetalAdded--; UserScrapAdded--; Bot.log.Success("User removed: " + item.ItemName); } else if (item.Defindex == 5001) { // Removed reclaimed metal UserMetalAdded -= 3; UserRecAdded--; Bot.log.Success("User removed: " + item.ItemName); } else if (item.Defindex == 5002) { // Removed refined metal UserMetalAdded -= 9; UserRefAdded--; Bot.log.Success("User removed: " + item.ItemName); } else if (item.Defindex == 5021) { // Removed keys UserKeysAdded--; Bot.log.Success("User removed: " + item.ItemName); } else if (item.Defindex == 5049 || item.Defindex == 5067 || item.Defindex == 5072 || item.Defindex == 5073 || item.Defindex == 5079 || item.Defindex == 5081 || item.Defindex == 5628 || item.Defindex == 5631 || item.Defindex == 5632) { Bot.log.Warn("User removed special key."); } else { // Removed other items Bot.log.Warn("User removed: " + item.ItemName); } // User removes key from trade if (UserKeysAdded < (float)BotMetalAdded / BuyPricePerKey) { int KeysToScrap = UserKeysAdded * BuyPricePerKey; bool DoneAddingMetal = false; while (!DoneAddingMetal) { WhileLoop++; if (BotRefAdded > 0 && BotMetalAdded - 9 >= KeysToScrap) { Trade.RemoveItemByDefindex(5002); Bot.log.Warn("I removed Refined Metal."); BotMetalAdded -= 9; BotRefAdded--; InventoryRef++; } else if (BotRecAdded > 0 && BotMetalAdded - 3 >= KeysToScrap) { Trade.RemoveItemByDefindex(5001); Bot.log.Warn("I removed Reclaimed Metal."); BotMetalAdded -= 3; BotRecAdded--; InventoryRec++; } else if (BotScrapAdded > 0 && BotMetalAdded - 1 >= KeysToScrap) { Trade.RemoveItemByDefindex(5000); Bot.log.Warn("I removed Scrap Metal."); BotMetalAdded--; BotScrapAdded--; InventoryScrap++; } else if (BotMetalAdded == KeysToScrap) { DoneAddingMetal = true; } else if (WhileLoop > 50) { Trade.SendMessage("Error: I could not remove the proper amounts of metal from the trade. I might be out of scrap metal - try adding more keys if possible, or remove a few keys."); WhileLoop = 0; DoneAddingMetal = true; } } } // User removes metal from trade while ((float)UserMetalAdded / SellPricePerKey < BotKeysAdded) { Trade.RemoveItemByDefindex(5021); Bot.log.Warn("I removed Mann Co. Supply Crate Key."); BotKeysAdded--; InventoryKeys++; PreviousKeys = BotKeysAdded; IsOverpaying = false; } }
public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { }
public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { Log.Debug("Item has been added. ID: " + inventoryItem.Id); }