final SpeakerNPC npc = npcs.get("Ritati Dragontracker");
// ask for joke when prompted for needle
npc.add(ConversationStates.ATTENDING,
Arrays.asList("needle", "magical", "magical needle", "ida", "cloak", "mithril cloak", "specials"),
new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_needle"),
ConversationStates.ATTENDING,
"Ok, but I have a little rule: never do important business with someone unless"
+ "they can make you laugh. So, come back to tell me a #joke and I will sell you a needle.",
null);
// ask for joke when player says joke
npc.add(ConversationStates.ATTENDING,
"joke",
new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "need_needle"),
ConversationStates.QUESTION_1,
"Ok, lets hear your joke then. and I hope it's from the book in Nalwor Library, that's my favourite. What joke did you choose?",
null);
npc.add(ConversationStates.QUESTION_1, "", null,
ConversationStates.QUEST_ITEM_QUESTION, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
for (int i = 1; i < 9; i++) {
String joke = jokes.get(i);
final Sentence answer = sentence.parseAsMatchingSource();
final Sentence expected = ConversationParser.parse(joke, new SimilarExprMatcher());
if (answer.matchesFull(expected)) {
final String[] questslot = player.getQuest(mithrilcloak.getQuestSlot()).split(";");
if (questslot.length > 2) {
// if the split worked, we had stored a needle number before and we need to store it again
int needles = Integer.parseInt(questslot[1]);
int saidjoke = Integer.parseInt(questslot[2]);
if (i == saidjoke) {
npc.say("You told me that joke last time, come back with a new one! Bye.");
npc.setCurrentState(ConversationStates.IDLE);
// // stop looking through the joke list
return;
} else {
player.setQuest(mithrilcloak.getQuestSlot(), "told_joke;" + Integer.toString(needles) + ";" + Integer.toString(i));
}
} else {
player.setQuest(mithrilcloak.getQuestSlot(), "told_joke;" + Integer.toString(i));
}
// this might have been his favourite joke, which is determined randomly
if (Rand.randUniform(1, 8) == i) {
npc.say("That's the funniest joke I ever heard! I think it's my favourite of the moment. Here, have your needle for free... and then get out of here, You've been here far too long already.");
new EquipItemAction("magical needle", 1, true).fire(player, sentence, npc);
npc.setCurrentState(ConversationStates.IDLE);
// // stop looking through the joke list
return;
} else {
npc.say("*guffaws* Alright, lets get on with business. A magical needle costs "
+ Integer.toString(NEEDLE_COST) + " pieces of money. Do you want to buy one now?");
// stop looking through the joke list
npc.setCurrentState(ConversationStates.QUEST_ITEM_QUESTION);
return;
}
}
}
if (ConversationPhrases.GOODBYE_MESSAGES.contains(sentence.getTriggerExpression().getNormalized())) {
npc.say("Ok, bye then.");
npc.setCurrentState(ConversationStates.IDLE);
} else if (sentence.getTriggerExpression().getNormalized().equals("none")) {
npc.say("Ok, bye.");
npc.setCurrentState(ConversationStates.IDLE);
} else {
npc.say("Sorry, that joke just isn't funny. go back to Nalwor library and get another.");
npc.setCurrentState(ConversationStates.IDLE);
}
}
});
// offer needle when prompted if they already told a joke
npc.add(ConversationStates.ATTENDING,
Arrays.asList("needle", "magical", "magical needle", "ida", "cloak", "mithril cloak", "specials"),
new QuestStateStartsWithCondition(mithrilcloak.getQuestSlot(), "told_joke"),
ConversationStates.QUEST_ITEM_QUESTION,
"I have some magical needles but they cost a pretty penny, "
+ Integer.toString(NEEDLE_COST) + " pieces of money to be precise. Do you want to buy one?",
null);