Where Is The Reward Actually Distributed?

Announcements, support questions, and discussion for Quest Machine.
Post Reply
Rhaelix
Posts: 4
Joined: Wed Mar 25, 2020 8:39 am

Where Is The Reward Actually Distributed?

Post by Rhaelix »

Hello,

I am absolutely loving Quest Machine. I had been using my own procedural quest generator, but it was not nearly as robust as this one. While I have the generator and UIs running well up to a point in my project now, I am attempting to find the exact point in Quest Machines process for the generated quests where the rewards (XpRewardSystem) is actually rewarded in Quest Machines process.

As a test, I have successfully sent the xp data to my QuestManager from within XpRewardSystem and distributed to all of the players from there, but that is not the purpose of the XpRewardSystem class, since it fires the xp text on generation and after.

I am have a time trying to trace down the single point where quest reward distribution is actually concurring before handing the rest of my reward system over to Quest Machine and linking my own quest complete events to it.

Thank you. :D
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Where Is The Reward Actually Distributed?

Post by Tony Li »

Hi,

When Quest Machine generates a quest, it computes a point value for the quest.

The point value is based on the count and level of the goal entity -- for example a quest to kill five level 3 orcs would be 15 points (5 * 3). (You can override all of this. If you need to override how points are determined or how entity levels are determined, let me know.)

Then the generator calls the DetermineReward() method on each of the quest giver's reward systems (e.g., XPRewardSystem).

It's up to each reward system to:
  • Add text to the quest, typically in the Offer Text section.
  • Add actions to the quest, typically in the Successful state's Actions list.
  • Optionally "use up" points and return the number of points left after this reward. For example, a reward system to give 5 gold could use up 5 points.
This is all done at the time the quest is generated. Since the reward system sets up the Actions list to run actions when the quest becomes successful, the reward system itself doesn't need to be involved any further after generation.

Quest Machine's XPRewardSystem is mainly just an example, but you can also use it for production in a real game. It does the following:
  • Computes xp based on the points specified, multiplied by the entity's XP reward modifier.
  • Adds "(xp) XP" to the quest's Offer Text.
  • Add an action to the Successful state's Actions list that sends the message "Add XP" + xp.
  • Doesn't use up any points. Returns the original points value provided to it.
If you want to use it in your game, you can add a message handler that listens for "Add XP", such as:

Code: Select all

using UnityEngine;
using PixelCrushers;
public class Player : MonoBehaviour, IMessageHandler
{
    public int currentXP;
    
    void OnEnable()
    {
        MessageSystem.AddListener(this, "Add XP", null);
    }
    
    void OnDisable()
    {
        MessageSystem.RemoveListener(this, "Add XP", null);
    }
    
    void OnMessage(MessageArgs messageArgs)
    {
        if (messageArgs.message == "Add XP")
        {
            currentXP += messageArgs.intValue;
        }
    }
}
Of course, you don't have to use the message system. You could write a custom quest action. There's a starter template in the Templates folder. This is what the third party integrations do. For example, inventory system integrations add a custom quest action to give items specific to the inventory system. Their rewards systems add this action to generated quests.
Rhaelix
Posts: 4
Joined: Wed Mar 25, 2020 8:39 am

Re: Where Is The Reward Actually Distributed?

Post by Rhaelix »

Tony,

That was an excellent and thorough breakdown. I appreciate the time and effort put into it. The message listener approach worked perfectly and has helped me better understand how to fully integrate the rest of the QM system into my own existing project.

Thank you!
User avatar
Tony Li
Posts: 21925
Joined: Thu Jul 18, 2013 1:27 pm

Re: Where Is The Reward Actually Distributed?

Post by Tony Li »

Happy to help!
Post Reply