Stendhal Quest Coding - Part 2: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Kymara
imported>Kribbel
m replace old link
 
(51 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Navigation for Stendhal Top}}
{{Navigation for Stendhal Top|Contributing}}
{{Navigation for Stendhal Contributors}}
{{Navigation for Stendhal Contributors}}


Line 76: Line 76:
As you can see, we now have to use "add()" instead of "addReply()" and that method has a lot more parameters.
As you can see, we now have to use "add()" instead of "addReply()" and that method 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.
We have predefined a number of states in the class [https://github.com/arianne/stendhal/blob/master/src/games/stendhal/server/entity/npc/ConversationStates.java ConversationStates] that you can and should use.


===Graphical representation===
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.
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.


== Conditions And Actions ==
== Conditions And Actions ==
Line 91: Line 92:
new LevelLessThanCondition(6),
new LevelLessThanCondition(6),
ConversationStates.IDLE,
ConversationStates.IDLE,
"Oh sorry, your have way too little experience.",
"Oh sorry, you have way too little experience.",
null);
null);
</source>
</source>
Line 113: Line 114:
== Teaching the NPC to remember the player ==
== Teaching the NPC to remember the player ==


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 beer 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:
The long term memory is called "quest slot". It is basically a hash table with 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">
<source lang="java">
public static final String QUEST_SLOT = "beer_hayunn";
public static final String QUEST_SLOT = "beer_hayunn";
</source>
</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.
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 are 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:
Having said that, let us make Hayunn check the quest state and reply accordingly:
Line 152: Line 153:
</source>
</source>


Note that in case the quest is already completed, Hayunn stay in ATTENING state.
Note that if the quest is already completed, Hayunn stays in ATTENDING 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:
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:
Line 175: Line 176:
== Third Part of this Tutorial ==
== Third Part of this Tutorial ==


Congratulations if you made it this far. You are now able to process basic conditions and actions. And you can handle both short and long term memory. The third and last part of this tutorial will explain how you accept the quest item and reward the player. It described some advanced techniques, too. Please make sure the steps on this page work before you continue to [[Stendhal Quest Coding - Part 3|the third part of this tutorial]].
Congratulations if you made it this far. You are now able to process basic conditions and actions. And you can handle both short and long term memory. The third and last part of this tutorial will explain how you accept the quest item and reward the player. It describes some advanced techniques, too. Please make sure the steps on this page work before you continue to [[Stendhal Quest Coding - Part 3|the third part of this tutorial]].


[[Category:Stendhal]]
[[Category:Stendhal]]