Rewards

The QTRewardItem class contains contains a QTItem and an amount of the item that should be granted to the player.

Creating Rewards

Ensure your reward keys are unique. Reward keys can be used to check if a reward has already been granted.

A QTRewardItem object needs a reference to a QTItem and the quest it's being used for. The quest ID reference is not required if it's not being used for the context of a quest. The ItemObjectName should be the name of the item scriptable object.

var quest = QT.GetQuest("MyQuestKey");
var reward = new QTRewardItem(quest.ID, "MyRewardKey", "MyItemObject", 1);

Adding Rewards

Rewards can be added to quests.

quest.AddReward(reward);

Removing Rewards

You can remove a reward by the reward itself, the item object name or its index in the reward list of the quest.

quest.RemoveReward("MyItemObject");

Getting Rewards

Rewards are a part of quests. To get a reward, you must have a reference to a quest. You can get a reward by the name of the QTItem object.

QTRewardItem reward = quest.GetReward("MyItemName");

You can get the full list of reward items with the quest.rewards field.

Granting Rewards

If QT has been set up properly, rewards should be "granted" to the player automatically, however, the rewards still need to be manually added to the players inventory with whatever inventory system you're using.

The best way to handle this is by adding a reward received handler to the QT.onRewardReceived event.

private void Awake()
{
    QT.onRewardsReceived.AddListener(ReceiveRewards);
}

public void ReceiveRewards(List<QTRewardItem> rewards)
{
    // Your code here...
}

Expanded Example

The code below is just an example of how items could be added to your inventory. Actual code may vary.

   private void Awake()
   {
       QT.onRewardsReceived.AddListener(ReceiveRewards);
   }

   public void ReceiveRewards(List<QTRewardItem> rewards)
   {
       foreach (QTRewardItem reward in rewards)
       {
           var item = (MyItemType)reward.Item.customDataObject;
           var amount = reward.intValue;

           // Add a certain amount of the item to the inventory
           SomeInventorySystem.AddItem(reward, amount);
       }
   }

Grant with QTRewardItem

With a QTRewardItem, you can grant a reward with the method below. This will simply invoke the onRewardReceived event.

qtRewardItem.GrantReward();

Last updated