public static void PickInventoryItem(CEnums.InvCategory category, bool selling) { // Select an object to interact with in your inventory // If "selling == True" that means that items are being sold, and not used. while (true) { CMethods.PrintDivider(); List <string> item_ids = DisplayInventory(category, selling); while (true) { string chosen = CMethods.FlexibleInput("Input [#] (or type 'exit'): ", item_ids.Count).ToLower(); try { chosen = item_ids[int.Parse(chosen) - 1]; } catch (Exception ex) when(ex is FormatException || ex is ArgumentOutOfRangeException) { if (CMethods.IsExitString(chosen)) { CMethods.PrintDivider(); return; } continue; } // If you're selling items at a general store, you have to call a different function if (selling) { SellItem(chosen); if (!GetInventory()[category].Any(x => x.IsImportant)) { return; } } else { PickInventoryAction(chosen); if (GetInventory()[category].Count == 0) { return; } } break; } } }
public static List <string> DisplayInventory(CEnums.InvCategory category, bool selling) { List <string> id_inventory = GetInventory()[category].Select(x => x.ItemID).ToList(); List <Tuple <string, string, int> > quantity_inv = new List <Tuple <string, string, int> >(); // This creates a tuple of every item in the inventory and its quantity, and adds it to quantity_inv id_inventory.Distinct().ToList().ForEach(x => quantity_inv.Add(new Tuple <string, string, int>(ItemManager.FindItemWithID(x).ItemName, x, id_inventory.Count(y => y == x)))); if (selling) { /* * List<Tuple<string, int>> sellable_inv = quantity_inv.Where(x => !ItemManager.FindItemWithID(x.Item1).IsImportant).ToList(); * * int padding; * * try * { * padding = sellable_inv.Select(x => $"{x.Item1} x {x.Item2}".Length).Max(); * } * * catch (ArgumentException ex) * { * padding = 1; * } * * int extra_pad = sellable_inv.Select(x => x.Item1); * /* * sellable_inv = [it for it in quantity_inv if not find_item_with_id(it[1]).imp] * * try: * padding = len(max([it2[0] + f" x {it2[2]}" for it2 in sellable_inv], key= len)) * * except ValueError: * padding = 1 * * extra_pad = len(str(len([it3[0] for it3 in sellable_inv]) + 1)) * * print(f'{vis_cat}:') * * highest_charisma = max([pcu.attributes['cha'] for pcu in [units.player, * units.solou, * units.chili, * units.chyme, * units.adorine, * units.parsto]]) - 1 * * for num, b in enumerate(sellable_inv) : * sell_value = find_item_with_id(b[1]).value//5 * modified_value = math.ceil(max([sell_value * (1 + 0.01 * highest_charisma), sell_value * 2])) * * fp = '-'*(padding - (len(b[0]) + len(f" x {b[2]}")) + (extra_pad - len(str(num + 1)))) * print(f" [{num + 1}] {b[0]} x {b[2]} {fp}--> {modified_value} GP each") * * return [x[1] for x in sellable_inv] */ return(id_inventory); } else { Console.WriteLine($"{category.EnumToString()}: "); int counter = 0; foreach (Tuple <string, string, int> item in quantity_inv) { Console.WriteLine($" [{counter + 1}] {item.Item1} x {item.Item3}"); counter++; } return(quantity_inv.Select(x => x.Item2).ToList()); } }
public static void RemoveItemFromInventory(string item_id) { // Removes the item_id from the inventory CEnums.InvCategory item_cat = ItemManager.FindItemWithID(item_id).Category; inventory[item_cat].Remove(item_id); }
/* =========================== * * METHODS * * =========================== */ public static void AddItemToInventory(string item_id) { // Adds the item_id to the inventory CEnums.InvCategory item_cat = ItemManager.FindItemWithID(item_id).Category; inventory[item_cat].Add(item_id); }