// player returns while quest is still active
npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestActiveCondition(QUEST_SLOT)),
ConversationStates.QUESTION_1, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
raiser.say("Hi again! I still need "
+ player.getQuest(QUEST_SLOT)
+ " blue elven "
+ Grammar.plnoun(
MathHelper.parseInt(player.getQuest(QUEST_SLOT)),
"cloak") + ". Do you have any for me?");
}
});
// player returns after finishing the quest
npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestCompletedCondition(QUEST_SLOT)),
ConversationStates.ATTENDING,
"Welcome! Thanks again for those cloaks.", null);
// player says he doesn't have any blue elf cloaks with him
npc.add(ConversationStates.QUESTION_1, ConversationPhrases.NO_MESSAGES, null,
ConversationStates.ATTENDING, "Too bad.", null);
// player says he has a blue elf cloak with him but he needs to bring more than one still
// could also have used GreaterThanCondition for Quest State but this is okay, note we can only get to question 1 if we were active
npc.add(ConversationStates.QUESTION_1,
ConversationPhrases.YES_MESSAGES,
new AndCondition(new QuestNotInStateCondition(QUEST_SLOT, "1"), new PlayerHasItemWithHimCondition("blue elf cloak")),
ConversationStates.QUESTION_1, null,
new MultipleActions(
new DropItemAction("blue elf cloak"),
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
// find out how many cloaks the player still has to
// bring. incase something has gone wrong and we can't parse the slot, assume it was just started
final int toBring = MathHelper.parseIntDefault(player.getQuest(QUEST_SLOT), REQUIRED_CLOAKS) -1;