public override void OnTradeRemoveItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { if (ActiveOrder != null && ActiveOrder.MatchesItem(inventoryItem)) { ActiveOrder = null; Trade.RemoveAllItems(); } else { if (schemaItem.Defindex == TF2Value.SCRAP_DEFINDEX) AmountAdded -= TF2Value.Scrap; else if (schemaItem.Defindex == TF2Value.RECLAIMED_DEFINDEX) AmountAdded -= TF2Value.Reclaimed; else if (schemaItem.Defindex == TF2Value.REFINED_DEFINDEX) AmountAdded -= TF2Value.Refined; else if (schemaItem.Defindex == TF2Value.KEY_DEFINDEX) AmountAdded -= TF2Value.Key; } }
public override void OnTradeAddItem(Schema.Item schemaItem, Inventory.Item inventoryItem) { Log.Info("Added item {0}{1} (defindex #{2}).", Order.GetQualityString(inventoryItem.Quality), schemaItem.ItemName, schemaItem.Defindex); if (!schemaItem.IsPure()) { Bot.GetInventory(); bool found = false; foreach (Order o in Bot.Orders.BuyOrders) { if (o.MatchesItem(inventoryItem)) { found = true; if (Bot.MyInventory.TotalPure() < o.Price) { Log.Warn("Out of metal for buy orders! Not enough metal to buy {0}.", schemaItem.ItemName); SendTradeMessage("Unfortunately I am out of metal and cannot buy anything at the moment."); SendTradeMessage("Enter 'buy' to get a list of the items I am selling."); } else if (Bot.MyInventory.GetItemsByDefindex(o.Defindex, o.Quality).Count >= o.MaxStock) { Log.Warn("Full stock for item {0}.", schemaItem.ItemName); SendTradeMessage("Unfortunately I have full stock and cannot buy your {0}.", schemaItem.ItemName); SendTradeMessage("Enter 'buy' to get a list of the items I am selling."); } else { ActiveOrder = o; SendTradeMessage(o.ToString(Trade.CurrentSchema)); AddPure(ActiveOrder.Price); } } } if (!found) { SendTradeMessage("I am currently not buying that item at the moment."); SendTradeMessage("Enter 'buy' to get a list of the items I am selling."); } } else { if (schemaItem.Defindex == TF2Value.SCRAP_DEFINDEX) AmountAdded += TF2Value.Scrap; else if (schemaItem.Defindex == TF2Value.RECLAIMED_DEFINDEX) AmountAdded += TF2Value.Reclaimed; else if (schemaItem.Defindex == TF2Value.REFINED_DEFINDEX) AmountAdded += TF2Value.Refined; else if (schemaItem.Defindex == TF2Value.KEY_DEFINDEX) AmountAdded += TF2Value.Key; else if (ActiveOrder != null) { SendTradeMessage("Sorry, but I cannot accept any {0} as valid payment.", schemaItem.ItemName); } if (AmountAdded == ActiveOrder.Price) { SendTradeMessage("You have paid the correct amount."); } else if (AmountAdded > ActiveOrder.Price) { SendTradeMessage("You are paying too much! The price for the {0} is {1}.", ActiveOrder.GetSearchString(Trade.CurrentSchema), ActiveOrder.Price.ToRefString()); } } }
public override void OnTradeMessage(string messageRaw) { Log.Info("Recieved trade message from user {0}: {1}", OtherSID.ToString(), messageRaw); string message = messageRaw.Trim().ToLower(); Bot.GetInventory(); if (message == "help" || message == "!help" || message == "?") { SendTradeMessage("These are all the available trade commands:"); SendTradeMessage("> help: List all trade commands."); SendTradeMessage("> buy, listall, showall: Show all items I am selling."); SendTradeMessage("> buy {item name}: Specify an item you wish to buy from me."); SendTradeMessage("> clear: Clear my items from the trade window."); SendTradeMessage("> cancel: Cancel the trade."); } if (message == "buy" || message == "listall" || message == "showall") { SendTradeMessage("These are the items I am currently selling and have in stock: "); foreach (Order o in Bot.Orders.SellOrders) { List<Inventory.Item> inStock = Bot.MyInventory. GetItemsByDefindex(o.Defindex, o.Quality); if (inStock != null && inStock.Count > 0) { SendTradeMessage("> {0} [{1} in stock]", o.ToString(Trade.CurrentSchema), inStock.Count.ToString()); Trade.AddItemByDefindex(o.Defindex, o.Quality); } } return; } if (message == "clear") { Trade.RemoveAllItems(); } if (message == "cancel" || message == "exit") { SendTradeMessage("I am now cancelling the trade."); Trade.CancelTrade(); return; } #region buy itemname if (message.StartsWith("buy ")) { string query = message.Substring("buy ".Length); query = query.Trim(); bool found = false; foreach (Order o in Bot.Orders.SellOrders) { if (o.GetSearchString(Trade.CurrentSchema).ToLower() == query) { List<Inventory.Item> inStock = Bot.MyInventory.GetItemsByDefindex(o.Defindex, o.Quality); if (inStock.Count == 0) { SendTradeMessage("Unfortunately I seem to be out of that item."); return; } ActiveOrder = o; SendTradeMessage("I currently have {0} of those in stock.", inStock.Count.ToString()); Trade.RemoveAllItems(); Trade.AddItemByDefindex(o.Defindex, o.Quality); found = true; SendTradeMessage("Now add your payment of {0}.", o.Price.ToRefString()); } } if (!found) { List<Order> validOrders = new List<Order>(); foreach (Order o in Bot.Orders.SellOrders) { if (o.GetSearchString(Trade.CurrentSchema).ToLower().Contains(query)) { validOrders.Add(o); } } if (validOrders.Count > 1) { SendTradeMessage("It seems I am selling multiple items that may fit that name:"); foreach (Order o in validOrders) { SendTradeMessage("> {0} [{1} in stock]", o.ToString(Trade.CurrentSchema), Bot.MyInventory.GetItemsByDefindex(o.Defindex, o.Quality).Count.ToString()); } SendTradeMessage("Perhaps being more specific in your query may help."); return; } else if (validOrders.Count == 0) { SendTradeMessage("Unfortunately I am not selling any items that fit that name."); return; } else // 1 { Order o = validOrders.First(); ActiveOrder = o; SendTradeMessage("I currently have {0} of those in stock.", Bot.MyInventory.GetItemsByDefindex(o.Defindex, o.Quality).Count.ToString()); Trade.RemoveAllItems(); Trade.AddItemByDefindex(o.Defindex, o.Quality); SendTradeMessage("Now add your payment of {0}.", o.Price.ToRefString()); } } } #endregion buy itemname }
public bool IsFullStock(Order o) { if (o == null) { return false; } if (o.IsBuyOrder) { Bot.GetInventory(); return Bot.MyInventory.GetItemsByDefindex(o.Defindex, o.Quality).Count >= o.MaxStock; } return false; }