public IInventoryItem GetFirstItemNotTool(IToolItem tool, Inventory workbenchInv) { IInventoryItem inventoryItem; IInventoryItem inventoryItem1; Inventory.OccupiedIterator occupiedIterator = workbenchInv.occupiedIterator; try { while (occupiedIterator.Next(out inventoryItem)) { if (object.ReferenceEquals(inventoryItem, tool)) { continue; } inventoryItem1 = inventoryItem; return(inventoryItem1); } Debug.LogWarning("Could not find target item"); return(null); } finally { ((IDisposable)(object)occupiedIterator).Dispose(); } return(inventoryItem1); }
public IInventoryItem GetFirstItemNotTool(IToolItem tool, Inventory workbenchInv) { using (Inventory.OccupiedIterator iterator = workbenchInv.occupiedIterator) { IInventoryItem item; while (iterator.Next(out item)) { if (!object.ReferenceEquals(item, tool)) { return(item); } } } Debug.LogWarning("Could not find target item"); return(null); }
public static void ShopSell(NetUser Sender, UserData userData, string Command, string[] Args) { if (!Shop.Enabled || !Shop.CanSell) { Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.Sell.NotAvailable", Sender, null), 5f); } else if (Shop.TradeZoneOnly && (userData.Zone == null || !userData.Zone.CanTrade)) { Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.NoTradeZone", Sender, null), 5f); } else if (Args == null || Args.Length == 0) { Broadcast.Notice(Sender, "✘", Config.GetMessageCommand("Command.InvalidSyntax", Command, null), 5f); } else { int item_index = 0; Inventory component = Sender.playerClient.controllable.GetComponent <Inventory>(); if (!Args[0].Equals("ALL", StringComparison.OrdinalIgnoreCase)) { ShopItem shopItem; if (int.TryParse(Args[0], out item_index)) { shopItem = Shop.FindItem(item_index); } else { shopItem = Shop.FindItem(Args[0]); } if (shopItem != null) { if (shopItem.BuyPrice != -1) { int num = shopItem.BuyPrice / shopItem.Quantity; int num2 = shopItem.Quantity; if (Args.Length > 1 && !int.TryParse(Args[1], out num2)) { num2 = shopItem.Quantity; } if (num2 < 1) { num2 = shopItem.Quantity; } int num3 = Helper.InventoryItemCount(component, shopItem.itemData); if (num3 == 0) { Broadcast.Notice(Sender, Economy.CurrencySign, Config.GetMessage("Economy.Shop.Sell.NotEnoughItem", Sender, null).Replace("%ITEMNAME%", shopItem.Name), 5f); return; } if (num2 > num3) { num2 = num3; } num3 = Helper.InventoryItemRemove(component, shopItem.itemData, num2); string text = "\"" + shopItem.Name + "\""; if (num3 > 1) { text = num3.ToString() + " " + text; } ulong amount = (ulong)((long)(num3 * num)); Economy.BalanceAdd(Sender.userID, amount); string text2 = Config.GetMessage("Economy.Shop.Sell.ItemSold", Sender, null); text2 = text2.Replace("%TOTALPRICE%", amount.ToString("N0") + Economy.CurrencySign); text2 = text2.Replace("%ITEMNAME%", text); Broadcast.Notice(Sender, Economy.CurrencySign, text2, 5f); Economy.Balance(Sender, userData, "balance", null); return; } } string newValue = (shopItem != null) ? shopItem.Name : Args[0]; Broadcast.Notice(Sender, Economy.CurrencySign, Config.GetMessage("Economy.Shop.Sell.ItemNotAvailable", Sender, null).Replace("%ITEMNAME%", newValue), 5f); } else { ulong num4 = 0uL; List <IInventoryItem> list = new List <IInventoryItem>(); Inventory.OccupiedIterator occupiedIterator = component.occupiedIterator; while (occupiedIterator.Next()) { ShopItem shopItem = Shop.FindItem(occupiedIterator.item.datablock.name); if (shopItem != null && shopItem.BuyPrice != -1) { int num5 = occupiedIterator.item.datablock._splittable ? occupiedIterator.item.uses : 1; ulong num6 = (ulong)((long)(shopItem.BuyPrice / shopItem.Quantity) * (long)num5); num4 += num6; list.Add(occupiedIterator.item); } } if (list.Count > 0) { foreach (IInventoryItem current in list) { component.RemoveItem(current); } if (num4 > 0uL) { Economy.BalanceAdd(Sender.userID, num4); } string text3 = Config.GetMessage("Economy.Shop.Sell.AllSold", Sender, null); text3 = text3.Replace("%TOTALPRICE%", num4.ToString("N0") + Economy.CurrencySign); text3 = text3.Replace("%TOTALAMOUNT%", list.Count.ToString()); Broadcast.Notice(Sender, Economy.CurrencySign, text3, 5f); } else { Broadcast.Notice(Sender, Economy.CurrencySign, Config.GetMessage("Economy.Shop.Sell.NoNothing", Sender, null), 5f); } } } }
public static void ShopSell(NetUser Sender, UserData userData, string Command, string[] Args) { if (Shop.Enabled && Shop.CanSell) { if (Shop.TradeZoneOnly && ((userData.Zone == null) || !userData.Zone.CanTrade)) { Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.NoTradeZone", Sender, null), 5f); } else if ((Args != null) && (Args.Length != 0)) { ShopItem item = null; int result = 0; int num2 = 0; Inventory component = Sender.playerClient.controllable.GetComponent <Inventory>(); if (Args[0].Equals("ALL", StringComparison.OrdinalIgnoreCase)) { ulong amount = 0L; System.Collections.Generic.List <IInventoryItem> list = new System.Collections.Generic.List <IInventoryItem>(); Inventory.OccupiedIterator occupiedIterator = component.occupiedIterator; while (occupiedIterator.Next()) { item = Shop.FindItem(occupiedIterator.item.datablock.name); if ((item != null) && (item.BuyPrice != -1)) { int num4 = occupiedIterator.item.datablock._splittable ? occupiedIterator.item.uses : 1; ulong num5 = (ulong)((item.BuyPrice / item.Quantity) * num4); amount += num5; list.Add(occupiedIterator.item); } } if (list.Count > 0) { foreach (IInventoryItem item2 in list) { component.RemoveItem(item2); } if (amount > 0L) { BalanceAdd(Sender.userID, amount); } string text = Config.GetMessage("Economy.Shop.Sell.AllSold", Sender, null).Replace("%TOTALPRICE%", amount.ToString("N0") + CurrencySign).Replace("%TOTALAMOUNT%", list.Count.ToString()); Broadcast.Notice(Sender, CurrencySign, text, 5f); } else { Broadcast.Notice(Sender, CurrencySign, Config.GetMessage("Economy.Shop.Sell.NoNothing", Sender, null), 5f); } } else { if (int.TryParse(Args[0], out result)) { item = Shop.FindItem(result); } else { item = Shop.FindItem(Args[0]); } if ((item != null) && (item.BuyPrice != -1)) { int num6 = item.BuyPrice / item.Quantity; int quantity = item.Quantity; if ((Args.Length > 1) && !int.TryParse(Args[1], out quantity)) { quantity = item.Quantity; } if (quantity < 1) { quantity = item.Quantity; } num2 = Helper.InventoryItemCount(component, item.itemData); if (num2 == 0) { Broadcast.Notice(Sender, CurrencySign, Config.GetMessage("Economy.Shop.Sell.NotEnoughItem", Sender, null).Replace("%ITEMNAME%", item.Name), 5f); } else { if (quantity > num2) { quantity = num2; } num2 = Helper.InventoryItemRemove(component, item.itemData, quantity); string newValue = "\"" + item.Name + "\""; if (num2 > 1) { newValue = num2.ToString() + " " + newValue; } ulong num8 = (ulong)(num2 * num6); BalanceAdd(Sender.userID, num8); string str4 = Config.GetMessage("Economy.Shop.Sell.ItemSold", Sender, null).Replace("%TOTALPRICE%", num8.ToString("N0") + CurrencySign).Replace("%ITEMNAME%", newValue); Broadcast.Notice(Sender, CurrencySign, str4, 5f); Balance(Sender, userData, "balance", null); } } else { string str2 = (item != null) ? item.Name : Args[0]; Broadcast.Notice(Sender, CurrencySign, Config.GetMessage("Economy.Shop.Sell.ItemNotAvailable", Sender, null).Replace("%ITEMNAME%", str2), 5f); } } } else { Broadcast.Notice(Sender, "✘", Config.GetMessageCommand("Command.InvalidSyntax", Command, null), 5f); } } else { Broadcast.Notice(Sender, "✘", Config.GetMessage("Economy.Shop.Sell.NotAvailable", Sender, null), 5f); } }