// 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_2,
"Welcome back! Have you brought any #cloaks with you?", null);
// player asks what exactly is missing
npc.add(ConversationStates.QUESTION_2,
"cloaks",
null,
ConversationStates.QUESTION_2,
null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser entity) {
final List<String> needed2 = missingcloaks2(player, true);
entity.say("I want "
+ Grammar.quantityplnoun(needed2.size(), "cloak", "a")
+ ". That's "
+ Grammar.enumerateCollection(needed2)
+ ". Did you bring any?");
}
@Override
public String toString() {
return "enumerate missingcloaks2";
}
});
// player says he has a required cloak with him
npc.add(ConversationStates.QUESTION_2,
ConversationPhrases.YES_MESSAGES,
null,
ConversationStates.QUESTION_2,
"Woo! What #cloaks did you bring?",
null);
for(final String itemName : NEEDEDCLOAKS2) {
npc.add(ConversationStates.QUESTION_2,
itemName,
null,
ConversationStates.QUESTION_2,
null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser entity) {
List<String> missing = missingcloaks2(player, false);
if (missing.contains(itemName)) {
if (player.drop(itemName)) {
// register cloak as done
final String doneText = player.getQuest(QUEST_SLOT);
player.setQuest(QUEST_SLOT, doneText + ";" + itemName);
// check if the player has brought all cloaks
missing = missingcloaks2(player, true);
if (missing.isEmpty()) {
rewardPlayer(player);
entity.say("Oh, yay! You're so kind, I bet you'll have great Karma now! Here, take these killer boots. I think they're gorgeous but they don't fit me!");
player.setQuest(QUEST_SLOT, "done;rewarded");
final Item boots = SingletonRepository.getEntityManager().getItem("killer boots");
boots.setBoundTo(player.getName());
player.equipOrPutOnGround(boots);
player.notifyWorldAboutChanges();
entity.setCurrentState(ConversationStates.ATTENDING);
} else {
entity.say("Wow, thank you! What else did you bring?");
}
} else {
entity.say("Oh, I'm disappointed. You don't really have "
+ Grammar.a_noun(itemName)
+ " with you.");
}
} else {
entity.say("You're terribly forgetful, you already brought that one to me.");
}
}
@Override
public String toString() {
return "answer neededcloaks2";
}
});
}
npc.add(ConversationStates.ATTENDING,
ConversationPhrases.NO_MESSAGES,
new ChatCondition() {
public boolean fire(final Player player, final Sentence sentence, final Entity entity) {
return !player.isQuestCompleted(QUEST_SLOT);
}
},
ConversationStates.ATTENDING,
"Ok. If you want help, just say.",
null);
// player says he didn't bring any cloaks to different question
npc.add(ConversationStates.QUESTION_2,
ConversationPhrases.NO_MESSAGES,
new ChatCondition() {
public boolean fire(final Player player, final Sentence sentence, final Entity entity) {
return !player.isQuestCompleted(QUEST_SLOT);
}
}, ConversationStates.ATTENDING, "Okay then. Come back later.",
null);
// player returns after finishing the quest but not rewarded
npc.add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestInStateCondition(QUEST_SLOT, "done")),
ConversationStates.ATTENDING,
"Oh! I didn't reward you for helping me again! Here, take these boots. I think they're gorgeous but they don't fit me :(",
new MultipleActions(new EquipItemAction("killer boots", 1, true), new SetQuestAction(QUEST_SLOT, "done;rewarded")));
// player returns after finishing the quest and was rewarded
npc.add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestInStateCondition(QUEST_SLOT, "done;rewarded")),
ConversationStates.ATTENDING,
"Thanks again for helping me! The cloaks look great!",
null);
}