Guest User

Untitled

a guest
Jul 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.55 KB | None | 0 0
  1. package server.model.npcs;
  2.  
  3. import server.Server;
  4. import server.util.Misc;
  5. import server.util.Stream;
  6. import server.world.WalkingHandler;
  7.  
  8. public class NPC {
  9. public int npcId;
  10. public int npcType;
  11. public int absX, absY;
  12. public int heightLevel;
  13. public int makeX, makeY, maxHit, defence, attack, moveX, moveY, direction, walkingType;
  14. public int spawnX, spawnY;
  15. public int viewX, viewY;
  16. /**
  17. * attackType: 0 = melee, 1 = range, 2 = mage, 3 = kbd fire
  18. */
  19. public int attackType, projectileId, endGfx, spawnedBy, hitDelayTimer, HP, MaxHP, hitDiff, animNumber, actionTimer, enemyX, enemyY;
  20. public boolean applyDead, isDead, needRespawn, respawns;
  21. public boolean walkingHome, underAttack;
  22. public int freezeTimer, attackTimer, killerId, killedBy, oldIndex, underAttackBy;
  23. public long lastDamageTaken;
  24. public boolean randomWalk;
  25. public boolean dirUpdateRequired;
  26. public boolean animUpdateRequired;
  27. public boolean hitUpdateRequired;
  28. public boolean updateRequired;
  29. public boolean forcedChatRequired;
  30. public boolean faceToUpdateRequired;
  31. public int firstAttacker;
  32. public String forcedText;
  33.  
  34. public NPC(int _npcId, int _npcType) {
  35. npcId = _npcId;
  36. npcType = _npcType;
  37. direction = -1;
  38. isDead = false;
  39. applyDead = false;
  40. actionTimer = 0;
  41. randomWalk = true;
  42. }
  43.  
  44.  
  45. public void updateNPCMovement(Stream str) {
  46. if (direction == -1) {
  47.  
  48. if (updateRequired) {
  49.  
  50. str.writeBits(1, 1);
  51. str.writeBits(2, 0);
  52. } else {
  53. str.writeBits(1, 0);
  54. }
  55. } else {
  56.  
  57. str.writeBits(1, 1);
  58. str.writeBits(2, 1);
  59. str.writeBits(3, Misc.xlateDirectionToClient[direction]);
  60. if (updateRequired) {
  61. str.writeBits(1, 1);
  62. } else {
  63. str.writeBits(1, 0);
  64. }
  65. }
  66. }
  67.  
  68. /**
  69. * Text update
  70. **/
  71.  
  72. public void forceChat(String text) {
  73. forcedText = text;
  74. forcedChatRequired = true;
  75. updateRequired = true;
  76. }
  77.  
  78. public void forceAnim(int number) {
  79. animNumber = number;
  80. animUpdateRequired = true;
  81. updateRequired = true;
  82. }
  83.  
  84. /**
  85. *Graphics
  86. **/
  87.  
  88. public int mask80var1 = 0;
  89. public int mask80var2 = 0;
  90. protected boolean mask80update = false;
  91.  
  92. public void appendMask80Update(Stream str) {
  93. str.writeWord(mask80var1);
  94. str.writeDWord(mask80var2);
  95. }
  96.  
  97. public void gfx100(int gfx){
  98. mask80var1 = gfx;
  99. mask80var2 = 6553600;
  100. mask80update = true;
  101. updateRequired = true;
  102. }
  103.  
  104. public void gfx0(int gfx){
  105. mask80var1 = gfx;
  106. mask80var2 = 65536;
  107. mask80update = true;
  108. updateRequired = true;
  109. }
  110.  
  111. public void appendAnimUpdate(Stream str) {
  112. str.writeWordBigEndian(animNumber);
  113. str.writeByte(1);
  114. }
  115.  
  116. /**
  117. *
  118. Face
  119. *
  120. **/
  121.  
  122. public int FocusPointX = -1, FocusPointY = -1;
  123. public int face = 0;
  124.  
  125. private void appendSetFocusDestination(Stream str) {
  126. str.writeWordBigEndian(FocusPointX);
  127. str.writeWordBigEndian(FocusPointY);
  128. }
  129.  
  130. public void turnNpc(int i, int j) {
  131. FocusPointX = 2 * i + 1;
  132. FocusPointY = 2 * j + 1;
  133. updateRequired = true;
  134.  
  135. }
  136.  
  137. public void appendFaceEntity(Stream str) {
  138. str.writeWord(face);
  139. }
  140.  
  141. public void facePlayer(int player) {
  142. face = player + 32768;
  143. dirUpdateRequired = true;
  144. updateRequired = true;
  145. }
  146.  
  147. public void appendFaceToUpdate(Stream str) {
  148. str.writeWordBigEndian(viewX);
  149. str.writeWordBigEndian(viewY);
  150. }
  151.  
  152.  
  153. public void appendNPCUpdateBlock(Stream str) {
  154. if(!updateRequired) return ;
  155. int updateMask = 0;
  156. if(animUpdateRequired) updateMask |= 0x10;
  157. if(hitUpdateRequired2) updateMask |= 8;
  158. if(mask80update) updateMask |= 0x80;
  159. if(dirUpdateRequired) updateMask |= 0x20;
  160. if(forcedChatRequired) updateMask |= 1;
  161. if(hitUpdateRequired) updateMask |= 0x40;
  162. if(FocusPointX != -1) updateMask |= 4;
  163.  
  164. str.writeByte(updateMask);
  165.  
  166. if (animUpdateRequired) appendAnimUpdate(str);
  167. if (hitUpdateRequired2) appendHitUpdate2(str);
  168. if (mask80update) appendMask80Update(str);
  169. if (dirUpdateRequired) appendFaceEntity(str);
  170. if(forcedChatRequired) {
  171. str.writeString(forcedText);
  172. }
  173. if (hitUpdateRequired) appendHitUpdate(str);
  174. if(FocusPointX != -1) appendSetFocusDestination(str);
  175.  
  176. }
  177.  
  178. public void clearUpdateFlags() {
  179. updateRequired = false;
  180. forcedChatRequired = false;
  181. hitUpdateRequired = false;
  182. hitUpdateRequired2 = false;
  183. animUpdateRequired = false;
  184. dirUpdateRequired = false;
  185. mask80update = false;
  186. forcedText = null;
  187. moveX = 0;
  188. moveY = 0;
  189. direction = -1;
  190. FocusPointX = -1;
  191. FocusPointY = -1;
  192. }
  193.  
  194.  
  195. public int getNextWalkingDirection() {
  196. int dir;
  197. dir = Misc.direction(absX, absY, (absX + moveX), (absY + moveY));
  198. if (dir == -1 || !WalkingHandler.getSingleton().traversable(absX + moveX, absY + moveY, dir))
  199. return -1;
  200. dir >>= 1;
  201. absX += moveX;
  202. absY += moveY;
  203. return dir;
  204. }
  205.  
  206. public void getNextNPCMovement(int i) {
  207. direction = -1;
  208. if(Server.npcHandler.npcs[i].freezeTimer == 0) {
  209. direction = getNextWalkingDirection();
  210. }
  211. }
  212.  
  213.  
  214. public void appendHitUpdate(Stream str) {
  215. if (HP <= 0) {
  216. isDead = true;
  217. }
  218. str.writeByteC(hitDiff);
  219. if (hitDiff > 0) {
  220. str.writeByteS(1);
  221. } else {
  222. str.writeByteS(0);
  223. }
  224. str.writeByteS(Misc.getCurrentHP(HP, MaxHP, 100));
  225. str.writeByteC(100);
  226. //str.writeByteS(HP);
  227. //str.writeByteC(MaxHP);
  228. }
  229.  
  230. public int hitDiff2 = 0;
  231. public boolean hitUpdateRequired2 = false;
  232.  
  233. public void appendHitUpdate2(Stream str) {
  234. if (HP <= 0) {
  235. isDead = true;
  236. }
  237. str.writeByteA(hitDiff2);
  238. if (hitDiff2 > 0) {
  239. str.writeByteC(1);
  240. } else {
  241. str.writeByteC(0);
  242. }
  243. str.writeByteA(HP);
  244. str.writeByte(MaxHP);
  245. }
  246.  
  247. public void handleHitMask(int damage) {
  248. if (!hitUpdateRequired) {
  249. hitUpdateRequired = true;
  250. hitDiff = damage;
  251. } else if (!hitUpdateRequired2) {
  252. hitUpdateRequired2 = true;
  253. hitDiff2 = damage;
  254. }
  255. updateRequired = true;
  256. }
  257.  
  258. public int getX() {
  259. return absX;
  260. }
  261.  
  262. public int getY() {
  263. return absY;
  264. }
  265.  
  266. public boolean inMulti() {
  267. if((absX >= 3136 && absX <= 3327 && absY >= 3519 && absY <= 3607) ||
  268. (absX >= 3210 && absX <= 3339 && absY >= 9333 && absY <= 9424) ||
  269. (absX >= 3190 && absX <= 3327 && absY >= 3648 && absY <= 3839) ||
  270. (absX >= 3200 && absX <= 3390 && absY >= 3840 && absY <= 3967) ||
  271. (absX >= 2992 && absX <= 3007 && absY >= 3912 && absY <= 3967) ||
  272. (absX >= 2955 && absX <= 2980 && absY >= 9515 && absY <= 9520) ||
  273. (absX >= 2946 && absX <= 2959 && absY >= 3816 && absY <= 3831) ||
  274. (absX >= 3008 && absX <= 3199 && absY >= 3856 && absY <= 3903) ||
  275. (absX >= 3008 && absX <= 3071 && absY >= 3600 && absY <= 3711) ||
  276. (absX >= 3072 && absX <= 3327 && absY >= 3608 && absY <= 3647) ||
  277. (absX >= 2624 && absX <= 2690 && absY >= 2550 && absY <= 2619) ||
  278. (absX >= 2820 && absX <= 2955 && absY >= 5250 && absY <= 5370) ||
  279. (absX >= 3092 && absX <= 3140 && absY >= 3667 && absY <= 3725) ||
  280. (absX >= 2371 && absX <= 2422 && absY >= 5062 && absY <= 5117) ||
  281. (absX >= 2896 && absX <= 2927 && absY >= 3595 && absY <= 3630) ||
  282. (absX >= 2892 && absX <= 2932 && absY >= 4435 && absY <= 4464) ||
  283. (absX >= 2824 && absX <= 2827 && absY >= 3808 && absY <= 3812) ||
  284. (absX >= 2256 && absX <= 2287 && absY >= 4680 && absY <= 4711)) {
  285. return true;
  286. }
  287. return false;
  288. }
  289.  
  290. public boolean inWild() {
  291. if(absX > 2941 && absX < 3392 && absY > 3518 && absY < 3966 ||
  292. absX > 2941 && absX < 3392 && absY > 9918 && absY < 10366) {
  293. return true;
  294. }
  295. return false;
  296. }
  297. }
Add Comment
Please, Sign In to add comment