Custom Quest Reward Handler
v4.0
When using the ItemObjectReward
type, you will need to determine how the items created are handled. This is entirely dependent on your inventory system, which is likely different from other developers systems.
View the Quest Repository - Party Based RPG Variant
object in the world scene of the Party Based RPG demo game. This has an additional class: QuestRewardHandler
Quest Reward Handler
ItemObjectReward.cs
The GiveReward()
method on ItemObjectReward
calls HandleItemObjectReward()
on the questRepository
.
QuestRepository.cs
QuestRepository
has a IHandleQuestRewards
variable. This is populated at start, if you have another class on the object that implements IHandleQuestRewards
.
If so, when HandleItemObjectReward()
is called, the custom reward handler is used: HandleItemObjectReward()
with the GameItemObjectList
with all of the items that need to be handled attached.
Your custom reward handler just has to iterate through the GameItemObjectList
and do something to each item. That is probably something you've already figured out how to do for your inventory system 😀
QuestRewardHandler (IHandleQuestRewards
)
IHandleQuestRewards
)You can name your handler something different, if you'd like, but it must be a Monobehaviour
which implements IHandleQuestRewards
.
In the class from the Party Based RPG demo game, we start a Coroutine
to handle the items one by one. This demo uses the Game Modules Inventory System, and each ItemObject
that is spawned will be shown as a "Held Item" on the screen, following the mouse position.
The player can choose to click the world to "Drop" the item into it, or select a player portrait by clicking the portrait or typing "1", "2", "3", or "4". If the player inventory can hold the item, it will be placed there.
After one of those actions occurs, the coroutine will move to the next item in the list, until there is no more.
If you're using the Game Modules Inventory System, then feel free to use this QuestRewardHandler
for your project as well. Otherwise, you'll need to write your own.
Hopefully you've realized that it's not that challenging to create your own handler!
Last updated