public void handleNpc(final Npc npc, Player player) throws Exception { final CerterDef certerDef = EntityHandler.getCerterDef(npc.getID()); if (certerDef == null) { return; } final String[] names = certerDef.getCertNames(); player.informOfNpcMessage( new ChatMessage(npc, "Welcome to my " + certerDef.getType() + " exchange stall", player)); player.setBusy(true); world .getDelayedEventHandler() .add( new ShortEvent(player) { public void action() { owner.setBusy(false); String[] options = new String[] { "I have some certificates to trade in", "I have some " + certerDef.getType() + " to trade in" }; owner.setMenuHandler( new MenuHandler(options) { public void handleReply(final int option, final String reply) { if (owner.isBusy()) { return; } owner.informOfChatMessage(new ChatMessage(owner, reply, npc)); owner.setBusy(true); world .getDelayedEventHandler() .add( new ShortEvent(owner) { public void action() { owner.setBusy(false); switch (option) { case 0: owner .getActionSender() .sendMessage( "What sort of certificate do you wish to trade in?"); owner.setMenuHandler( new MenuHandler(names) { public void handleReply( final int index, String reply) { owner .getActionSender() .sendMessage( "How many certificates do you wish to trade in?"); String[] options = new String[] { "One", "Two", "Three", "Four", "Five", "All to bank" }; owner.setMenuHandler( new MenuHandler(options) { public void handleReply( int certAmount, String reply) { owner.resetPath(); int certID = certerDef.getCertID(index); if (certID < 0) { // This shouldn't happen return; } int itemID = certerDef.getItemID(index); if (certAmount == 5) { certAmount = owner.getInventory().countId(certID); if (certAmount <= 0) { owner .getActionSender() .sendMessage( "You don't have any " + names[index] + " certificates"); return; } // MIGHT BE SMART TO CHECK THEIR BANK // ISN'T FULL InvItem bankItem = new InvItem(itemID, certAmount * 5); if (owner .getInventory() .remove( new InvItem( certID, certAmount)) > -1) { owner .getActionSender() .sendMessage( "You exchange the certificates, " + bankItem.getAmount() + " " + bankItem .getDef() .getName() + " is added to your bank"); owner.getBank().add(bankItem); } } else { certAmount += 1; int itemAmount = certAmount * 5; if (owner.getInventory().countId(certID) < certAmount) { owner .getActionSender() .sendMessage( "You don't have that many certificates"); return; } if (owner .getInventory() .remove(certID, certAmount) > -1) { owner .getActionSender() .sendMessage( "You exchange the certificates for " + certerDef.getType() + "."); for (int x = 0; x < itemAmount; x++) { owner .getInventory() .add(new InvItem(itemID, 1)); } } } owner.getActionSender().sendInventory(); } }); owner.getActionSender().sendMenu(options); } }); owner.getActionSender().sendMenu(names); break; case 1: owner .getActionSender() .sendMessage( "What sort of " + certerDef.getType() + " do you wish to trade in?"); owner.setMenuHandler( new MenuHandler(names) { public void handleReply( final int index, String reply) { owner .getActionSender() .sendMessage( "How many " + certerDef.getType() + " do you wish to trade in?"); String[] options = new String[] { "Five", "Ten", "Fifteen", "Twenty", "Twentyfive", "All from bank" }; owner.setMenuHandler( new MenuHandler(options) { public void handleReply( int certAmount, String reply) { owner.resetPath(); int certID = certerDef.getCertID(index); if (certID < 0) { // This shouldn't happen return; } int itemID = certerDef.getItemID(index); if (certAmount == 5) { certAmount = (int) (owner.getBank().countId(itemID) / 5); int itemAmount = certAmount * 5; if (itemAmount <= 0) { owner .getActionSender() .sendMessage( "You don't have any " + names[index] + " to cert"); return; } if (owner .getBank() .remove(itemID, itemAmount) > -1) { owner .getActionSender() .sendMessage( "You exchange the " + certerDef.getType() + ", " + itemAmount + " " + EntityHandler.getItemDef( itemID) .getName() + " is taken from your bank"); owner .getInventory() .add( new InvItem( certID, certAmount)); } } else { certAmount += 1; int itemAmount = certAmount * 5; if (owner.getInventory().countId(itemID) < itemAmount) { owner .getActionSender() .sendMessage( "You don't have that many " + certerDef.getType()); return; } owner .getActionSender() .sendMessage( "You exchange the " + certerDef.getType() + " for certificates."); for (int x = 0; x < itemAmount; x++) { owner.getInventory().remove(itemID, 1); } owner .getInventory() .add(new InvItem(certID, certAmount)); } owner.getActionSender().sendInventory(); } }); owner.getActionSender().sendMenu(options); } }); owner.getActionSender().sendMenu(names); break; } npc.unblock(); } }); } }); owner.getActionSender().sendMenu(options); } }); npc.blockedBy(player); }
public void handleNpc(final Npc npc, final Player player) throws Exception { if (player.getDemonSlayerStatus() == 6) { // Quest Complete player.informOfNpcMessage( new ChatMessage( npc, "Well done brave adventurer. You surely showed Delrith who is boss around here!", player)); return; } if (player.getDemonSlayerStatus() == 5) { // Got the silverlight player.informOfNpcMessage( new ChatMessage(npc, "Please go slay Delrith with the silverlight!", player)); return; } if (player.getDemonSlayerStatus() == 4) { player.informOfNpcMessage( new ChatMessage( npc, "Perhaps you should get all the keys to Sir Prysin as soon as possible!", player)); return; } if (player.getDemonSlayerStatus() == 0) { player.informOfNpcMessage( new ChatMessage( npc, "Go speak with the gypsy. She looks like she's in trouble!", player)); return; } if (player.getDemonSlayerStatus() == 1) { player.informOfNpcMessage( new ChatMessage( npc, "I heard Delrith is around town. Go find and inform Sir Prysin!", player)); return; } if (player.getDemonSlayerStatus() == 3) { player.informOfNpcMessage( new ChatMessage( npc, "Take the keys back to Sir Prysin to recieve the silverlight sword!", player)); return; } if (player.getDemonSlayerStatus() == 2) { player.informOfNpcMessage(new ChatMessage(npc, "How can I help you?", player)); world .getDelayedEventHandler() .add( new ShortEvent(player) { public void action() { String[] option = new String[] { "What are you doing up here?", "I am looking for the silverlight key", "You can't help me" }; player.setMenuHandler( new MenuHandler(option) { public void handleReply(final int option, final String reply) { if (player.isBusy()) { return; } player.informOfChatMessage(new ChatMessage(player, reply, npc)); player.setBusy(true); world .getDelayedEventHandler() .add( new ShortEvent(player) { public void action() { player.setBusy(false); if (option == 2) { // Nothing player.informOfNpcMessage( new ChatMessage( npc, "Then go away! I need to keep the guards in order!", player)); return; } if (option == 0) { // What are you doing up here player.informOfNpcMessage( new ChatMessage( npc, "I am training these guards and keeping them in top shape!", player)); return; } if (option == 1) { // Looking for the key player.informOfNpcMessage( new ChatMessage( npc, "Ah, yes. Sir Prysin informed of you would be coming to see me", player)); world .getDelayedEventHandler() .add( new ShortEvent(player) { public void action() { player.informOfNpcMessage( new ChatMessage( npc, "The Delrith is no push over, I hope you know what you are getting into", player)); world .getDelayedEventHandler() .add( new ShortEvent(player) { public void action() { player.informOfChatMessage( new ChatMessage( player, "Let me worry about defeating the Delrith. You stick to coaching the guards!", npc)); world .getDelayedEventHandler() .add( new ShortEvent(player) { public void action() { player .informOfNpcMessage( new ChatMessage( npc, "Ok soldier! Here's the key!", player)); player .getInventory() .add( new InvItem( 26, 1)); player .getActionSender() .sendInventory(); player .setDemonSlayerStatus( 3); npc.unblock(); } }); } }); } }); } } }); } }); owner.getActionSender().sendMenu(option); } }); npc.blockedBy(player); } }
public void handleAction(QuestAction action, Object[] args, final Player player) { int stage = player.getQuestStage(this); if (stage == -1) // Quest hasn't been started { if (action == action.TALKED_NPC) { if (!(args[0] instanceof Npc)) return; final Npc npc = (Npc) args[0]; if (npc.getID() != FRED_ID) return; player.setBusy(true); npc.blockedBy(player); sendChat("Hi there, traveller. Care to make some money?", npc, player); addSingleEvent( new SingleEvent(player, 2000) { public void action() { player.setBusy(false); player.setMenuHandler( new MenuHandler(FIRST_MENU) { public void handleReply(final int option, final String reply) { player.setBusy(true); switch (option) { case 1: player.setBusy(false); npc.unblock(); sendChat("No thanks, I'm good.", player, npc); break; case 0: sendChat("Sure, what do I need to do?", player, npc); addSingleEvent( new SingleEvent(player, 2000) { public void action() { sendChat( "If you collect 20 balls of wool for me, I'll pay you 500 coins.", npc, player); addSingleEvent( new SingleEvent(player, 2000) { public void action() { sendChat( "Maybe I'll teach you a thing or two about crafting, too.", npc, player); addSingleEvent( new SingleEvent(player, 2000) { public void action() { sendChat( "I'm afraid you'll have to find your own shears, but the sheep are outside.", npc, player); addSingleEvent( new SingleEvent(player, 2000) { public void action() { player.setBusy(false); player.setMenuHandler( new MenuHandler(SECOND_MENU) { public void handleReply( final int option, final String reply) { player.setBusy(true); switch (option) { case 1: sendChat( "I'd be happy to help.", player, npc); addSingleEvent( new SingleEvent( player, 2000) { public void action() { sendChat( "Great! Come back and see me when you're done.", npc, player); addSingleEvent( new SingleEvent( player, 2000) { public void action() { player .setQuestStage( getUniqueID(), 1); player .setBusy( false); npc .unblock(); } }); } }); break; case 0: sendChat( "Sorry, I don't like the sound of that.", player, npc); addSingleEvent( new SingleEvent( player, 2000) { public void action() { sendChat( "Suit yourself. Come and see me if you change your mind.", npc, player); player.setBusy( false); npc.unblock(); } }); break; default: player.setBusy(false); npc.unblock(); break; } } }); owner .getActionSender() .sendMenu(SECOND_MENU); } }); } }); } }); } }); break; default: player.setBusy(false); npc.unblock(); break; } } }); owner.getActionSender().sendMenu(FIRST_MENU); } }); } else return; } else if (stage == 1) { if (action == action.TALKED_NPC) { if (!(args[0] instanceof Npc)) return; final Npc npc = (Npc) args[0]; if (npc.getID() != FRED_ID) return; player.setBusy(true); npc.blockedBy(player); sendChat("Ahh, you've returned! Do you have my wool?", npc, player); addSingleEvent( new SingleEvent(player, 2000) { public void action() { player.setBusy(false); player.setMenuHandler( new MenuHandler(new String[] {"I'm afraid not.", "Yes, I do."}) { public void handleReply(final int option, final String reply) { player.setBusy(true); sendChat(reply, player, npc); if (option == 0) { addSingleEvent( new SingleEvent(player, 2000) { public void action() { sendChat( "Well, come and see me when you do. The offer still stands", npc, player); player.setBusy(false); npc.unblock(); } }); } else if (option == 1) { addSingleEvent( new SingleEvent(player, 2000) { public void action() { // check items if (player.getInventory().hasItemId(ITEM_WOOL) && player.getInventory().countId(ITEM_WOOL) >= 20) { finishQuest(player, npc); } else { sendChat( "Um, no you don't. Get back to me when you do. The reward still stands!", npc, player); player.setBusy(false); npc.unblock(); } } }); } } }); owner.getActionSender().sendMenu(new String[] {"I'm afraid not.", "Yes, I do."}); } }); } } else if (stage == 0) { if (action == action.TALKED_NPC) { if (!(args[0] instanceof Npc)) return; final Npc npc = (Npc) args[0]; if (npc.getID() != FRED_ID) return; player.setBusy(true); npc.blockedBy(player); sendChat("Hello " + player.getUsername() + "!", npc, player); player.setBusy(false); npc.unblock(); } } }