-
Notifications
You must be signed in to change notification settings - Fork 12
How To Add a New Crafting Combination
All _gc
references in these examples are instances of a IGameController
More about inventory engine here.
To add a new crafting combination (recipe), go to InventoryItemsCombinatoryFactory class, and in its constructor you'll see all the combinations currently created.
Using simple fluent syntax, add a new one, like this:
CombinatoryItemBuilder<_type_of_resulted_item_>.Is<_item_one_>().And<_item_two_>()
If you want more than two items in a combination do the following:
CombinatoryItemBuilder<_type_of_resulted_item_>.Is<_item_one_>().Plus<_item_two_>().Plus<_item_three_>()/*...Plus<>...Plus<>*/.And<_item_four_>()
In any And, Is or Plus method, you can specify count of items needed:
CombinatoryItemBuilder<_type_of_resulted_item_>.Is<_item_one_>(5).And<_item_two_>(2)
Crafting recipe can result not in an item, but in action, like "water + lit torch = turn off the torch". Combinations with special actions are using this syntax:
CombinatoryItemBuilder<_item_type_on_which_the_action_is_executed_>.Is<_item_type_on_which_the_action_is_executed_>().Plus<_item_two_>().WithSpecialAction(_value_from_the_ItemsCombination.SpecialActions_enum_).AvailableWhen(items => _validation_function_that_checks_if_action_can_be_done_and_returns_bool_),
where items
is a collection of all player's inventory items. You can use ItemByType method to quickly get item of a needed type from this collection.
Similarly, any combination with special action can contain any number of items involved, and you also can specify items count as well.
The action itself should be handled in the InventorySpecialActionsProcessor class, where in the ProcessAction method you add your logic when combination.SpecialAction is equals to one you specified in a combination above.