Stendhal Quest Coding: Difference between revisions
Content deleted Content added
imported>Ufizavipupu No edit summary |
imported>Kribbel m replace old link |
||
| (119 intermediate revisions by 12 users not shown) | |||
Line 1:
{{Navigation for Stendhal Top|Contributing}}
{{Navigation for Stendhal Contributors}}
{{ TODO | Update page for changes in quest coding }}
Line 18 ⟶ 19:
== Creating a quest skeleton ==
This tutorial is based on the quest
Quest files are put into the package games.stendhal.server.maps.quests. (If you are new to Java: this refers to the folder stendhal/src/games/stendhal/server/maps/quests).
Line 24 ⟶ 25:
Please create a new file in that folder called BeerForHayunn.java. (Note: The upper / lower case spelling is important, even on Microsoft Windows):
package games.stendhal.server.maps.quests;
Line 35 ⟶ 36:
public class BeerForHayunn extends AbstractQuest {
public static final String QUEST_SLOT =
@Override
Line 49 ⟶ 50:
@Override
public String getName() {
return
}
public List<String> getHistory(final Player player) {
final List<String> res = new ArrayList<String>();
return res;
}
}
Don't worry, if you don't understand a word of this; just copy it. We will explain the important parts and extend this skeleton in the following sections.
Line 58 ⟶ 64:
In order for the Stendhal server to pick up this file, it has to be registered in the file StendhalQuestSystem.java in the package games.stendhal.server.core.rp by adding two lines at the appropriate places:
import games.stendhal.server.maps.quests.BeerForHayunn;
Line 64 ⟶ 70:
loadQuest(new BeerForHayunn());
Of course in the case of this tutorial the two lines for BeerForHayunn are already there.
Line 70 ⟶ 76:
== Teaching the NPC to talk ==
Okay, we have now completed the preparation. Our first task is to get Hayunn to reply to the word
Therefore we add a new method called prepareQuestStep() at the end of the file BeerForHayunn, just above the last closing
public void prepareQuestStep() {
// get a reference to the Hayunn npc
SpeakerNPC npc = npcs.get(
// add a reply on the trigger phrase
npc.addReply(
}
There is one little step left before we can test it: We need to tell the server to execute our new method. There is already a method called
@Override
public void addToWorld() {
Line 94 ⟶ 100:
prepareQuestStep();
}
Okay, all done? Please start the server (depending on whether you are using an IDE or not you might have to compile or build first). Go to Hayunn and say
== Commonly used conversation phrases ==
Good, Hayunn now replies to the trigger
Let's adjust the above sample by using ''ConversationPhrases.QUEST_MESSAGES'' instead of the hard coded word
public void prepareQuestStep() {
// get a reference to the Hayunn npc
SpeakerNPC npc = npcs.get(
// add a reply on quest related trigger phrases to Hayunn
npc.addReply(ConversationPhrases.QUEST_MESSAGES,
}
Please compile and restart your server. Hayunn should now respond to
== Blue trigger words ==
As you probably know NPCs can say words in blue, words that they expect to be repeated by the player. We want to add such words for
So, how do we get the words colored blue? Simple, add a
public void prepareQuestStep() {
// get a reference to the Hayunn npc
SpeakerNPC npc = npcs.get(
// ask for a beer and explain it
npc.addReply(ConversationPhrases.QUEST_MESSAGES,
// explain blue words
npc.addReply(
npc.addReply(
// an example for escaping #
npc.addReply(
}
You know the drill: Compile, restart and try it out.
| |||