Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void process() {
- for (int i = 0; i < maxNPCs; i++) {
- if (npcs[i] == null) continue;
- npcs[i].clearUpdateFlags();
- }
- /* if (npcs[i].npcType == 812){
- if (Misc.random(10) == 4)
- npcs[i].forceChat(guardRandomTalk[Misc.random3(guardRandomTalk.length)]);
- } */
- for (int i = 0; i < maxNPCs; i++) {
- if (npcs[i] != null) {
- if (npcs[i].actionTimer > 0) {
- npcs[i].actionTimer--;
- }
- if (npcs[i].freezeTimer > 0) {
- npcs[i].freezeTimer--;
- }
- if (npcs[i].hitDelayTimer > 0) {
- npcs[i].hitDelayTimer--;
- }
- if (npcs[i].hitDelayTimer == 1) {
- npcs[i].hitDelayTimer = 0;
- applyDamage(i);
- }
- if(npcs[i].attackTimer > 0) {
- npcs[i].attackTimer--;
- }
- if (npcs[i] != null) {
- Client c = (Client) PlayerHandler.players[NPCHandler.npcs[i].spawnedBy];
- if (c != null
- && c.familiarID > 0
- && !PlayerHandler.players[npcs[i].spawnedBy]
- .goodDistance(
- npcs[i].getX(),
- npcs[i].getY(),
- PlayerHandler.players[npcs[i].spawnedBy]
- .getX(),
- PlayerHandler.players[npcs[i].spawnedBy]
- .getY(), 10)
- && npcs[i].summon == true && !npcs[i].isDead) {
- npcs[i].isDead = true;
- npcs[i].applyDead = true;
- Summoning.spawnFamiliar(c, c.familiarID);
- npcs[i].underAttackBy2 = -1;
- npcs[i].dirUpdateRequired = true;
- npcs[i].getNextWalkingDirection();
- }
- if (c != null && npcs[i].actionTimer < 1
- && npcs[i].summon == true) {
- if (c.playerIndex > 0) {
- Client o = (Client) PlayerHandler.players[c.playerIndex];
- if (o != null) {
- if (c.underAttackBy2 > 0 && o.inMulti()
- || c.underAttackBy > 0 && o.inMulti()) {
- followPlayer(o, i, o.playerId);
- attackPlayer(o, i);
- npcs[i].index = o.playerId;
- npcs[i].actionTimer = 7;
- }
- }
- }
- }
- if(npcs[i].spawnedBy > 0) { // delete summons npc
- if(Server.playerHandler.players[npcs[i].spawnedBy] == null
- || Server.playerHandler.players[npcs[i].spawnedBy].heightLevel != npcs[i].heightLevel
- || Server.playerHandler.players[npcs[i].spawnedBy].respawnTimer > 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(), 20)) {
- if(Server.playerHandler.players[npcs[i].spawnedBy] != null) {
- for(int o = 0; o < Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs.length; o++){
- if(npcs[i].npcType == Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][0]) {
- if (Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] == 1)
- Server.playerHandler.players[npcs[i].spawnedBy].barrowsNpcs[o][1] = 0;
- }
- }
- }
- npcs[i] = null;
- }
- }
- if (npcs[i] == null) continue;
- /**
- * Attacking player
- **/
- if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && !switchesAttackers(i)) {
- npcs[i].killerId = getCloseRandomPlayer(i);
- } else if (isAggressive(i) && !npcs[i].underAttack && !npcs[i].isDead && switchesAttackers(i)) {
- npcs[i].killerId = getCloseRandomPlayer(i);
- }
- if (System.currentTimeMillis() - npcs[i].lastDamageTaken > 5000)
- npcs[i].underAttackBy = 0;
- if((npcs[i].killerId > 0 || npcs[i].underAttack) && !npcs[i].walkingHome && retaliates(npcs[i].npcType)) {
- if(!npcs[i].isDead) {
- int p = npcs[i].killerId;
- if(Server.playerHandler.players[p] != null) {
- Client c1 = (Client) Server.playerHandler.players[p];
- followPlayer(c1, i, c1.playerId);
- if (npcs[i] == null) continue;
- if(npcs[i].attackTimer == 0) {
- if(c1 != null) {
- attackPlayer(c1, i);
- } else {
- npcs[i].killerId = 0;
- npcs[i].underAttack = false;
- npcs[i].facePlayer(0);
- }
- }
- } else {
- npcs[i].killerId = 0;
- npcs[i].underAttack = false;
- npcs[i].facePlayer(0);
- }
- }
- }
- /**
- * Random walking and walking home
- **/
- if (npcs[i] == null) continue;
- if((!npcs[i].underAttack || npcs[i].walkingHome) && npcs[i].randomWalk && !npcs[i].isDead) {
- npcs[i].facePlayer(0);
- npcs[i].killerId = 0;
- if(npcs[i].spawnedBy == 0) {
- 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)) {
- npcs[i].walkingHome = true;
- }
- }
- if (npcs[i].walkingHome && npcs[i].absX == npcs[i].makeX && npcs[i].absY == npcs[i].makeY) {
- npcs[i].walkingHome = false;
- } else if(npcs[i].walkingHome) {
- npcs[i].moveX = GetMove(npcs[i].absX, npcs[i].makeX);
- npcs[i].moveY = GetMove(npcs[i].absY, npcs[i].makeY);
- npcs[i].getNextNPCMovement(i);
- npcs[i].updateRequired = true;
- }
- if(npcs[i].walkingType == 1) {
- if(Misc.random(3)== 1 && !npcs[i].walkingHome) {
- int MoveX = 0;
- int MoveY = 0;
- int Rnd = Misc.random(9);
- if (Rnd == 1) {
- MoveX = 1;
- MoveY = 1;
- } else if (Rnd == 2) {
- MoveX = -1;
- } else if (Rnd == 3) {
- MoveY = -1;
- } else if (Rnd == 4) {
- MoveX = 1;
- } else if (Rnd == 5) {
- MoveY = 1;
- } else if (Rnd == 6) {
- MoveX = -1;
- MoveY = -1;
- } else if (Rnd == 7) {
- MoveX = -1;
- MoveY = 1;
- } else if (Rnd == 8) {
- MoveX = 1;
- MoveY = -1;
- }
- if (MoveX == 1) {
- if (npcs[i].absX + MoveX < npcs[i].makeX + 1) {
- npcs[i].moveX = MoveX;
- } else {
- npcs[i].moveX = 0;
- }
- }
- if (MoveX == -1) {
- if (npcs[i].absX - MoveX > npcs[i].makeX - 1) {
- npcs[i].moveX = MoveX;
- } else {
- npcs[i].moveX = 0;
- }
- }
- if(MoveY == 1) {
- if(npcs[i].absY + MoveY < npcs[i].makeY + 1) {
- npcs[i].moveY = MoveY;
- } else {
- npcs[i].moveY = 0;
- }
- }
- if(MoveY == -1) {
- if(npcs[i].absY - MoveY > npcs[i].makeY - 1) {
- npcs[i].moveY = MoveY;
- } else {
- npcs[i].moveY = 0;
- }
- }
- int x = (npcs[i].absX + npcs[i].moveX);
- int y = (npcs[i].absY + npcs[i].moveY);
- /*if (VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, x, y, 0))
- npcs[i].getNextNPCMovement(i);
- else
- {
- npcs[i].moveX = 0;
- npcs[i].moveY = 0;
- }*/
- handleClipping(i);
- npcs[i].getNextNPCMovement(i);
- npcs[i].updateRequired = true;
- }
- }
- }
- if (npcs[i].isDead == true) {
- if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) {
- npcs[i].updateRequired = true;
- npcs[i].facePlayer(0);
- npcs[i].killedBy = getNpcKillerId(i);
- npcs[i].animNumber = getDeadEmote(i); // dead emote
- npcs[i].animUpdateRequired = true;
- npcs[i].freezeTimer = 0;
- npcs[i].applyDead = true;
- killedBarrow(i);
- npcs[i].actionTimer = 4; // delete time
- resetPlayersInCombat(i);
- npcs[i].dagColor = "";
- getDtLastKill(i);
- } else if (npcs[i].actionTimer == 0 && npcs[i].applyDead == true && npcs[i].needRespawn == false) {
- npcs[i].needRespawn = true;
- npcs[i].actionTimer = getRespawnTime(i); // respawn time
- dropItems(i); // npc drops items!
- appendSlayerExperience(i);
- appendKillCount(i);
- //appendJailKc(i);
- npcs[i].absX = npcs[i].makeX;
- npcs[i].absY = npcs[i].makeY;
- npcs[i].HP = npcs[i].MaxHP;
- npcs[i].animNumber = 0x328;
- npcs[i].updateRequired = true;
- npcs[i].animUpdateRequired = true;
- if (npcs[i].npcType >= 2440 && npcs[i].npcType <= 2446) {
- Server.objectManager.removeObject(npcs[i].absX, npcs[i].absY);
- }
- if (npcs[i].npcType == 2745) {
- handleJadDeath(i);
- }
- } else if (npcs[i].actionTimer == 0 && npcs[i].needRespawn == true) {
- Client player = (Client) Server.playerHandler.players[npcs[i].spawnedBy];
- if(player != null) {
- checkDt(i);
- checkHfd(i);
- checkRfd(i);
- npcs[i] = null;
- } else {
- int old1 = npcs[i].npcType;
- int old2 = npcs[i].makeX;
- int old3 = npcs[i].makeY;
- int old4 = npcs[i].heightLevel;
- int old5 = npcs[i].walkingType;
- int old6 = npcs[i].MaxHP;
- int old7 = npcs[i].maxHit;
- int old8 = npcs[i].attack;
- int old9 = npcs[i].defence;
- npcs[i] = null;
- newNPC(old1, old2, old3, old4, old5, old6, old7, old8, old9);
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement