npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestStateStartsWithCondition(QUEST_SLOT, "start")),
ConversationStates.ATTENDING, null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
final String[] tokens = player.getQuest(QUEST_SLOT).split(";");
int idx1 = 1;
for (ItemData itemdata : neededItems.values()) {
itemdata.resetAmount();
itemdata.subAmount(tokens[idx1]);
idx1++;
}
boolean missingSomething = false;
int size = neededItems.size();
for (int idx = 1; !missingSomething && idx <= size; idx++) {
ItemData itemData = neededItems.get(idx);
missingSomething = proceedItem(player, raiser,
itemData);
}
if (player.hasKilledSolo("black giant") && !missingSomething) {
raiser.say("You've brought everything I need to forge the shield. Come back in "
+ REQUIRED_MINUTES
+ " minutes and it will be ready.");
player.setQuest(QUEST_SLOT, "forging;" + System.currentTimeMillis());
} else {
if (!player.hasKilledSolo("black giant") && !missingSomething) {
raiser.say("This shield can only be given to those who have killed a black giant, and without the help of others.");
}
StringBuilder sb = new StringBuilder(30);
sb.append("start");
for (ItemData id : neededItems.values()) {
sb.append(";");
sb.append(id.getAlreadyBrought());
}
player.setQuest(QUEST_SLOT, sb.toString());
}
}
private boolean proceedItem(final Player player,
final EventRaiser engine, final ItemData itemData) {
if (itemData.getStillNeeded() > 0) {
if (player.isEquipped(itemData.getName(), itemData.getStillNeeded())) {
player.drop(itemData.getName(), itemData.getStillNeeded());
itemData.setAmount(0);
} else {
final int amount = player.getNumberOfEquipped(itemData.getName());
if (amount > 0) {
player.drop(itemData.getName(), amount);
itemData.subAmount(amount);
}
engine.say(itemData.getAnswer());
return true;
}
}
return false;
}
});
npc.add(ConversationStates.IDLE, ConversationPhrases.GREETING_MESSAGES,
new AndCondition(new GreetingMatchesNameCondition(npc.getName()),
new QuestStateStartsWithCondition(QUEST_SLOT, "forging;")),
ConversationStates.IDLE, null, new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
final String[] tokens = player.getQuest(QUEST_SLOT).split(";");
final long delay = REQUIRED_MINUTES * MathHelper.MILLISECONDS_IN_ONE_MINUTE;
final long timeRemaining = (Long.parseLong(tokens[1]) + delay)
- System.currentTimeMillis();
if (timeRemaining > 0L) {
raiser.say("I haven't finished forging your shield. Please check back in "
+ TimeUtil.approxTimeUntil((int) (timeRemaining / 1000L))
+ ".");
return;
}
raiser.say("I have finished forging your new mithril shield. Enjoy. Now I will see what Trillium has stored behind the counter for me. ;)");
player.addXP(95000);
player.addKarma(25);
final Item mithrilshield = SingletonRepository.getEntityManager().getItem("mithril shield");
mithrilshield.setBoundTo(player.getName());
player.equipOrPutOnGround(mithrilshield);
player.notifyWorldAboutChanges();
player.setQuest(QUEST_SLOT, "done");
}
});
npc.add(ConversationStates.ATTENDING,
Arrays.asList("forge", "missing"),
new QuestStartedCondition(QUEST_SLOT),
ConversationStates.ATTENDING,
null,
new ChatAction() {
public void fire(final Player player, final Sentence sentence, final EventRaiser raiser) {
final String[] tokens = player.getQuest(QUEST_SLOT).split(";");
final int neededMithrilBar = REQUIRED_MITHRIL_BAR
- Integer.parseInt(tokens[1]);