Skip to content

Instantly share code, notes, and snippets.

@ajcomeau
Created December 17, 2025 16:45
Show Gist options
  • Select an option

  • Save ajcomeau/4374aca2182f418d9a9bd621c65f0ef5 to your computer and use it in GitHub Desktop.

Select an option

Save ajcomeau/4374aca2182f418d9a9bd621c65f0ef5 to your computer and use it in GitHub Desktop.
InventoryDisplay() function from Rogue C#.
public static List<InventoryLine> InventoryDisplay(List<Inventory> PlayerInventory)
{
char charID = 'a';
// Get the player's current inventory in a grouped format.
List<InventoryLine> lines = new List<InventoryLine>();
// Get groupable identified inventory.
var groupedInventory =
(from invEntry in PlayerInventory
where invEntry.IsGroupable && invEntry.IsIdentified
group invEntry by invEntry.RealName into itemGroup
select itemGroup).ToList();
// Add groupable non-identified inventory.
...
// Get non-groupable identified
...
// Create a unique list of grouped items and count of each.
foreach (var itemGroup in groupedInventory)
lines.Add(new InventoryLine
{ Count = itemGroup.Count(), InvItem = itemGroup.First() });
// Add non-grouped items.
foreach (var invEntry in individualItems)
lines.Add(new InventoryLine { Count = 1, InvItem = invEntry });
// Order new list by item category.
lines = lines.OrderBy(x => x.InvItem.ItemType).ToList();
// Call the ListingDescription function to get a finished description.
foreach (InventoryLine line in lines)
{
line.ID = charID;
line.Description = line.ID + ".) "
+ ListingDescription(line.Count, line.InvItem);
charID++;
}
return lines;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment