예제 #1
0
 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);
   }
 }
예제 #2
0
 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);
 }