Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.81 KB | None | 0 0
  1. package server.model.players.packets;
  2.  
  3. import server.Config;
  4. import server.event.CycleEvent;
  5. import server.event.CycleEventContainer;
  6. import server.event.CycleEventHandler;
  7. import server.model.npcs.NPC;
  8. import server.model.npcs.NPCHandler;
  9. import server.model.players.Client;
  10. import server.model.players.PacketType;
  11. import server.model.players.Player;
  12.  
  13. /**
  14. * Click NPC
  15. */
  16. public class ClickNPC implements PacketType {
  17. public static final int ATTACK_NPC = 72, MAGE_NPC = 131, FIRST_CLICK = 155,
  18. SECOND_CLICK = 17, THIRD_CLICK = 21, FOURTH_CLICK = 18;;
  19.  
  20. @Override
  21. public void processPacket(final Client c, int packetType, int packetSize) {
  22. c.npcIndex = 0;
  23. c.npcClickIndex = 0;
  24. c.playerIndex = 0;
  25. c.clickNpcType = 0;
  26. c.getPA().resetFollow();
  27. c.playerSkilling[c.playerFishing] = false;
  28. if(c.jumpingDitch)
  29. return;
  30. switch (packetType) {
  31.  
  32. /**
  33. * Attack npc melee or range
  34. **/
  35. case ATTACK_NPC:
  36. c.npcIndex = c.getInStream().readUnsignedWordA();
  37. NPC npc = NPCHandler.npcs[c.npcIndex];
  38. if (npc == null) {
  39. c.npcIndex = 0;
  40. break;
  41. }
  42. if (npc.maximumHealth == 0) {
  43. c.npcIndex = 0;
  44. break;
  45. }
  46. if (c.autocastId > 0)
  47. c.autocasting = true;
  48. if (!c.autocasting && c.spellId > 0) {
  49. c.spellId = 0;
  50. }
  51. c.faceUpdate(c.npcIndex);
  52. c.usingMagic = false;
  53. boolean usingBow = false;
  54. boolean usingOtherRangeWeapons = false;
  55. boolean usingArrows = false;
  56. boolean usingCross = c.playerEquipment[c.playerWeapon] == 9185 || c.playerEquipment[c.playerWeapon] == 11785;
  57. if (c.playerEquipment[c.playerWeapon] >= 4214
  58. && c.playerEquipment[c.playerWeapon] <= 4223)
  59. usingBow = true;
  60. for (int bowId : Client.BOWS) {
  61. if (c.playerEquipment[c.playerWeapon] == bowId) {
  62. usingBow = true;
  63. for (int arrowId : Client.ARROWS) {
  64. if (c.playerEquipment[c.playerArrows] == arrowId) {
  65. usingArrows = true;
  66. }
  67. }
  68. }
  69. }
  70. for (int otherRangeId : Client.OTHER_RANGE_WEAPONS) {
  71. if (c.playerEquipment[c.playerWeapon] == otherRangeId) {
  72. usingOtherRangeWeapons = true;
  73. }
  74. }
  75. if ((usingBow || c.autocasting)
  76. && Player.goodDistance(c.getX(), c.getY(),
  77. NPCHandler.npcs[c.npcIndex].getX(),
  78. NPCHandler.npcs[c.npcIndex].getY(), 7)) {
  79. c.stopMovement();
  80. }
  81.  
  82. if (usingOtherRangeWeapons
  83. && Player.goodDistance(c.getX(), c.getY(),
  84. NPCHandler.npcs[c.npcIndex].getX(),
  85. NPCHandler.npcs[c.npcIndex].getY(), 4)) {
  86. c.stopMovement();
  87. }
  88. if (!usingCross && !usingArrows && usingBow
  89. && c.playerEquipment[c.playerWeapon] < 4212
  90. && c.playerEquipment[c.playerWeapon] > 4223 && !usingCross) {
  91. c.sendMessage("You have run out of arrows!");
  92. break;
  93. }
  94. if (!c.getCombat().usingCorrectBowAndArrows(c)
  95. && Config.CORRECT_ARROWS
  96. && usingBow
  97. && !c.getCombat().usingCrystalBow()
  98. && c.playerEquipment[c.playerWeapon] != 9185 &&c.playerEquipment[c.playerWeapon] != 11785) {
  99. c.sendMessage("You can't use "
  100. + c.getItems()
  101. .getItemName(c.playerEquipment[c.playerArrows])
  102. .toLowerCase()
  103. + "s with a "
  104. + c.getItems()
  105. .getItemName(c.playerEquipment[c.playerWeapon])
  106. .toLowerCase() + ".");
  107. c.stopMovement();
  108. c.getCombat().resetPlayerAttack();
  109. return;
  110. }
  111. if ((c.playerEquipment[c.playerWeapon] == 9185 || c.playerEquipment[c.playerWeapon] == 11785)
  112. && !c.getCombat().properBolts()) {
  113. c.sendMessage("You must use bolts with a crossbow.");
  114. c.stopMovement();
  115. c.getCombat().resetPlayerAttack();
  116. return;
  117. }
  118.  
  119. if (c.followId > 0) {
  120. c.sendMessage("Resetting Follow");
  121. c.getPA().resetFollow();
  122. }
  123. if (c.attackTimer <= 0) {
  124. c.getCombat().attackNpc(c.npcIndex);
  125. c.attackTimer++;
  126. }
  127.  
  128. break;
  129.  
  130. /**
  131. * Attack npc with magic
  132. **/
  133. case MAGE_NPC:
  134. // c.usingSpecial = false;
  135. // c.getItems().updateSpecialBar();
  136.  
  137. c.npcIndex = c.getInStream().readSignedWordBigEndianA();
  138. int castingSpellId = c.getInStream().readSignedWordA();
  139. c.usingMagic = false;
  140.  
  141. if (NPCHandler.npcs[c.npcIndex] == null) {
  142. break;
  143. }
  144.  
  145. if (NPCHandler.npcs[c.npcIndex].maximumHealth == 0
  146. || NPCHandler.npcs[c.npcIndex].npcId == 944) {
  147. c.sendMessage("You can't attack this npc.");
  148. break;
  149. }
  150.  
  151. for (int i = 0; i < Client.MAGIC_SPELLS.length; i++) {
  152. if (castingSpellId == Client.MAGIC_SPELLS[i][0]) {
  153. c.spellId = i;
  154. c.usingMagic = true;
  155. break;
  156. }
  157. }
  158. if (castingSpellId == 1171) { // crumble undead
  159. for (int iNpc : Config.UNDEAD_NPCS) {
  160. if (NPCHandler.npcs[c.npcIndex].npcId != iNpc) {
  161. c.sendMessage("You can only attack undead monsters with this spell.");
  162. c.usingMagic = false;
  163. c.stopMovement();
  164. break;
  165. }
  166. }
  167. }
  168. /*
  169. * if(!c.getCombat().checkMagicReqs(c.spellId)) { c.stopMovement();
  170. * break; }
  171. */
  172.  
  173. if (c.autocasting)
  174. c.autocasting = false;
  175.  
  176. if (c.usingMagic) {
  177. if (Player.goodDistance(c.getX(), c.getY(),
  178. NPCHandler.npcs[c.npcIndex].getX(),
  179. NPCHandler.npcs[c.npcIndex].getY(), 6)) {
  180. c.stopMovement();
  181. }
  182. if (c.attackTimer <= 0) {
  183. c.getCombat().attackNpc(c.npcIndex);
  184. c.attackTimer++;
  185. }
  186. }
  187.  
  188. break;
  189.  
  190. case FIRST_CLICK:
  191. c.npcClickIndex = c.inStream.readSignedWordBigEndian();
  192. c.npcType = NPCHandler.npcs[c.npcClickIndex].npcId;
  193. c.objectX = NPCHandler.npcs[c.npcClickIndex].getX();
  194. c.objectY = NPCHandler.npcs[c.npcClickIndex].getY();
  195. c.faceUpdate(c.npcClickIndex);
  196. if (Player.goodDistance(NPCHandler.npcs[c.npcClickIndex].getX(),
  197. NPCHandler.npcs[c.npcClickIndex].getY(), c.getX(),
  198. c.getY(), 1)) {
  199. c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(),
  200. NPCHandler.npcs[c.npcClickIndex].getY());
  201. NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
  202. c.getActions().firstClickNpc(c.npcType);
  203. } else {
  204. c.clickNpcType = 1;
  205. CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
  206. @Override
  207. public void execute(CycleEventContainer container) {
  208. if((c.clickNpcType == 1) && NPCHandler.npcs[c.npcClickIndex] != null) {
  209. if(Player.goodDistance(c.getX(), c.getY(), NPCHandler.npcs[c.npcClickIndex].getX(), NPCHandler.npcs[c.npcClickIndex].getY(), 1)) {
  210. c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(), NPCHandler.npcs[c.npcClickIndex].getY());
  211. NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
  212. c.getActions().firstClickNpc(c.npcType);
  213. container.stop();
  214. }
  215. }
  216. if(c.clickNpcType == 0 || c.clickNpcType > 1)
  217. container.stop();
  218. }
  219. @Override
  220. public void stop() {
  221. c.clickNpcType = 0;
  222. }
  223. }, 1);
  224. }
  225. break;
  226.  
  227. case SECOND_CLICK:
  228. c.npcClickIndex = c.inStream.readUnsignedWordBigEndianA();
  229. c.npcType = NPCHandler.npcs[c.npcClickIndex].npcId;
  230. c.faceUpdate(c.npcClickIndex);
  231. if (Player.goodDistance(NPCHandler.npcs[c.npcClickIndex].getX(),
  232. NPCHandler.npcs[c.npcClickIndex].getY(), c.getX(),
  233. c.getY(), 1)) {
  234. c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(),
  235. NPCHandler.npcs[c.npcClickIndex].getY());
  236. NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
  237. c.getActions().secondClickNpc(c.npcType);
  238. } else {
  239. c.clickNpcType = 2;
  240. CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
  241. @Override
  242. public void execute(CycleEventContainer container) {
  243. if((c.clickNpcType == 2) && NPCHandler.npcs[c.npcClickIndex] != null) {
  244. if(Player.goodDistance(c.getX(), c.getY(), NPCHandler.npcs[c.npcClickIndex].getX(), NPCHandler.npcs[c.npcClickIndex].getY(), 1)) {
  245. c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(), NPCHandler.npcs[c.npcClickIndex].getY());
  246. NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
  247. c.getActions().secondClickNpc(c.npcType);
  248. container.stop();
  249. }
  250. }
  251. if(c.clickNpcType < 2 || c.clickNpcType > 2)
  252. container.stop();
  253. }
  254. @Override
  255. public void stop() {
  256. c.clickNpcType = 0;
  257. }
  258. }, 1);
  259. }
  260. break;
  261.  
  262. case THIRD_CLICK:
  263. c.npcClickIndex = c.inStream.readSignedWord();
  264. c.npcType = NPCHandler.npcs[c.npcClickIndex].npcId;
  265. c.faceUpdate(c.npcClickIndex);
  266. if (Player.goodDistance(NPCHandler.npcs[c.npcClickIndex].getX(),
  267. NPCHandler.npcs[c.npcClickIndex].getY(), c.getX(),
  268. c.getY(), 1)) {
  269. c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(),
  270. NPCHandler.npcs[c.npcClickIndex].getY());
  271. NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
  272. c.getActions().thirdClickNpc(c.npcType);
  273. } else {
  274. c.clickNpcType = 3;
  275. CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
  276. @Override
  277. public void execute(CycleEventContainer container) {
  278. if((c.clickNpcType == 3) && NPCHandler.npcs[c.npcClickIndex] != null) {
  279. if(Player.goodDistance(c.getX(), c.getY(), NPCHandler.npcs[c.npcClickIndex].getX(), NPCHandler.npcs[c.npcClickIndex].getY(), 1)) {
  280. c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(), NPCHandler.npcs[c.npcClickIndex].getY());
  281. NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
  282. c.getActions().thirdClickNpc(c.npcType);
  283. container.stop();
  284. }
  285. }
  286. if(c.clickNpcType < 3)
  287. container.stop();
  288. }
  289. @Override
  290. public void stop() {
  291. c.clickNpcType = 0;
  292. }
  293. }, 1);
  294. }
  295. break;
  296.  
  297. case FOURTH_CLICK:
  298. c.npcClickIndex = c.inStream.readSignedWord();
  299. c.npcType = NPCHandler.npcs[c.npcClickIndex].npcId;
  300. if (Player.goodDistance(NPCHandler.npcs[c.npcClickIndex].getX(),
  301. NPCHandler.npcs[c.npcClickIndex].getY(), c.getX(),
  302. c.getY(), 1)) {
  303. c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(),
  304. NPCHandler.npcs[c.npcClickIndex].getY());
  305. NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
  306. c.getActions().thirdClickNpc(c.npcType);
  307. } else {
  308. c.clickNpcType = 3;
  309. CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
  310. @Override
  311. public void execute(CycleEventContainer container) {
  312. if((c.clickNpcType == 3) && NPCHandler.npcs[c.npcClickIndex] != null) {
  313. if(Player.goodDistance(c.getX(), c.getY(), NPCHandler.npcs[c.npcClickIndex].getX(), NPCHandler.npcs[c.npcClickIndex].getY(), 1)) {
  314. c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(), NPCHandler.npcs[c.npcClickIndex].getY());
  315. NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
  316. c.getActions().thirdClickNpc(c.npcType);
  317. container.stop();
  318. }
  319. }
  320. if(c.clickNpcType < 3)
  321. container.stop();
  322. }
  323. @Override
  324. public void stop() {
  325. c.clickNpcType = 0;
  326. }
  327. }, 1);
  328. }
  329. break;
  330. }
  331.  
  332. }
  333. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement