Advertisement
Guest User

Untitled

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