top of page

How I Used Design Patterns in Arcane Lands (Part IV)

Composite Pattern

Following the concept of Loot Tables in Loot Tables in Daniel Cook's Blog here , I apply the structural design pattern called Composite to implement ILootItem and LootTables.

Each ILootItem would have a private ItemCard and BaseWeight, as well as a public Weight. It also has main functions: Insert(), GetResult(). Decrement() and GetTotalWeight() are shown just for reminder purposes.

Insert() allows LootTables to have multiple ILootItems in its Loots reference. GetResult() for a basic LootItem would then only return its ItemCard, while a LootTable will randomly select an ILootItem from its Loots array and return that ILootItem’s GetResult(). This inheritance-based composite effectively allows LootTables to reference inner LootTables.

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page