npc.add(
ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestStartedCondition(QUEST_SLOT),
new NotCondition(new QuestStateStartsWithCondition(QUEST_SLOT, "done"))),
ConversationStates.QUESTION_1,
"Welcome back! I hope you collected some #ingredients for the soup, or #everything.",
null);
// player asks what exactly is missing
npc.add(ConversationStates.QUESTION_1, "ingredients",
new AndCondition(new QuestStartedCondition(QUEST_SLOT), new NotCondition(new QuestStateStartsWithCondition(QUEST_SLOT, "done"))),
ConversationStates.QUESTION_1, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
final List<String> needed = missingFood(player, true);
npc.say("I still need "
+ Grammar.quantityplnoun(needed.size(),
"ingredient", "one") + ": "
+ Grammar.enumerateCollection(needed)
+ ". Did you bring anything I need?");
}
});
// player says he has a required ingredient with him
npc.add(ConversationStates.QUESTION_1,
ConversationPhrases.YES_MESSAGES, null,
ConversationStates.QUESTION_1, "What did you bring?", null);
for(final String itemName : NEEDED_FOOD) {
npc.add(ConversationStates.QUESTION_1, itemName, null,
ConversationStates.QUESTION_1, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
List<String> missing = missingFood(player, false);
if (missing.contains(itemName)) {
if (player.drop(itemName)) {
// register ingredient as done
final String doneText = player.getQuest(QUEST_SLOT);
player.setQuest(QUEST_SLOT, doneText + ";" + itemName);
// check if the player has brought all Food
missing = missingFood(player, true);
if (!missing.isEmpty()) {
npc.say("Thank you very much! What else did you bring?");
} else {
player.addKarma(5.0);
player.addXP(20);
/*
* place soup after XP added otherwise
* the XP change MIGHT change level and
* player MIGHT gain health points which
* changes the base HP, which is desired
* to be accurate for the place soup
* stage
*/
placeSoupFor(player);
player.healPoison();
npc.say("The soup's on the table for you. It will heal you. "
+ "My magical method in making the soup has given you a little karma too.");
player.setQuest(QUEST_SLOT, "done;"
+ System.currentTimeMillis());
player.notifyWorldAboutChanges();
npc.setCurrentState(ConversationStates.ATTENDING);
}
} else {
npc.say("Don't take me for a fool, traveller. You don't have "
+ Grammar.a_noun(itemName)
+ " with you.");
}
} else {
npc.say("You brought me that ingredient already.");
}
}
});
}
// Perhaps player wants to give all the ingredients at once
npc.add(ConversationStates.QUESTION_1, "everything",
null,
ConversationStates.QUESTION_1,
null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence,
final EventRaiser npc) {
checkForAllIngredients(player, npc);
}
});
// player says something which isn't in the needed food list.
npc.add(ConversationStates.QUESTION_1, "",
new NotCondition(new TriggerInListCondition(NEEDED_FOOD)),
ConversationStates.QUESTION_1,
"I won't put that in your soup.", null);
// allow to say goodbye while Helena is listening for food names
npc.add(ConversationStates.QUESTION_1, ConversationPhrases.GOODBYE_MESSAGES, null,
ConversationStates.IDLE, "Bye.", null);
npc.add(ConversationStates.ATTENDING, ConversationPhrases.NO_MESSAGES,
new AndCondition(new QuestStartedCondition(QUEST_SLOT), new NotCondition(new QuestStateStartsWithCondition(QUEST_SLOT, "done"))),
ConversationStates.ATTENDING,
"I'm not sure what you want from me, then.", null);
// player says he didn't bring any Food to different question
npc.add(ConversationStates.QUESTION_1, ConversationPhrases.NO_MESSAGES,
new AndCondition(new QuestStartedCondition(QUEST_SLOT), new NotCondition(new QuestStateStartsWithCondition(QUEST_SLOT, "done"))),
ConversationStates.ATTENDING, "Okay then. Come back later.",
null);
}