How to manage a variety of Item Combinations?

I’m making a point-and-click adventure game with an inventory system. I’m managing the items using Godot’s resources, and I store the possible interactions with the objects in the world inside that resource.

However, I also want the player to be able to combine the items. My first idea was to:

  • store the list of items that the item can interact with inside the resource (like I do with the world objects),
  • make a function inside the item resource that receives an item and returns the new combined item / a line of text if the combination isn’t possible.

But I realized that if I do it this way, then it’s possible for two items in the combination to have differing results of the combination. Moreover, it’s not convenient to manage, because I’ll have to remember inside which item I stored the item combination for two items.

So, my question is: what is the best way to store the possible item combinations? Perhaps a different ItemCombination resource? Any suggestions are welcome!

Yes, your ItemCombination resource sounds like the Recipe data model that I once used to craft new items from ingredients. You can still keep references to the combinations on the items in your inventory to make displaying the combinations quicker.

I thought about making the ItemCombination resource, and I suppose I’d store the items being combined in an array, and the combined item as a separate value. My only issue with this approach is that I’d need too many ItemCombinations, since there may be a lot of items in the game. How do you manage such a large volume of them?

If I keep an array of ItemCombnations on an item, how do I pull the needed ItemCombination when two items interact with each other? Should I just iterate over the array of ItemCombinations until I find the one that matches the pair?

I guess I could make a Dictionary instead of an array on an Item, in a key : Item and value : ItemCombination format to avoid iterating. But that requires me to manually assign all of the values to each Dictionary in an item. Again, I don’t know how to make it more efficient. Any advice would be appreciated!

I’d say you code the ItemCombinations with references to the items and when you load the game you loo over each combination’s items where you pass the combination to the item.

# not real code
item:
  @export var combinations: Array[Combination]

combination:
  @export var items: Array[Item]
  func _init():
    for item in items:
     item.combinations.append(self)