Advertisement
Guest User

process()

a guest
Feb 2nd, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.23 KB | None | 0 0
  1. public void process() {
  2. for (int i = 0; i < maxNPCs; i++) {
  3. if (npcs[i] == null) continue;
  4. npcs[i].clearUpdateFlags();
  5.  
  6. }
  7. /* if (npcs[i].npcType == 812){
  8. if (Misc.random(10) == 4)
  9. npcs[i].forceChat(guardRandomTalk[Misc.random3(guardRandomTalk.length)]);
  10. } */
  11. for (int i = 0; i < maxNPCs; i++) {
  12. if (npcs[i] != null) {
  13. if (npcs[i].actionTimer > 0) {
  14. npcs[i].actionTimer--;
  15. }
  16.  
  17. if (npcs[i].freezeTimer > 0) {
  18. npcs[i].freezeTimer--;
  19. }
  20.  
  21. if (npcs[i].hitDelayTimer > 0) {
  22. npcs[i].hitDelayTimer--;
  23. }
  24.  
  25. if (npcs[i].hitDelayTimer == 1) {
  26. npcs[i].hitDelayTimer = 0;
  27. applyDamage(i);
  28. }
  29.  
  30. if(npcs[i].attackTimer > 0) {
  31. npcs[i].attackTimer--;
  32. }
  33.  
  34. if (npcs[i] != null) {
  35. Client c = (Client) PlayerHandler.players[NPCHandler.npcs[i].spawnedBy];
  36. if (c != null
  37. && c.familiarID > 0
  38. && !PlayerHandler.players[npcs[i].spawnedBy]
  39. .goodDistance(
  40. npcs[i].getX(),
  41. npcs[i].getY(),
  42. PlayerHandler.players[npcs[i].spawnedBy]
  43. .getX(),
  44. PlayerHandler.players[npcs[i].spawnedBy]
  45. .getY(), 10)
  46. && npcs[i].summon == true && !npcs[i].isDead) {
  47. npcs[i].isDead = true;
  48. npcs[i].applyDead = true;
  49. Summoning.spawnFamiliar(c, c.familiarID);
  50. npcs[i].underAttackBy2 = -1;
  51. npcs[i].dirUpdateRequired = true;
  52. npcs[i].getNextWalkingDirection();
  53. }
  54.  
  55. if (c != null && npcs[i].actionTimer < 1
  56. && npcs[i].summon == true) {
  57. if (c.playerIndex > 0) {
  58. Client o = (Client) PlayerHandler.players[c.playerIndex];
  59. if (o != null) {
  60. if (c.underAttackBy2 > 0 && o.inMulti()
  61. || c.underAttackBy > 0 && o.inMulti()) {
  62. followPlayer(o, i, o.playerId);
  63. attackPlayer(o, i);
  64. npcs[i].index = o.playerId;
  65. npcs[i].actionTimer = 7;
  66. }
  67. }
  68. }
  69. }
  70.  
  71. if(npcs[i].spawnedBy > 0) { // delete summons npc
  72. if(Server.playerHandler.players[npcs[i].spawnedBy] == null
  73. || Server.playerHandler.players[npcs[i].spawnedBy].heightLevel != npcs[i].heightLevel
  74. || Server.playerHandler.players[npcs[i].spawnedBy].respawnTimer > 0
  75. || !Server.playerHandler.players[npcs[i].spawnedBy].goodDistance(npcs[i].getX(), npcs[i].getY(), Server.playerHandler.players[npcs[i].spawnedBy].getX(), Server.playerHandler.players[npcs[i].spawnedBy].getY(), 20)) {
  76.  
  77. if(Server.playerHandler.players[npcs[i].spawnedBy] != null) {
  78. for(int o = 0; o < Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs.length; o++){
  79. if(npcs[i].npcType == Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][0]) {
  80. if (Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] == 1)
  81. Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] = 0;
  82. }
  83. }
  84. }
  85. npcs[i] = null;
  86. }
  87. }
  88. if (npcs[i] == null) continue;
  89.  
  90. /**
  91. * Attacking player
  92. **/
  93. if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && !switchesAttackers(i)) {
  94. npcs[i].killerId = getCloseRandomPlayer(i);
  95. } else if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && switchesAttackers(i)) {
  96. npcs[i].killerId = getCloseRandomPlayer(i);
  97. }
  98.  
  99. if (System.currentTimeMillis() - npcs[i].lastDamageTaken > 5000)
  100. npcs[i].underAttackBy = 0;
  101.  
  102. if((npcs[i].killerId > 0 || npcs[i].underAttack) && !npcs[i].walkingHome && retaliates(npcs[i].npcType)) {
  103. if(!npcs[i].isDead) {
  104. int p = npcs[i].killerId;
  105. if(Server.playerHandler.players[p] != null) {
  106. Client c1 = (Client) Server.playerHandler.players[p];
  107. followPlayer(c1, i, c1.playerId);
  108. if (npcs[i] == null) continue;
  109. if(npcs[i].attackTimer == 0) {
  110. if(c1 != null) {
  111. attackPlayer(c1, i);
  112. } else {
  113. npcs[i].killerId = 0;
  114. npcs[i].underAttack = false;
  115. npcs[i].facePlayer(0);
  116. }
  117. }
  118. } else {
  119. npcs[i].killerId = 0;
  120. npcs[i].underAttack = false;
  121. npcs[i].facePlayer(0);
  122. }
  123. }
  124. }
  125.  
  126.  
  127.  
  128. /**
  129. * Random walking and walking home
  130. **/
  131. if (npcs[i] == null) continue;
  132. if((!npcs[i].underAttack || npcs[i].walkingHome) && npcs[i].randomWalk && !npcs[i].isDead) {
  133. npcs[i].facePlayer(0);
  134. npcs[i].killerId = 0;
  135. if(npcs[i].spawnedBy == 0) {
  136. if((npcs[i].absX > npcs[i].makeX + Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absX < npcs[i].makeX - Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absY > npcs[i].makeY + Config.NPC_RANDOM_WALK_DISTANCE) || (npcs[i].absY < npcs[i].makeY - Config.NPC_RANDOM_WALK_DISTANCE)) {
  137. npcs[i].walkingHome = true;
  138. }
  139. }
  140.  
  141. if (npcs[i].walkingHome && npcs[i].absX == npcs[i].makeX && npcs[i].absY == npcs[i].makeY) {
  142. npcs[i].walkingHome = false;
  143. } else if(npcs[i].walkingHome) {
  144. npcs[i].moveX = GetMove(npcs[i].absX, npcs[i].makeX);
  145. npcs[i].moveY = GetMove(npcs[i].absY, npcs[i].makeY);
  146. npcs[i].getNextNPCMovement(i);
  147. npcs[i].updateRequired = true;
  148. }
  149. if(npcs[i].walkingType == 1) {
  150. if(Misc.random(3)== 1 && !npcs[i].walkingHome) {
  151. int MoveX = 0;
  152. int MoveY = 0;
  153. int Rnd = Misc.random(9);
  154. if (Rnd == 1) {
  155. MoveX = 1;
  156. MoveY = 1;
  157. } else if (Rnd == 2) {
  158. MoveX = -1;
  159. } else if (Rnd == 3) {
  160. MoveY = -1;
  161. } else if (Rnd == 4) {
  162. MoveX = 1;
  163. } else if (Rnd == 5) {
  164. MoveY = 1;
  165. } else if (Rnd == 6) {
  166. MoveX = -1;
  167. MoveY = -1;
  168. } else if (Rnd == 7) {
  169. MoveX = -1;
  170. MoveY = 1;
  171. } else if (Rnd == 8) {
  172. MoveX = 1;
  173. MoveY = -1;
  174. }
  175.  
  176. if (MoveX == 1) {
  177. if (npcs[i].absX + MoveX < npcs[i].makeX + 1) {
  178. npcs[i].moveX = MoveX;
  179. } else {
  180. npcs[i].moveX = 0;
  181. }
  182. }
  183.  
  184. if (MoveX == -1) {
  185. if (npcs[i].absX - MoveX > npcs[i].makeX - 1) {
  186. npcs[i].moveX = MoveX;
  187. } else {
  188. npcs[i].moveX = 0;
  189. }
  190. }
  191.  
  192. if(MoveY == 1) {
  193. if(npcs[i].absY + MoveY < npcs[i].makeY + 1) {
  194. npcs[i].moveY = MoveY;
  195. } else {
  196. npcs[i].moveY = 0;
  197. }
  198. }
  199.  
  200. if(MoveY == -1) {
  201. if(npcs[i].absY - MoveY > npcs[i].makeY - 1) {
  202. npcs[i].moveY = MoveY;
  203. } else {
  204. npcs[i].moveY = 0;
  205. }
  206. }
  207.  
  208.  
  209. int x = (npcs[i].absX + npcs[i].moveX);
  210. int y = (npcs[i].absY + npcs[i].moveY);
  211. /*if (VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, x, y, 0))
  212. npcs[i].getNextNPCMovement(i);
  213. else
  214. {
  215. npcs[i].moveX = 0;
  216. npcs[i].moveY = 0;
  217. }*/
  218. handleClipping(i);
  219. npcs[i].getNextNPCMovement(i);
  220. npcs[i].updateRequired = true;
  221. }
  222. }
  223. }
  224.  
  225.  
  226. if (npcs[i].isDead == true) {
  227. if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) {
  228. npcs[i].updateRequired = true;
  229. npcs[i].facePlayer(0);
  230. npcs[i].killedBy = getNpcKillerId(i);
  231. npcs[i].animNumber = getDeadEmote(i); // dead emote
  232. npcs[i].animUpdateRequired = true;
  233. npcs[i].freezeTimer = 0;
  234. npcs[i].applyDead = true;
  235. killedBarrow(i);
  236. npcs[i].actionTimer = 4; // delete time
  237. resetPlayersInCombat(i);
  238. npcs[i].dagColor = "";
  239. getDtLastKill(i);
  240. } else if (npcs[i].actionTimer == 0 && npcs[i].applyDead == true && npcs[i].needRespawn == false) {
  241. npcs[i].needRespawn = true;
  242. npcs[i].actionTimer = getRespawnTime(i); // respawn time
  243. dropItems(i); // npc drops items!
  244. appendSlayerExperience(i);
  245. appendKillCount(i);
  246. //appendJailKc(i);
  247. npcs[i].absX = npcs[i].makeX;
  248. npcs[i].absY = npcs[i].makeY;
  249. npcs[i].HP = npcs[i].MaxHP;
  250. npcs[i].animNumber = 0x328;
  251. npcs[i].updateRequired = true;
  252. npcs[i].animUpdateRequired = true;
  253. if (npcs[i].npcType >= 2440 && npcs[i].npcType <= 2446) {
  254. Server.objectManager.removeObject(npcs[i].absX, npcs[i].absY);
  255. }
  256. if (npcs[i].npcType == 2745) {
  257. handleJadDeath(i);
  258. }
  259. } else if (npcs[i].actionTimer == 0 && npcs[i].needRespawn == true) {
  260. Client player = (Client) Server.playerHandler.players[npcs[i].spawnedBy];
  261. if(player != null) {
  262. checkDt(i);
  263. checkHfd(i);
  264. checkRfd(i);
  265. npcs[i] = null;
  266. } else {
  267. int old1 = npcs[i].npcType;
  268. int old2 = npcs[i].makeX;
  269. int old3 = npcs[i].makeY;
  270. int old4 = npcs[i].heightLevel;
  271. int old5 = npcs[i].walkingType;
  272. int old6 = npcs[i].MaxHP;
  273. int old7 = npcs[i].maxHit;
  274. int old8 = npcs[i].attack;
  275. int old9 = npcs[i].defence;
  276.  
  277. npcs[i] = null;
  278. newNPC(old1, old2, old3, old4, old5, old6, old7, old8, old9);
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement