Skip to content
deanljohnson edited this page Jun 26, 2015 · 2 revisions

Strategies

Strategies represent a skeleton-like structure to a quest. With a strategy, you define actions to be taken to complete a quest on a very generic level (ex: goto-kill-reportBack), and the ways in which those actions tie together (ex: goto(enemy.location)-kill(enemy)-reportBack(questGiver)). They tie in to motivations by being the way in which a npc can have a motivation satisfied or fulfilled. This is where most of the work for building quests goes.

A strategy definition has 3 required parts, and some optional ones as well:

  1. Name
  2. Tag Assignments
  3. Actions and their tagged parameters
  4. (optional) Action Descriptions

Name

Name is simply an identifier you give to a strategy, such as:

//killEnemy is the name
questGen.strategies.killEnemy = QUESTIFY.createStrategy(...);

Tag Assignments

Tag assignments are used to assign parameters to your actions. You do this by passing an array of strings as the first argument to createStrategy(). For a full description of tag assignment and it's options, see the relevant page on the right. Here is a simple example:

questGen.strategies.killEnemy = QUESTIFY.createStrategy(["[ENEMY]:'enemy'"], {...});

[ENEMY] tells Questify to select an object from the ENEMY array of the object you pass in to generateQuest(). 'enemy' is the tag that the object is assigned to.

Actions and Tagged Parameters

Those tags are then used when defining the actions for this strategy and their parameters:

questGen.strategies.killEnemy = QUESTIFY.createStrategy(["[ENEMY]:'enemy'"], 
    [{action: 'goto', actionArgs = [['pc', 'enemy:location']]},
     {action: 'kill', actionArgs = [['pc', 'enemy:location'], ['enemy']]},
     {action: 'report', actionArgs = [['pc', 'giver:location'], ['giver', 'enemy']]}]);

Here, we only had to define one tag: enemy. Questify automatically defines 3 tags, 2 of which are used here: pc (player character), giver (the quest giver), start (the location where the quest started).

Action Descriptions

Descriptions can be given to actions during the strategy definition phase. These descriptions will be easily accessible through the Quest object that Questify generates. To assign a description, you simply add a description string to the action as you pass it to createStrategy as shown here:

questGen.strategies.killEnemy = QUESTIFY.createStrategy(["[ENEMY]:'enemy'"], 
    [{action: 'goto', actionArgs = [['pc', 'enemy:location']],
         description: "Go to [enemy:location:name]"},
     {action: 'kill', actionArgs = [['pc', 'enemy:location'], ['enemy']],
         description: "Kill [enemy:name], mercilessly"},
     {action: 'report', actionArgs = [['pc', 'giver:location'], ['giver', 'enemy']],
         description: "Report back to [giver:name]"}]);

As you can see, we can still use the tags that we define as the first argument to createStrategy and can access the properties of the tagged object as well. We define descriptions at this stage and not on the action themselves for two reasons:

  1. Internally, actions are treated like static classes. They cant keep track of data themselves, such as condition function parameters and tags used in descriptions. Quest instances handle that.
  2. We can re-use the same action for multiple circumstances. In the example above, the description says to kill the enemy mercilessly, but what if we had a quest that had the player kill someone they had a personal connection to. In that case, this description would not make sense. So, by assigning the description to the strategy, we can tailor the description to match the desired feel of a quest.

You can then access these strategies from the object returned from generateQuest:

var questGen = QUESTIFY.createQuestGenerator();
...
var quest = questGen.generateQuest(...);

console.log( quest.getActionDescription(0) ); //Logs, for example, "Go to Home"

quest.setActionDescription( 0, "Go to Work" );
console.log( quest.getActionDescription(0) ); //Logs "Go to Work"

quest.setActionDescription( 0, "Go to [enemy:location:name]");
console.log( quest.getActionDescription(0) ); //Logs "Go to [enemy:location:name]"

Descriptions are accessed and set with an index that relates to the actions place in the overall quest path. Note that at this point you can not access the tags used during strategy creation, as shown in the last two lines.

Clone this wiki locally