Guest User

Klank.java

a guest
Nov 13th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. package org.rscdaemon.server.npchandler;
  2.  
  3. import org.rscdaemon.server.model.Player;
  4. import org.rscdaemon.server.model.Npc;
  5. import org.rscdaemon.server.model.World;
  6. import org.rscdaemon.server.model.InvItem;
  7. import org.rscdaemon.server.model.ChatMessage;
  8. import org.rscdaemon.server.model.MenuHandler;
  9. import org.rscdaemon.server.event.ShortEvent;
  10.  
  11. public class Klank implements NpcHandler {
  12. /**
  13. * World instance
  14. */
  15. public static final World world = World.getWorld();
  16.  
  17. public void handleNpc(final Npc npc, Player player) throws Exception {
  18. player.informOfNpcMessage(new ChatMessage(npc, "Would you like me to put your Dragon shield together?", player));
  19. player.informOfNpcMessage(new ChatMessage(npc, "I can do it for a small fee of 1 million coins.", player));
  20. player.setBusy(true);
  21. world.getDelayedEventHandler().add(new ShortEvent(player) {
  22. public void action() {
  23. owner.setBusy(false);
  24. String[] options = new String[]{"Yes, please.", "No, thank you."};
  25. owner.setMenuHandler(new MenuHandler(options) {
  26. public void handleReply(final int option, final String reply) {
  27. if(owner.isBusy()) {
  28. return;
  29. }
  30. owner.informOfChatMessage(new ChatMessage(owner, reply, npc));
  31. owner.setBusy(true);
  32. world.getDelayedEventHandler().add(new ShortEvent(owner) {
  33. public void action() {
  34. switch(option) {
  35. case 0: //Yes
  36. world.getDelayedEventHandler().add(new ShortEvent(owner) {
  37. public void action() {
  38. if(owner.getInventory().countId(1276) < 1) {
  39. }
  40. if(owner.getInventory().countId(1277) < 1) {
  41. owner.getActionSender().sendMessage("You don't have both halfs of the shield.");
  42. owner.setBusy(false);
  43. npc.unblock();
  44. }
  45. else if(owner.getInventory().countId(10) < 1000000) {
  46. owner.getActionSender().sendMessage("You do not have enough cash.");
  47. running = false;
  48. owner.setBusy(false);
  49. npc.unblock();
  50. }
  51. else {
  52. owner.getInventory().remove(1276, 1);
  53. owner.getInventory().remove(1277, 1);
  54. owner.getInventory().remove(10, 1000000);
  55. owner.getInventory().add(new InvItem(1278, 1));
  56. owner.getActionSender().sendInventory();
  57. npc.unblock();
  58. owner.setBusy(false);
  59. }}
  60. });
  61. return;
  62. case 1: //No
  63. owner.setBusy(false);
  64. owner.informOfNpcMessage(new ChatMessage(npc, "Ok. Come back when you change your mind.", owner));
  65. npc.unblock();
  66. break;
  67. default:
  68. owner.setBusy(false);
  69. npc.unblock();
  70. return;
  71. }
  72.  
  73. }
  74. });
  75. }
  76. });
  77. owner.getActionSender().sendMenu(options);
  78. }
  79. });
  80. npc.blockedBy(player);
  81. }
  82.  
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment