Stendhal Quest Coding - Part 2: Difference between revisions

From Arianne
Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
imported>Hendrik Brummermann
Line 39: Line 39:
You may have noticed in the above diagram that there is something called "ANY". This is a special "state" which allows the triggers associated with the outgoing arrows to be triggered in any state. You should not use this except for "bye" which should always work.
You may have noticed in the above diagram that there is something called "ANY". This is a special "state" which allows the triggers associated with the outgoing arrows to be triggered in any state. You should not use this except for "bye" which should always work.


Okay, enough theory for now, lets write some code:
{{TODO|

* code
<source lang="java">
* point to ConverstationStates
public void prepareQuestStep() {
* View Transitions with Graphviz

}}
// get a reference to the Hayunn npc
SpeakerNPC npc = npcs.get("Hayunn Naratha");

// ...

// if the player asks for a quest, go to state QUEST_OFFERED
npc.add(ConversationStates.ATTENDING,
ConversationPhrases.QUEST_MESSAGES,
null,
ConversationStates.QUEST_OFFERED,
"My mouth is dry, but I can't be seen to abandon this teaching room! Could you bring me some beer from the tavern?",
null);

// in state QUEST_OFFERED, accept "yes" and go back to ATTENDING
npc.add(
ConversationStates.QUEST_OFFERED,
ConversationPhrases.YES_MESSAGES,
null,
ConversationStates.ATTENDING,
"Thanks! I'll be right here, waiting. And guarding, of course.",
null);

// in state QUEST_OFFERED, accept "no" and go back to ATTENDING
npc.add(
ConversationStates.QUEST_OFFERED,
ConversationPhrases.NO_MESSAGES,
null,
ConversationStates.ATTENDING,
"Oh, well forget it then. I guess I'll just hope for it to start raining, and then stand with my mouth open.",
null);
}
</source>

As you can see, we now have to use "add()" instead of "addReply()" and that methods has a lot more parameters.

We have predefined a number of states in the class [http://arianne.cvs.sf.net/viewvc/arianne/stendhal/src/games/stendhal/server/entity/npc/ConversationStates.java?view=markup ConverstationStates] that you can and should use.

There is one last thing that makes your life easier: If you are using Linux, have the graphviz package installed and you are an admin in game, you can select "View Transitions" in the right click menu of NPCs. This will generate an image of the current transition graph very similar to the images above.


== Teaching the NPC to remember the player ==
== Teaching the NPC to remember the player ==

Revision as of 14:14, 24 February 2010


Stendhal Quests



This page is currently reworked. You can find the old content on the talk page

You may want to read the first part of the Stendhal Quest Coding tutorial first.

If you have ideas for new quests or are interested in helping to refine quest ideas, please have a look at the Quest Contributor's Guide or the Stendhal Quest Ideas.

Teaching the NPC to ask the players whether they will do the quest

Now we want Hayunn to ask the player whether he is going to help:

  • quest: My mouth is dry, but I can't be seen to abandon this teaching room! Could you bring me some beer from the tavern?
    • yes: Thanks! I'll be right here, waiting. And guarding, of course.
    • no: Oh, well forget it then. I guess I'll just hope for it to start raining, and then stand with my mouth open.

As a little exercise you can code this part to check whether you understood the first part of this tutorial.

There is, however, a small problem with the current solution: There can only be one reply for "yes" and "no". So the NPC can only ask one single question in order to be able to process the answers.

Fortunately there is a solution: The NPCs needs to remember the state of the conversation:

Currently our NPC knows two states: IDLE for walking around and ATTENDING for talking to a player. You can change between states by talking to the NPC. So if the NPC is IDLE, it will accept "hi" and move on to the ATTENING state. If you say "hi" again, nothing will happen because "hi" is unknown in this state. The NPC, however, will now reply to "job" and "help". You can end the conversation with "bye" which will cause the NPC to return to IDLE (and start walking around again).

So, lets return to our example. We want the NPC to reply to "yes" and "no" but only after the quest question was asked. So we add a third state called QUEST_OFFERED. When the player says "quest", the NPC goes to that state. On "yes" or "no" it returns to ATTENDING.

You may have noticed in the above diagram that there is something called "ANY". This is a special "state" which allows the triggers associated with the outgoing arrows to be triggered in any state. You should not use this except for "bye" which should always work.

Okay, enough theory for now, lets write some code:

<source lang="java"> public void prepareQuestStep() {

   // get a reference to the Hayunn npc
   SpeakerNPC npc = npcs.get("Hayunn Naratha");
   // ...
   // if the player asks for a quest, go to state QUEST_OFFERED
   npc.add(ConversationStates.ATTENDING,
       ConversationPhrases.QUEST_MESSAGES, 
       null,
       ConversationStates.QUEST_OFFERED, 
       "My mouth is dry, but I can't be seen to abandon this teaching room! Could you bring me some beer from the tavern?",
       null);
   // in state QUEST_OFFERED, accept "yes" and go back to ATTENDING
   npc.add(
       ConversationStates.QUEST_OFFERED,
       ConversationPhrases.YES_MESSAGES,
       null,
       ConversationStates.ATTENDING,
       "Thanks! I'll be right here, waiting. And guarding, of course.",
       null);
   // in state QUEST_OFFERED, accept "no" and go back to ATTENDING
   npc.add(
       ConversationStates.QUEST_OFFERED,
       ConversationPhrases.NO_MESSAGES,
       null,
       ConversationStates.ATTENDING,
       "Oh, well forget it then. I guess I'll just hope for it to start raining, and then stand with my mouth open.",
       null);

} </source>

As you can see, we now have to use "add()" instead of "addReply()" and that methods has a lot more parameters.

We have predefined a number of states in the class ConverstationStates that you can and should use.

There is one last thing that makes your life easier: If you are using Linux, have the graphviz package installed and you are an admin in game, you can select "View Transitions" in the right click menu of NPCs. This will generate an image of the current transition graph very similar to the images above.

Teaching the NPC to remember the player

TODO:

  • ChatAction
  • ChatCondition

Rewarding the player

TODO:

  • MultiAction

Quest Documentation

TODO:

  • should be done much earlier usually
  • content should be done earlier (see contributor's guide

Further Reading

TODO: