public static void SetItemList(string[] items) { foreach (string item in items) { // Make sure that the item exists before trying to create it string outString; int outInt; if (!addedItems.Contains(item) && !NametoDesc.TryGetValue(item, out outString) && !NametoShortName.TryGetValue(item, out outString) && !NametoType.TryGetValue(item, out outInt) && !NametoPrice.TryGetValue(item, out outInt)) { throw new CYFException("Inventory.SetInventory: The item \"" + item + "\" was not found." + (UnitaleUtil.IsOverworld ? "" : "\n\nAre you sure you called Inventory.AddCustomItems first?")); } } inventory = new List <UnderItem>(new UnderItem[] { }); for (int i = 0; i < items.Length; i++) { if (i == inventorySize) { UnitaleUtil.Warn("The inventory can only contain " + inventorySize + " items, yet you tried to add the item \"" + items[i] + "\" as item number " + (i + 1) + "."); break; } inventory.Add(new UnderItem(items[i])); } }
public static bool AddItem(string Name) { if (inventory.Count == inventorySize) { return(false); } // Make sure that the item exists before trying to create it string outString; int outInt; if (!addedItems.Contains(Name) && !NametoDesc.TryGetValue(Name, out outString) && !NametoShortName.TryGetValue(Name, out outString) && !NametoType.TryGetValue(Name, out outInt) && !NametoPrice.TryGetValue(Name, out outInt)) { throw new CYFException("Inventory.AddItem: The item \"" + Name + "\" was not found." + (UnitaleUtil.IsOverworld ? "" : "\n\nAre you sure you called Inventory.AddCustomItems first?")); } inventory.Add(new UnderItem(Name)); return(true); }
public static void SetItemList(string[] items = null) { foreach (string item in items) { // Make sure that the item exists before trying to create it string outString = ""; int outInt = 0; if (!addedItems.Contains(item) && !NametoDesc.TryGetValue(item, out outString) && !NametoShortName.TryGetValue(item, out outString) && !NametoType.TryGetValue(item, out outInt) && !NametoPrice.TryGetValue(item, out outInt)) { throw new CYFException("Inventory.SetInventory: The item \"" + item + "\" was not found.\n\nAre you sure you called Inventory.AddCustomItems first?"); } } inventory = new List <UnderItem>(new UnderItem[] { }); if (items != null) { for (int i = 0; i < items.Length; i++) { if (i == inventorySize) { UnitaleUtil.WriteInLogAndDebugger("[WARN]The inventory can only contain " + inventorySize + " items, yet you tried to add the item \"" + items[i] + "\" as item number " + (i + 1) + "."); } else { // Search through addedItemsTypes to find the type of the new item int type = 0; // Get the index of the new item in addedItems for (int j = 0; j < addedItems.Count; j++) { if (addedItems[j] == items[i]) { type = addedItemsTypes[j]; } } inventory.Add(new UnderItem(items[i])); } } } }