-
-
Save ajcomeau/4374aca2182f418d9a9bd621c65f0ef5 to your computer and use it in GitHub Desktop.
InventoryDisplay() function from Rogue C#.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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