/// <summary> /// Removes an item with the given Defindex from the trade. /// </summary> /// <returns> /// Returns <c>true</c> if it found a corresponding item; <c>false</c> otherwise. /// </returns> public bool RemoveItemByDefindex(int defindex) { foreach (TradeUserAssets asset in myOfferedItemsLocalCopy.Values) { Inventory.Item item = MyInventory.GetItem(asset.assetid); if (item != null && item.Defindex == defindex) { return(RemoveItem(item.Id)); } } return(false); }
/// <summary> /// Gets an item from a TradeEvent, and passes it into the UserHandler's implemented OnUserAddItem([...]) routine. /// Passes in null items if something went wrong. /// </summary> private void FireOnUserAddItem(TradeUserAssets asset) { if (MeIsReady) { SetReady(false); } if (OtherInventory != null && !OtherInventory.IsPrivate) { Inventory.Item item = OtherInventory.GetItem(asset.assetid); if (item != null) { Schema.Item schemaItem = CurrentSchema.GetItem(item.Defindex); if (schemaItem == null) { Console.WriteLine("User added an unknown item to the trade."); } OnUserAddItem?.Invoke(schemaItem, item); } else { item = new Inventory.Item { Id = asset.assetid, AppId = asset.appid, ContextId = asset.contextid }; //Console.WriteLine("User added a non TF2 item to the trade."); OnUserAddItem?.Invoke(null, item); } } else { var schemaItem = GetItemFromPrivateBp(asset); if (schemaItem == null) { Console.WriteLine("User added an unknown item to the trade."); } OnUserAddItem(schemaItem, null); // todo: figure out what to send in with Inventory item..... } }
/// <summary> /// Gets an item from a TradeEvent, and passes it into the UserHandler's implemented OnUserRemoveItem([...]) routine. /// Passes in null items if something went wrong. /// </summary> /// <returns></returns> private void FireOnUserRemoveItem(TradeUserAssets asset) { if (MeIsReady) { SetReady(false); } if (OtherInventory != null) { Inventory.Item item = OtherInventory.GetItem(asset.assetid); if (item != null) { Schema.Item schemaItem = CurrentSchema.GetItem(item.Defindex); if (schemaItem == null) { // TODO: Add log (counldn't find item in CurrentSchema) } OnUserRemoveItem(schemaItem, item); } else { // TODO: Log this (Couldn't find item in user's inventory can't find item in CurrentSchema item = new Inventory.Item { Id = asset.assetid, AppId = asset.appid, ContextId = asset.contextid }; OnUserRemoveItem(null, item); } } else { var schemaItem = GetItemFromPrivateBp(asset); if (schemaItem == null) { // TODO: Add log (counldn't find item in CurrentSchema) } OnUserRemoveItem(schemaItem, null); } }
/// <summary> /// Removes all offered items from the trade. /// </summary> /// <returns>Number of items removed.</returns> public uint RemoveAllItems() { uint numRemoved = 0; foreach (TradeUserAssets asset in myOfferedItemsLocalCopy.Values.ToList()) { Inventory.Item item = MyInventory.GetItem(asset.assetid); if (item != null) { bool wasRemoved = RemoveItem(item.Id); if (wasRemoved) { numRemoved++; } } } return(numRemoved); }