// the player returns to Carena after having started the quest, or found
// some ghosts.
npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestActiveCondition(QUEST_SLOT)),
ConversationStates.QUESTION_1,
"If you found any #spirits, please tell me their name.", null);
for(final String spiritName : NEEDED_SPIRITS) {
npc.add(ConversationStates.QUESTION_1, spiritName, null,
ConversationStates.QUESTION_1, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser npc) {
final String name = spiritName;
// although all names are stored as lower case from now on,
// older versions did not,
// so we have to be compatible with them
final String npcQuestText = player.getQuest(QUEST_SLOT).toLowerCase();
final String[] npcDoneText = npcQuestText.split(":");
final String lookingStr;
final String saidStr;
if (npcDoneText.length > 1) {
lookingStr = npcDoneText[0];
saidStr = npcDoneText[1];
} else {
// compatibility with broken quests
logger.warn("Player " + player.getTitle() + " found with find_ghosts quest slot in state " + player.getQuest(QUEST_SLOT) + " - now setting this to done.");
player.setQuest(QUEST_SLOT, "done");
npc.say("Sorry, it looks like you have already found them after all. I got confused");
player.notifyWorldAboutChanges();
npc.setCurrentState(ConversationStates.ATTENDING);
return;
}
final List<String> looking = Arrays.asList(lookingStr.split(";"));
final List<String> said = Arrays.asList(saidStr.split(";"));
String reply = "";
List<String> missing = missingNames(player);
final boolean isMissing = missing.contains(name);
if (isMissing && looking.contains(name) && !said.contains(name)) {
// we haven't said the name yet so we add it to the list
player.setQuest(QUEST_SLOT, lookingStr
+ ":" + saidStr + ";" + name);
reply = "Thank you.";
} else if (!looking.contains(name)) {
// we have said it was a valid name but haven't met them
reply = "I don't believe you've spoken with any spirit of that name.";
} else if (!isMissing && said.contains(name)) {
// we have said the name so we are stupid!
reply = "You've told me that name already, thanks.";
} else {
assert false;
}
// we may have changed the missing list
missing = missingNames(player);
if (!missing.isEmpty()) {
reply += " If you met any other spirits, please tell me their name.";
npc.say(reply);
} else {
player.setBaseHP(50 + player.getBaseHP());
player.heal(50, true);
player.addXP(5000);
player.addKarma(15);
reply += " Now that I know those 4 names, perhaps I can even reach the spirits with my mind. I can't give you anything of material value, but I have given you a boost to your basic wellbeing, which will last forever. May you live long, and prosper.";
npc.say(reply);
player.setQuest(QUEST_SLOT, "done");
player.notifyWorldAboutChanges();
npc.setCurrentState(ConversationStates.ATTENDING);
}
}
});
}
final List<String> triggers = new ArrayList<String>();
triggers.add(ConversationPhrases.NO_EXPRESSION);
triggers.addAll(ConversationPhrases.GOODBYE_MESSAGES);
npc.add(ConversationStates.QUESTION_1, triggers, null,
ConversationStates.IDLE, "No problem, come back later.", null);
// player says something which isn't in the needed spirits list.
npc.add(
ConversationStates.QUESTION_1,
"",
new NotCondition(new TriggerInListCondition(NEEDED_SPIRITS)),
ConversationStates.QUESTION_1,
"Sorry, I don't understand you. What name are you trying to say?",
null);
npc.add(
ConversationStates.QUESTION_1,
Arrays.asList("spirits", "spirit"),
null,
ConversationStates.QUESTION_1,
"I seek to know more about other spirits who are dead but stalk the earthly world as ghosts. Please tell me any names you know.",
null);
// the player goes to Carena and says hi, and has no quest or is completed.
npc.add(ConversationStates.IDLE,
ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new NotCondition(new QuestActiveCondition(QUEST_SLOT))),
ConversationStates.ATTENDING, "Wooouhhhhhh!",
null);
}