Stendhal Quest Coding - Part 2: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
imported>Hendrik Brummermann
Line 117: Line 117:


Okay, lets get back to the topic: Hayunn needs a long term memory in order to only accept one bear per player. After all he is on duty and a totally drunken teacher is no good...
Okay, lets get back to the topic: Hayunn needs a long term memory in order to only accept one bear per player. After all he is on duty and a totally drunken teacher is no good...

The long term memory is called "quest slot". It is basically a hash table which one row per quest. You might remember that the following line in the template we added at the very beginning of this tutorial:
<source lang="java">
public static final String QUEST_SLOT = "beer_hayunn";
</source>

That's the name of the slot we are using. It has to be unique, but other than that, we can write anything we want in there. There are, however, two conventions that make things a lot easier: Multiple values are separated by an ";" without space. And the terms "done" and "rejected" are used to denote a complete or rejected quest. There is a number of predefined chat conditions and actions that work based on those conventions.

Having said that, let us make Hayunn check the quest state and reply accordingly:


<source lang="java">
<source lang="java">
Line 144: Line 153:
// ...
// ...
}
}
</source>


Note that in case the quest is already completed, Hayunn stay in ATTENING state.

The next step is to save that the quest was completed. We take a simple approach for the moment and only check that the player owns a beer:

<source lang="java">
private void prepareBringingStep() {
private void prepareBringingStep() {
SpeakerNPC npc = npcs.get("Hayunn Naratha");
SpeakerNPC npc = npcs.get("Hayunn Naratha");


// if the players says "beer" and owns one, we set the quest slot to "done".
npc.add(
npc.add(
ConversationStates.QUEST_ITEM_BROUGHT,
ConversationStates.ATTENDING,
ConversationPhrases.YES_MESSAGES,
"beer",
new PlayerHasItemWithHimCondition("beer"),
new PlayerHasItemWithHimCondition("beer"),
ConversationStates.ATTENDING,
ConversationStates.ATTENDING,
Line 159: Line 175:


Of course we need to add a call to <code>prepareBringingStep();</code> in <code>addToWorld</code>.
Of course we need to add a call to <code>prepareBringingStep();</code> in <code>addToWorld</code>.

{{TODO|
* Explain quest slot concept
* Explain multi value fields in quest slot
}}


== Rewarding the player ==
== Rewarding the player ==