Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.33 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.  
  8. for (int i = 0; i < maxNPCs; i++) {
  9. if (npcs[i] != null) {
  10.  
  11.  
  12.  
  13.  
  14.  
  15. if(npcs[i].summon == true) {
  16. Client c = (Client)Server.playerHandler.players[npcs[i].spawnedBy];
  17.  
  18.  
  19. if(c != null && c.npcIndex > 0) {
  20.  
  21. follownpc(i, c.npcIndex);
  22. }
  23.  
  24. if(c != null && c.playerIndex < 1 && npcs[i].summon == true) {
  25. if(!npcs[i].underAttack) {
  26. if(!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(), 2) && c.npcIndex < 1)
  27. followPlayer(i, c.playerId);
  28. }
  29. } else {
  30. if(c != null && npcs[i].summon == true) {
  31. if(!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(), 5) && c.playerIndex < 1 || c.npcIndex < 1)
  32. {
  33. followPlayer(i, c.playerId);
  34. }
  35. }
  36.  
  37. }
  38.  
  39.  
  40. if(c != null && c.lastsummon > 0 && !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(), 10) && npcs[i].summon == true && !npcs[i].isDead)
  41. {
  42.  
  43. npcs[i].isDead = true;
  44. npcs[i].applyDead = true;
  45. c.Summoning.SummonNewNPC(c.lastsummon);
  46. npcs[i].gfx0(1315);
  47. npcs[i].underAttackBy2 = -1;
  48. npcs[i].updateRequired = true;
  49. npcs[i].dirUpdateRequired = true;
  50. npcs[i].getNextWalkingDirection();
  51. }
  52.  
  53.  
  54. if(c != null && c.lastsummon < 0 || c == null)
  55. {
  56. npcs[i].isDead = true;
  57. npcs[i].applyDead = true;
  58. npcs[i].summon = false;
  59. npcs[i].underAttackBy2 = -1;
  60. }
  61.  
  62.  
  63. if(c != null && npcs[i].actionTimer < 1 && npcs[i].summon == true)
  64. {
  65. if(c.playerIndex > 0)
  66. {
  67. Client o = (Client)Server.playerHandler.players[c.playerIndex];
  68. if(o != null) {
  69. if(npcs[i].IsAttackingPerson = true && o.inMulti())
  70. {
  71. followPlayer(i, o.playerId);
  72. attackPlayer(o, i);
  73. npcs[i].index = o.playerId;
  74. npcs[i].actionTimer = 7;
  75. }
  76. }
  77. }
  78. }
  79. }
  80.  
  81. if (npcs[i].npcType == 692) {
  82. if (Misc.random2(2) <= 3) {
  83. npcs[i].updateRequired = true;
  84. npcs[i].forceChat("Get ya Fresh 'ome grown Weed 'ere, 1 Dollar a Gram!");
  85. }
  86. }
  87.  
  88. if (npcs[i].npcType ==2578) {
  89. if (Misc.random2(6) <= 20) {
  90. npcs[i].updateRequired = true;
  91. npcs[i].forceChat("All hail James! Thats right im a fanboy!!");
  92. npcs[i].forceChat("EVERYONE VOTE YES IM A WANNABE MOD!");
  93. npcs[i].forceChat("James is a sexy beast im going to follow him all day!");
  94. }
  95. }
  96.  
  97. if (npcs[i].npcType == 659) {
  98. if (Misc.random2(2) <= 3) {
  99. npcs[i].updateRequired = true;
  100. npcs[i].forceChat("Welcome to the donator zone! Trade me ;)");
  101. }
  102. }
  103.  
  104. if (npcs[i].actionTimer > 0) {
  105. npcs[i].actionTimer--;
  106. }
  107. if (npcs[i].freezeTimer > 0) {
  108. npcs[i].freezeTimer--;
  109. }
  110. if (npcs[i].hitDelayTimer > 0) {
  111. npcs[i].hitDelayTimer--;
  112. }
  113.  
  114. if (npcs[i].hitDelayTimer == 1) {
  115. npcs[i].hitDelayTimer = 0;
  116. applyDamage(i);
  117. }
  118.  
  119. if(npcs[i].attackTimer > 0) {
  120. npcs[i].attackTimer--;
  121. }
  122.  
  123. if(npcs[i].spawnedBy > 0) { // delete summons npc
  124. if(Server.playerHandler.players[npcs[i].spawnedBy] == null
  125. || Server.playerHandler.players[npcs[i].spawnedBy].heightLevel != npcs[i].heightLevel
  126. || Server.playerHandler.players[npcs[i].spawnedBy].respawnTimer > 0
  127. || !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(), 10)) {
  128.  
  129. if(Server.playerHandler.players[npcs[i].spawnedBy] != null) {
  130. for(int o = 0; o < Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs.length; o++){
  131. if(npcs[i].npcType == Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][0]) {
  132. if (Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] == 1)
  133. Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] = 0;
  134. }
  135. }
  136. }
  137. npcs[i] = null;
  138. }
  139. }
  140. if (npcs[i] == null) continue;
  141.  
  142. /**
  143. * Attacking player
  144. **/
  145. if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && !switchesAttackers(i)) {
  146. npcs[i].killerId = getCloseRandomPlayer(i);
  147. } else if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && switchesAttackers(i)) {
  148. npcs[i].killerId = getCloseRandomPlayer(i);
  149. }
  150.  
  151. if (System.currentTimeMillis() - npcs[i].lastDamageTaken > 5000)
  152. npcs[i].underAttackBy = 0;
  153.  
  154. if((npcs[i].killerId > 0 || npcs[i].underAttack) && !npcs[i].walkingHome && retaliates(npcs[i].npcType)) {
  155. if(!npcs[i].isDead) {
  156. int p = npcs[i].killerId;
  157. if(Server.playerHandler.players[p] != null) {
  158. Client c = (Client) Server.playerHandler.players[p];
  159. followPlayer(i, c.playerId);
  160. if (npcs[i] == null) continue;
  161. if(npcs[i].attackTimer == 0) {
  162. if(c != null) {
  163. attackPlayer(c, i);
  164. } else {
  165. npcs[i].killerId = 0;
  166. npcs[i].underAttack = false;
  167. npcs[i].facePlayer(0);
  168. }
  169. }
  170. } else {
  171. npcs[i].killerId = 0;
  172. npcs[i].underAttack = false;
  173. npcs[i].facePlayer(0);
  174. }
  175. }
  176. }
  177. /**
  178. * Random walking and walking home
  179. **/
  180. if (npcs[i] == null) continue;
  181. if((!npcs[i].underAttack || npcs[i].walkingHome) && npcs[i].randomWalk && !npcs[i].isDead) {
  182. npcs[i].facePlayer(0);
  183. npcs[i].killerId = 0;
  184. if(npcs[i].spawnedBy == 0) {
  185. 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)) {
  186. npcs[i].walkingHome = true;
  187. }
  188. }
  189.  
  190. if (npcs[i].walkingHome && npcs[i].absX == npcs[i].makeX && npcs[i].absY == npcs[i].makeY) {
  191. npcs[i].walkingHome = false;
  192. } else if(npcs[i].walkingHome) {
  193. npcs[i].moveX = GetMove(npcs[i].absX, npcs[i].makeX);
  194. npcs[i].moveY = GetMove(npcs[i].absY, npcs[i].makeY);
  195. npcs[i].getNextNPCMovement(i);
  196. npcs[i].updateRequired = true;
  197. }
  198. if(npcs[i].walkingType == 1) {
  199. if(Misc.random(3)== 1 && !npcs[i].walkingHome) {
  200. int MoveX = 0;
  201. int MoveY = 0;
  202. int Rnd = Misc.random(9);
  203. if (Rnd == 1) {
  204. MoveX = 1;
  205. MoveY = 1;
  206. } else if (Rnd == 2) {
  207. MoveX = -1;
  208. } else if (Rnd == 3) {
  209. MoveY = -1;
  210. } else if (Rnd == 4) {
  211. MoveX = 1;
  212. } else if (Rnd == 5) {
  213. MoveY = 1;
  214. } else if (Rnd == 6) {
  215. MoveX = -1;
  216. MoveY = -1;
  217. } else if (Rnd == 7) {
  218. MoveX = -1;
  219. MoveY = 1;
  220. } else if (Rnd == 8) {
  221. MoveX = 1;
  222. MoveY = -1;
  223. }
  224.  
  225. if (MoveX == 1) {
  226. if (npcs[i].absX + MoveX < npcs[i].makeX + 1) {
  227. npcs[i].moveX = MoveX;
  228. } else {
  229. npcs[i].moveX = -1;
  230. }
  231. }
  232.  
  233. if (MoveX == -1) {
  234. if (npcs[i].absX - MoveX > npcs[i].makeX - 1) {
  235. npcs[i].moveX = MoveX;
  236. } else {
  237. npcs[i].moveX = -1;
  238. }
  239. }
  240.  
  241. if(MoveY == 1) {
  242. if(npcs[i].absY + MoveY < npcs[i].makeY + 1) {
  243. npcs[i].moveY = MoveY;
  244. } else {
  245. npcs[i].moveY = -1;
  246. }
  247. }
  248.  
  249. if(MoveY == -1) {
  250. if(npcs[i].absY - MoveY > npcs[i].makeY - 1) {
  251. npcs[i].moveY = MoveY;
  252. } else {
  253. npcs[i].moveY = -1;
  254. }
  255. }
  256.  
  257.  
  258. int x = (npcs[i].absX + npcs[i].moveX);
  259. int y = (npcs[i].absY + npcs[i].moveY);
  260. if (VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, x, y, 0))
  261. npcs[i].getNextNPCMovement(i);
  262. else
  263. {
  264. npcs[i].moveX = -1;
  265. npcs[i].moveY = -1;
  266. }
  267. npcs[i].updateRequired = true;
  268. }
  269. }
  270. }
  271.  
  272. if (npcs[i].isDead == true) {
  273. if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) {
  274. npcs[i].updateRequired = true;
  275. npcs[i].facePlayer(0);
  276. npcs[i].killedBy = getNpcKillerId(i);
  277. npcs[i].animNumber = getDeadEmote(i); // dead emote
  278. npcs[i].animUpdateRequired = true;
  279. npcs[i].freezeTimer = 0;
  280. npcs[i].applyDead = true;
  281. killedBarrow(i);
  282. if (isFightCaveNpc(i))
  283. killedTzhaar(i);
  284. if(npcs[i].summon == true)
  285. npcs[i].summon = false;
  286. npcs[i].actionTimer = 4; // delete time
  287. resetPlayersInCombat(i);
  288. /*if (npcs[i].npcType == 1158){
  289. handleKalpite(i);
  290. }*/
  291.  
  292.  
  293. } else if (npcs[i] != null && npcs[i].actionTimer == 0 && npcs[i].applyDead == true && npcs[i].needRespawn == false) {
  294. //if (npcs[i] != null) {
  295. npcs[i].needRespawn = true;
  296. npcs[i].actionTimer = getRespawnTime(i); // respawn time
  297. dropItems(i); // npc drops items!
  298. appendSlayerExperience(i);
  299. //appendKillCount(i);
  300. Player.npcKills += 1;
  301. npcs[i].absX = npcs[i].makeX;
  302. npcs[i].absY = npcs[i].makeY;
  303. npcs[i].HP = npcs[i].MaxHP;
  304. npcs[i].animNumber = 0x328;
  305. npcs[i].updateRequired = true;
  306. npcs[i].animUpdateRequired = true;
  307. if (npcs[i].npcType >= 2440 && npcs[i].npcType <= 2446) {
  308. Server.objectManager.removeObject(npcs[i].absX, npcs[i].absY);
  309. }
  310. if (npcs[i].npcType == 2745) {
  311. handleJadDeath(i);
  312. }
  313. if (npcs[i].npcType == 3491) {
  314. handleRFDDeath(i);
  315. }
  316.  
  317. if (npcs[i] != null && npcs[i].npcType != 1158){
  318. if (!npcs[i].needRespawn){
  319. npcs[i] = null;
  320. for (int j = 1; j < Config.MAX_PLAYERS; j++) {
  321. if (Server.playerHandler.players[j] != null) {
  322. Server.playerHandler.players[j].RebuildNPCList = true;
  323. }
  324. }
  325. continue;
  326. }
  327. npcs[i].needRespawn = true;
  328. npcs[i].actionTimer = 30;
  329. npcs[i].absX = npcs[i].makeX;
  330. npcs[i].absY = npcs[i].makeY - 1;
  331. } else if (npcs[i] != null && npcs[i].npcType == 1158) {
  332. npcs[i] = null;
  333. for (int j = 1; j < Config.MAX_PLAYERS; j++) {
  334. if (Server.playerHandler.players[j] != null){
  335. Server.playerHandler.players[j].RebuildNPCList = true;
  336. }
  337. }
  338. }
  339.  
  340. } else if (npcs[i].actionTimer == 0 && npcs[i].needRespawn == true) {
  341. if(npcs[i].spawnedBy > 0) {
  342. npcs[i] = null;
  343. } else {
  344. /*if (npcs[i].actionTimer <= 0 && npcs[i].needRespawn && npcs[i].NeedsRespawn) {
  345. for (int j = 1; j < Config.MAX_PLAYERS; j++) {
  346. if (Server.playerHandler.players[j] != null) {
  347. Server.playerHandler.players[j].RebuildNPCList = true;
  348. }
  349. }*/
  350. int type = npcs[i].npcType;
  351. if (type == 1160)
  352. type = 1158;
  353. int x = npcs[i].makeX;
  354. int y = npcs[i].makeY;
  355. int height = npcs[i].heightLevel;
  356. int walk = npcs[i].walkingType;
  357. int mHp = npcs[i].MaxHP;
  358. int mHit = npcs[i].maxHit;
  359. int attack = npcs[i].attack;
  360. int defence = npcs[i].defence;
  361.  
  362. npcs[i] = null;
  363. newNPC(type, x, y, height, walk, mHp, mHit, attack, defence);
  364. }
  365. }
  366. }
  367. }
  368. }
  369. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement