Code:
package server.model.npcs;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import server.Config;
import server.Server;
import server.model.players.Client;
import server.util.Misc;
import server.world.map.VirtualWorld;
import server.event.EventManager;
import server.event.Event;
import server.event.EventContainer;
public class NPCHandler {
public static int maxNPCs = 10000;
public static int maxListedNPCs = 10000;
public static NPCDrops drop[] = new NPCDrops[3500];
public static NPC npcs[] = new NPC[maxNPCs];
public static NPCList NpcList[] = new NPCList[maxListedNPCs];
public NPCHandler() {
for(int i = 0; i < maxNPCs; i++) {
npcs[i] = null;
}
for(int i = 0; i < maxListedNPCs; i++) {
NpcList[i] = null;
}
for(int i = 0; i < 3500; i ++) {
NPCDrops newNpc = new NPCDrops(i);
drop[i] = newNpc;
}
loadDrops("./Data/CFG/npcdrops.cfg");
loadNPCList("./Data/CFG/npc.cfg");
loadNPCSounds("./Data/CFG/npcsounds.cfg");
loadAutoSpawn("./Data/CFG/spawn-config.cfg");
}
public void multiAttackGfx(int i, int gfx) {
if (npcs[i].projectileId < 0)
return;
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
Client c = (Client)Server.playerHandler.players[j];
if (c.heightLevel != npcs[i].heightLevel)
continue;
if (Server.playerHandler.players[j].goodDistance(c.absX, c.absY, npcs[i].absX, npcs[i].absY, 15)) {
int nX = Server.npcHandler.npcs[i].getX() + offset(i);
int nY = Server.npcHandler.npcs[i].getY() + offset(i);
int pX = c.getX();
int pY = c.getY();
int offX = (nY - pY)* -1;
int offY = (nX - pX)* -1;
c.getPA().createPlayersProjectile(nX, nY, offX, offY, 50, getProjectileSpeed(i), npcs[i].projectileId, 43, 31, -c.getId() - 1, 65);
}
}
}
}
public boolean switchesAttackers(int i) {
switch(npcs[i].npcType) {
case 2551:
case 2552:
case 2553:
case 2559:
case 2560:
case 2561:
case 2563:
case 2564:
case 2565:
case 2892:
case 2894:
return true;
}
return false;
}
public void multiAttackDamage(int i) {
int max = getMaxHit(i);
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
Client c = (Client)Server.playerHandler.players[j];
if (c.isDead || c.heightLevel != npcs[i].heightLevel)
continue;
if (Server.playerHandler.players[j].goodDistance(c.absX, c.absY, npcs[i].absX, npcs[i].absY, 15)) {
if (npcs[i].attackType == 2) {
if (!c.prayerActive[16]) {
if (Misc.random(500) + 200 > Misc.random(c.getCombat().mageDef())) {
int dam = Misc.random(max);
c.dealDamage(dam);
c.handleHitMask(dam);
} else {
c.dealDamage(0);
c.handleHitMask(0);
}
} else {
c.dealDamage(0);
c.handleHitMask(0);
}
} else if (npcs[i].attackType == 1) {
if (!c.prayerActive[17]) {
int dam = Misc.random(max);
if (Misc.random(500) + 200 > Misc.random(c.getCombat().calculateRangeDefence())) {
c.dealDamage(dam);
c.handleHitMask(dam);
} else {
c.dealDamage(0);
c.handleHitMask(0);
}
} else {
c.dealDamage(0);
c.handleHitMask(0);
}
}
if (npcs[i].endGfx > 0) {
c.gfx0(npcs[i].endGfx);
}
}
c.getPA().refreshSkill(3);
}
}
}
public int getClosePlayer(int i) {
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
if (j == npcs[i].spawnedBy)
return j;
if (goodDistance(Server.playerHandler.players[j].absX, Server.playerHandler.players[j].absY, npcs[i].absX, npcs[i].absY, 2 + distanceRequired(i) + followDistance(i)) || isFightCaveNpc(i)) {
if ((Server.playerHandler.players[j].underAttackBy <= 0 && Server.playerHandler.players[j].underAttackBy2 <= 0) || Server.playerHandler.players[j].inMulti())
if (Server.playerHandler.players[j].heightLevel == npcs[i].heightLevel)
return j;
}
}
}
return 0;
}
public int getCloseRandomPlayer(int i) {
ArrayList<Integer> players = new ArrayList<Integer>();
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
if (goodDistance(Server.playerHandler.players[j].absX, Server.playerHandler.players[j].absY, npcs[i].absX, npcs[i].absY, 2 + distanceRequired(i) + followDistance(i)) || isFightCaveNpc(i)) {
if ((Server.playerHandler.players[j].underAttackBy <= 0 && Server.playerHandler.players[j].underAttackBy2 <= 0) || Server.playerHandler.players[j].inMulti())
if (Server.playerHandler.players[j].heightLevel == npcs[i].heightLevel)
players.add(j);
}
}
}
if (players.size() > 0)
return players.get(Misc.random(players.size() -1));
else
return 0;
}
public int npcSize(int i) {
switch (npcs[i].npcType) {
case 2883:
case 2882:
case 2881:
return 3;
}
return 0;
}
public boolean isAggressive(int i) {
switch (npcs[i].npcType) {
case 2550:
case 2551:
case 2552:
case 2553:
case 2558:
case 2559:
case 2560:
case 2561:
case 2562:
case 2563:
case 2564:
case 2565:
case 2892:
case 2894:
case 2881:
case 2882:
case 2883:
return true;
}
if (npcs[i].inWild() && npcs[i].MaxHP > 0)
return true;
if (isFightCaveNpc(i))
return true;
return false;
}
public boolean isFightCaveNpc(int i) {
switch (npcs[i].npcType) {
case 2627:
case 2630:
case 2631:
case 2741:
case 2743:
case 2745:
return true;
}
return false;
}
/**
* Summon npc, barrows, etc
**/
public void spawnNpc(Client c, int npcType, int x, int y, int heightLevel, int WalkingType, int HP, int maxHit, int attack, int defence, boolean attackPlayer, boolean headIcon) {
// first, search for a free slot
int slot = -1;
for (int i = 1; i < maxNPCs; i++) {
if (npcs[i] == null) {
slot = i;
break;
}
}
if(slot == -1) {
//Misc.println("No Free Slot");
return; // no free slot found
}
NPC newNPC = new NPC(slot, npcType);
newNPC.absX = x;
newNPC.absY = y;
newNPC.makeX = x;
newNPC.makeY = y;
newNPC.heightLevel = heightLevel;
newNPC.walkingType = WalkingType;
newNPC.HP = HP;
newNPC.MaxHP = HP;
newNPC.maxHit = maxHit;
newNPC.attack = attack;
newNPC.defence = defence;
newNPC.spawnedBy = c.getId();
if(headIcon)
c.getPA().drawHeadicon(1, slot, 0, 0);
if(attackPlayer) {
newNPC.underAttack = true;
if(c != null) {
newNPC.killerId = c.playerId;
}
}
npcs[slot] = newNPC;
}
public void spawnNpc2(int npcType, int x, int y, int heightLevel, int WalkingType, int HP, int maxHit, int attack, int defence) {
// first, search for a free slot
int slot = -1;
for (int i = 1; i < maxNPCs; i++) {
if (npcs[i] == null) {
slot = i;
break;
}
}
if(slot == -1) {
//Misc.println("No Free Slot");
return; // no free slot found
}
NPC newNPC = new NPC(slot, npcType);
newNPC.absX = x;
newNPC.absY = y;
newNPC.makeX = x;
newNPC.makeY = y;
newNPC.heightLevel = heightLevel;
newNPC.walkingType = WalkingType;
newNPC.HP = HP;
newNPC.MaxHP = HP;
newNPC.maxHit = maxHit;
newNPC.attack = attack;
newNPC.defence = defence;
npcs[slot] = newNPC;
}
/**
* Attack delays
**/
public int getNpcDelay(int i) {
switch(npcs[i].npcType) {
case 2025:
case 2028:
return 7;
case 2745:
return 8;
case 2558:
case 2559:
case 2560:
case 2561:
case 2550:
return 6;
//saradomin gw boss
case 2562:
return 2;
default:
return 5;
}
}
/**
* Hit delays
**/
public int getHitDelay(int i) {
switch(npcs[i].npcType) {
case 2881:
case 2882:
case 3200:
case 2892:
case 2894:
return 3;
case 2743:
case 2631:
case 2558:
case 2559:
case 2560:
return 3;
case 2745:
if (npcs[i].attackType == 1 || npcs[i].attackType == 2)
return 5;
else
return 2;
case 2025:
return 4;
case 2028:
return 3;
default:
return 2;
}
}
/**
* Npc respawn time
**/
public int getRespawnTime(int i) {
switch(npcs[i].npcType) {
case 2881:
case 2882:
case 2883:
case 2558:
case 2559:
case 2560:
case 2561:
case 2562:
case 2563:
case 2564:
case 2550:
case 2551:
case 2552:
case 2553:
return 100;
case 3777:
case 3778:
case 3779:
case 3780:
return 500;
default:
return 25;
}
}
public void newNPC(int npcType, int x, int y, int heightLevel, int WalkingType, int HP) {
// first, search for a free slot
int slot = -1;
for (int i = 1; i < maxNPCs; i++) {
if (npcs[i] == null) {
slot = i;
break;
}
}
if(slot == -1) return; // no free slot found
NPC newNPC = new NPC(slot, npcType);
newNPC.absX = x;
newNPC.absY = y;
newNPC.makeX = x;
newNPC.makeY = y;
newNPC.heightLevel = heightLevel;
newNPC.walkingType = WalkingType;
newNPC.dirUpdateRequired = true;
newNPC.updateRequired = true;
newNPC.HP = HP;
newNPC.MaxHP = HP;
newNPC.maxHit = getNpcListMaxHit(npcType);
newNPC.attack = getNpcListAttack(npcType);;
newNPC.defence = getNpcListDefence(npcType);;
npcs[slot] = newNPC;
}
public void newNPCList(int npcType, String npcName, int combat, int HP, int maxHit, int attack, int defence, int atkanim, int blockanim, int dieanim) {
if(atkanim == 0)
atkanim = 0x326;
// first, search for a free slot
int slot = -1;
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] == null) {
slot = i;
break;
}
}
if(slot == -1) return; // no free slot found
NPCList newNPCList = new NPCList(npcType);
newNPCList.npcName = npcName;
newNPCList.npcCombat = combat;
newNPCList.npcHealth = HP;
newNPCList.maxHit = maxHit;
newNPCList.attack = attack;
newNPCList.defence = defence;
newNPCList.atkanim = atkanim;
newNPCList.blockanim = blockanim;
newNPCList.dieanim = dieanim;
NpcList[slot] = newNPCList;
}
public void newNPCSound(int npcId, int attack, int block, int die) {
System.out.println("New npc sound: "+npcId+", "+attack+", "+block+", "+die);
int slot = -1;
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i].npcId == npcId) {
slot = i;
break;
}
}
if(slot == -1) return; // npc entry not found
NpcList[slot].attackSound = attack;
NpcList[slot].blockSound = block;
NpcList[slot].dieSound = die;
}
public void process() {
for (int i = 0; i < maxNPCs; i++) {
if (npcs[i] == null) continue;
npcs[i].clearUpdateFlags();
}
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].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 c = (Client) Server.playerHandler.players[p];
followPlayer(i, c.playerId);
if (npcs[i] == null) continue;
if(npcs[i].attackTimer == 0) {
if(c != null) {
attackPlayer(c, 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 && VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, npcs[i].absX + 1, npcs[i].absY + 1, 0)) {
MoveX = 1;
MoveY = 1;
} else if (Rnd == 2 && VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, npcs[i].absX - 1, npcs[i].absY, 0)) {
MoveX = -1;
} else if (Rnd == 3 && VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, npcs[i].absX, npcs[i].absY - 1, 0)) {
MoveY = -1;
} else if (Rnd == 4 && VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, npcs[i].absX + 1, npcs[i].absY, 0)) {
MoveX = 1;
} else if (Rnd == 5 && VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, npcs[i].absX, npcs[i].absY + 1, 0)) {
MoveY = 1;
} else if (Rnd == 6 && VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, npcs[i].absX - 1, npcs[i].absY - 1, 0)) {
MoveX = -1;
MoveY = -1;
} else if (Rnd == 7 && VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, npcs[i].absX - 1, npcs[i].absY + 1, 0)) {
MoveX = -1;
MoveY = 1;
} else if (Rnd == 8 && VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, npcs[i].absX + 1, npcs[i].absY - 1, 0)) {
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;
}
}
if (!VirtualWorld.I(npcs[i].heightLevel, npcs[i].absX, npcs[i].absY, (npcs[i].absX + npcs[i].moveX), (npcs[i].absY + npcs[i].moveY), 0)) {
npcs[i].moveX = 0;
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;
}
npcs[i].updateRequired = true;
}
}
}
if(!npcs[i].isDead) {
if(npcs[i].walkingType != 0) {
switch(npcs[i].walkingType) {
case 5:
npcs[i].turnNpc(npcs[i].absX-1, npcs[i].absY);
break;
case 4:
npcs[i].turnNpc(npcs[i].absX+1, npcs[i].absY);
break;
case 3:
npcs[i].turnNpc(npcs[i].absX, npcs[i].absY-1);
break;
case 2:
npcs[i].turnNpc(npcs[i].absX, npcs[i].absY+1);
break;
}
}
npcs[i].updateRequired = true;
}
if (npcs[i].isDead == true) {
if(npcs[i].actionTimer == 3 && npcs[i].applyDead == true && npcs[i].needRespawn == false) {
Client c = (Client)Server.playerHandler.players[npcs[i].killedBy];
c.getPA().sound(getNpcListDieSound(npcs[i].npcType));
}
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(npcs[i].npcType); // dead emote
npcs[i].animUpdateRequired = true;
npcs[i].freezeTimer = 0;
npcs[i].applyDead = true;
killedBarrow(i);
if (isFightCaveNpc(i))
killedTzhaar(i);
npcs[i].actionTimer = 4; // delete time
resetPlayersInCombat(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!
Client c = (Client)Server.playerHandler.players[npcs[i].killedBy];
c.getSlayer().killSlayerNpc(i);
appendKillCount(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, 10);
}
if (npcs[i].npcType == 2745) {
handleJadDeath(i);
}
} else if (npcs[i].actionTimer == 0 && npcs[i].needRespawn == true) {
if(npcs[i].spawnedBy > 0) {
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;
npcs[i] = null;
newNPC(old1, old2, old3, old4, old5, old6);
}
}
}
}
}
}
public boolean getsPulled(int i) {
switch (npcs[i].npcType) {
case 2550:
if (npcs[i].firstAttacker > 0)
return false;
break;
}
return true;
}
public boolean multiAttacks(int i) {
switch (npcs[i].npcType) {
case 2558:
return true;
case 2562:
if (npcs[i].attackType == 2)
return true;
case 2550:
if (npcs[i].attackType == 1)
return true;
default:
return false;
}
}
/**
* Npc killer id?
**/
public int getNpcKillerId(int npcId) {
int oldDamage = 0;
int count = 0;
int killerId = 0;
for (int p = 1; p < Config.MAX_PLAYERS; p++) {
if (Server.playerHandler.players[p] != null) {
if(Server.playerHandler.players[p].lastNpcAttacked == npcId) {
if(Server.playerHandler.players[p].totalDamageDealt > oldDamage) {
oldDamage = Server.playerHandler.players[p].totalDamageDealt;
killerId = p;
}
Server.playerHandler.players[p].totalDamageDealt = 0;
}
}
}
return killerId;
}
/**
*
*/
private void killedBarrow(int i) {
Client c = (Client)Server.playerHandler.players[npcs[i].killedBy];
if(c != null) {
for(int o = 0; o < c.barrowsNpcs.length; o++){
if(npcs[i].npcType == c.barrowsNpcs[o][0]) {
c.barrowsNpcs[o][1] = 2; // 2 for dead
c.barrowsKillCount++;
}
}
}
}
private void killedTzhaar(int i) {
final Client c2 = (Client)Server.playerHandler.players[npcs[i].spawnedBy];
c2.tzhaarKilled++;
//System.out.println("To kill: " + c2.tzhaarToKill + " killed: " + c2.tzhaarKilled);
if (c2.tzhaarKilled == c2.tzhaarToKill) {
//c2.sendMessage("STARTING EVENT");
c2.waveId++;
EventManager.getSingleton().addEvent(new Event() {
public void execute(EventContainer c) {
if (c2 != null) {
Server.fightCaves.spawnNextWave(c2);
}
c.stop();
}
}, 7500);
}
}
public void handleJadDeath(int i) {
Client c = (Client)Server.playerHandler.players[npcs[i].spawnedBy];
c.getItems().addItem(6570,1);
c.sendMessage("Congratulations on completing the fight caves minigame!");
c.getPA().resetTzhaar();
c.waveId = 300;
}
/**
* Dropping Items!
**/
public void dropItems(int j) {
int npcId = npcs[j].npcType;
Client c = (Client)Server.playerHandler.players[npcs[j].killedBy];
if(c != null) {
for(int i = 0; i < drop[npcId].itemId.length; i ++) {
if(drop[npcId].itemId[i] == 0)
break;
int dropChance = 1 + Misc.random(999);
System.out.println("Drop chance: "+dropChance);
if(drop[npcId].chance[i] >= dropChance)
Server.itemHandler.createGroundItem(c, drop[npcId].itemId[i], npcs[j].absX, npcs[j].absY, drop[npcId].itemAmount[i], c.playerId);
}
}
}
public void appendKillCount(int i) {
Client c = (Client)Server.playerHandler.players[npcs[i].killedBy];
if(c != null) {
int[] kcMonsters = {122,49,2558,2559,2560,2561,2550,2551,2552,2553,2562,2563,2564,2565};
for (int j : kcMonsters) {
if (npcs[i].npcType == j) {
if (c.killCount < 20) {
c.killCount++;
c.sendMessage("Killcount: " + c.killCount);
} else {
c.sendMessage("You already have 20 kill count");
}
break;
}
}
}
}
/**
* Resets players in combat
*/
public void resetPlayersInCombat(int i) {
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null)
if (Server.playerHandler.players[j].underAttackBy2 == i)
Server.playerHandler.players[j].underAttackBy2 = 0;
}
}
/**
* Npc Follow Player
**/
public int GetMove(int Place1,int Place2) {
if ((Place1 - Place2) == 0) {
return 0;
} else if ((Place1 - Place2) < 0) {
return 1;
} else if ((Place1 - Place2) > 0) {
return -1;
}
return 0;
}
public boolean followPlayer(int i) {
switch (npcs[i].npcType) {
case 2892:
case 2894:
return false;
}
return true;
}
public void followPlayer(int i, int playerId) {
if (Server.playerHandler.players[playerId] == null) {
return;
}
if (Server.playerHandler.players[playerId].respawnTimer > 0) {
npcs[i].facePlayer(0);
npcs[i].randomWalk = true;
npcs[i].underAttack = false;
return;
}
if (!followPlayer(i)) {
npcs[i].facePlayer(playerId);
return;
}
int playerX = Server.playerHandler.players[playerId].absX;
int playerY = Server.playerHandler.players[playerId].absY;
npcs[i].randomWalk = false;
if (goodDistance(npcs[i].getX(), npcs[i].getY(), playerX, playerY, distanceRequired(i)))
return;
if((npcs[i].spawnedBy > 0) || ((npcs[i].absX < npcs[i].makeX + Config.NPC_FOLLOW_DISTANCE) && (npcs[i].absX > npcs[i].makeX - Config.NPC_FOLLOW_DISTANCE) && (npcs[i].absY < npcs[i].makeY + Config.NPC_FOLLOW_DISTANCE) && (npcs[i].absY > npcs[i].makeY - Config.NPC_FOLLOW_DISTANCE))) {
if(npcs[i].heightLevel == Server.playerHandler.players[playerId].heightLevel) {
if(Server.playerHandler.players[playerId] != null && npcs[i] != null) {
if(playerY < npcs[i].absY) {
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
} else if(playerY > npcs[i].absY) {
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
} else if(playerX < npcs[i].absX) {
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
} else if(playerX > npcs[i].absX) {
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
} else if(playerX == npcs[i].absX || playerY == npcs[i].absY) {
int o = Misc.random(3);
switch(o) {
case 0:
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY+1);
break;
case 1:
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY-1);
break;
case 2:
npcs[i].moveX = GetMove(npcs[i].absX, playerX+1);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
break;
case 3:
npcs[i].moveX = GetMove(npcs[i].absX, playerX-1);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
break;
}
}
int x = (npcs[i].absX + npcs[i].moveX);
int y = (npcs[i].absY + npcs[i].moveY);
npcs[i].facePlayer(playerId);
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;
}
npcs[i].facePlayer(playerId);
npcs[i].updateRequired = true;
}
}
} else {
npcs[i].facePlayer(0);
npcs[i].randomWalk = true;
npcs[i].underAttack = false;
}
}
public boolean checkClipping(int i) {
NPC npc = npcs[i];
int size = npcSize(i);
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
if (!VirtualWorld.I(npc.heightLevel, npc.absX + x, npc.absY + y, npc.absX + npc.moveX, npc.absY + npc.moveY, 0))
return false;
}
}
return true;
}
/**
* load spell
**/
public void loadSpell2(int i) {
npcs[i].attackType = 3;
int random = Misc.random(3);
if (random == 0) {
npcs[i].projectileId = 393; //red
npcs[i].endGfx = 430;
} else if (random == 1) {
npcs[i].projectileId = 394; //green
npcs[i].endGfx = 429;
} else if (random == 2) {
npcs[i].projectileId = 395; //white
npcs[i].endGfx = 431;
} else if (random == 3) {
npcs[i].projectileId = 396; //blue
npcs[i].endGfx = 428;
}
}
public void loadSpell(int i) {
switch(npcs[i].npcType) {
case 2892:
npcs[i].projectileId = 94;
npcs[i].attackType = 2;
npcs[i].endGfx = 95;
break;
case 2894:
npcs[i].projectileId = 298;
npcs[i].attackType = 1;
break;
case 50:
int random = Misc.random(4);
if (random == 0) {
npcs[i].projectileId = 393; //red
npcs[i].endGfx = 430;
npcs[i].attackType = 3;
} else if (random == 1) {
npcs[i].projectileId = 394; //green
npcs[i].endGfx = 429;
npcs[i].attackType = 3;
} else if (random == 2) {
npcs[i].projectileId = 395; //white
npcs[i].endGfx = 431;
npcs[i].attackType = 3;
} else if (random == 3) {
npcs[i].projectileId = 396; //blue
npcs[i].endGfx = 428;
npcs[i].attackType = 3;
} else if (random == 4) {
npcs[i].projectileId = -1; //melee
npcs[i].endGfx = -1;
npcs[i].attackType = 0;
}
break;
//arma npcs
case 2561:
npcs[i].attackType = 0;
break;
case 2560:
npcs[i].attackType = 1;
npcs[i].projectileId = 1190;
break;
case 2559:
npcs[i].attackType = 2;
npcs[i].projectileId = 1203;
break;
case 2558:
random = Misc.random(1);
npcs[i].attackType = 1 + random;
if (npcs[i].attackType == 1) {
npcs[i].projectileId = 1197;
} else {
npcs[i].attackType = 2;
npcs[i].projectileId = 1198;
}
break;
//sara npcs
case 2562: //sara
random = Misc.random(1);
if (random == 0) {
npcs[i].attackType = 2;
npcs[i].endGfx = 1224;
npcs[i].projectileId = -1;
} else if (random == 1)
npcs[i].attackType = 0;
break;
case 2563: //star
npcs[i].attackType = 0;
break;
case 2564: //growler
npcs[i].attackType = 2;
npcs[i].projectileId = 1203;
break;
case 2565: //bree
npcs[i].attackType = 1;
npcs[i].projectileId = 9;
break;
//bandos npcs
case 2550:
random = Misc.random(2);
if (random == 0 || random == 1)
npcs[i].attackType = 0;
else {
npcs[i].attackType = 1;
npcs[i].endGfx = 1211;
npcs[i].projectileId = 288;
}
break;
case 2551:
npcs[i].attackType = 0;
break;
case 2552:
npcs[i].attackType = 2;
npcs[i].projectileId = 1203;
break;
case 2553:
npcs[i].attackType = 1;
npcs[i].projectileId = 1206;
break;
case 2025:
npcs[i].attackType = 2;
int r = Misc.random(3);
if(r == 0) {
npcs[i].gfx100(158);
npcs[i].projectileId = 159;
npcs[i].endGfx = 160;
}
if(r == 1) {
npcs[i].gfx100(161);
npcs[i].projectileId = 162;
npcs[i].endGfx = 163;
}
if(r == 2) {
npcs[i].gfx100(164);
npcs[i].projectileId = 165;
npcs[i].endGfx = 166;
}
if(r == 3) {
npcs[i].gfx100(155);
npcs[i].projectileId = 156;
}
break;
case 2881://supreme
npcs[i].attackType = 1;
npcs[i].projectileId = 298;
break;
case 2882://prime
npcs[i].attackType = 2;
npcs[i].projectileId = 162;
npcs[i].endGfx = 477;
break;
case 2028:
npcs[i].attackType = 1;
npcs[i].projectileId = 27;
break;
case 3200:
int r2 = Misc.random(1);
if (r2 == 0) {
npcs[i].attackType = 1;
npcs[i].gfx100(550);
npcs[i].projectileId = 551;
npcs[i].endGfx = 552;
} else {
npcs[i].attackType = 2;
npcs[i].gfx100(553);
npcs[i].projectileId = 554;
npcs[i].endGfx = 555;
}
break;
case 2745:
int r3 = 0;
if (goodDistance(npcs[i].absX, npcs[i].absY, Server.playerHandler.players[npcs[i].spawnedBy].absX, Server.playerHandler.players[npcs[i].spawnedBy].absY, 1))
r3 = Misc.random(2);
else
r3 = Misc.random(1);
if (r3 == 0) {
npcs[i].attackType = 2;
npcs[i].endGfx = 157;
npcs[i].projectileId = 448;
} else if (r3 == 1) {
npcs[i].attackType = 1;
npcs[i].endGfx = 451;
npcs[i].projectileId = -1;
} else if (r3 == 2) {
npcs[i].attackType = 0;
npcs[i].projectileId = -1;
}
break;
case 2743:
npcs[i].attackType = 2;
npcs[i].projectileId = 445;
npcs[i].endGfx = 446;
break;
case 2631:
npcs[i].attackType = 1;
npcs[i].projectileId = 443;
break;
}
}
/**
* Distanced required to attack
**/
public int distanceRequired(int i) {
switch(npcs[i].npcType) {
case 2025:
case 2028:
return 6;
case 50:
case 2562:
return 2;
case 2881://dag kings
case 2882:
case 3200://chaos ele
case 2743:
case 2631:
case 2745:
return 8;
case 2883://rex
return 1;
case 2552:
case 2553:
case 2556:
case 2557:
case 2558:
case 2559:
case 2560:
case 2564:
case 2565:
return 9;
//things around dags
case 2892:
case 2894:
return 10;
default:
return 1;
}
}
public int followDistance(int i) {
switch (npcs[i].npcType) {
case 2550:
case 2551:
case 2562:
case 2563:
return 8;
case 2883:
return 4;
case 2881:
case 2882:
return 1;
}
return 0;
}
public int getProjectileSpeed(int i) {
switch(npcs[i].npcType) {
case 2881:
case 2882:
case 3200:
return 85;
case 2745:
return 130;
case 50:
return 90;
case 2025:
return 85;
case 2028:
return 80;
default:
return 85;
}
}
/**
*NPC Attacking Player
**/
public void attackPlayer(Client c, int i) {
if(npcs[i] != null) {
if (npcs[i].isDead)
return;
if (!npcs[i].inMulti() && npcs[i].underAttackBy > 0 && npcs[i].underAttackBy != c.playerId) {
npcs[i].killerId = 0;
return;
}
if (!npcs[i].inMulti() && (c.underAttackBy > 0 || (c.underAttackBy2 > 0 && c.underAttackBy2 != i))) {
npcs[i].killerId = 0;
return;
}
if (npcs[i].heightLevel != c.heightLevel) {
npcs[i].killerId = 0;
return;
}
npcs[i].facePlayer(c.playerId);
boolean special = false;//specialCase(c,i);
if(goodDistance(npcs[i].getX(), npcs[i].getY(), c.getX(), c.getY(), distanceRequired(i)) || special) {
if(c.respawnTimer <= 0) {
npcs[i].facePlayer(c.playerId);
npcs[i].attackTimer = getNpcDelay(i);
npcs[i].hitDelayTimer = getHitDelay(i);
npcs[i].attackType = 0;
c.getPA().sound(getNpcListAttackSound(npcs[i].npcType));
if (special)
loadSpell2(i);
else
loadSpell(i);
if (npcs[i].attackType == 3)
npcs[i].hitDelayTimer += 2;
if (multiAttacks(i)) {
multiAttackGfx(i, npcs[i].projectileId);
startAnimation(getAttackEmote(i), i);
c.getPA().sound(Server.npcHandler.getNpcListAttackSound(NPCHandler.npcs[i].npcType));
npcs[i].oldIndex = c.playerId;
return;
}
if(npcs[i].projectileId > 0) {
int nX = Server.npcHandler.npcs[i].getX() + offset(i);
int nY = Server.npcHandler.npcs[i].getY() + offset(i);
int pX = c.getX();
int pY = c.getY();
int offX = (nY - pY)* -1;
int offY = (nX - pX)* -1;
c.getPA().createPlayersProjectile(nX, nY, offX, offY, 50, getProjectileSpeed(i), npcs[i].projectileId, 43, 31, -c.getId() - 1, 65);
}
c.underAttackBy2 = i;
c.singleCombatDelay2 = System.currentTimeMillis();
npcs[i].oldIndex = c.playerId;
startAnimation(getAttackEmote(npcs[i].npcType), i);
c.getPA().sound(Server.npcHandler.getNpcListAttackSound(NPCHandler.npcs[i].npcType));
c.getPA().removeAllWindows();
}
}
}
}
public int offset(int i) {
switch (npcs[i].npcType) {
case 50:
return 2;
case 2881:
case 2882:
return 1;
case 2745:
case 2743:
return 1;
}
return 0;
}
public boolean specialCase(Client c, int i) { //responsible for npcs that much
if (goodDistance(npcs[i].getX(), npcs[i].getY(), c.getX(), c.getY(), 8) && !goodDistance(npcs[i].getX(), npcs[i].getY(), c.getX(), c.getY(), distanceRequired(i)))
return true;
return false;
}
public boolean retaliates(int npcType) {
return npcType < 3777 || npcType > 3780 && !(npcType >= 2440 && npcType <= 2446);
}
public void applyDamage(int i) {
if(npcs[i] != null) {
if(Server.playerHandler.players[npcs[i].oldIndex] == null) {
return;
}
if (npcs[i].isDead)
return;
Client c = (Client) Server.playerHandler.players[npcs[i].oldIndex];
if (multiAttacks(i)) {
multiAttackDamage(i);
return;
}
if (c.playerIndex <= 0 && c.npcIndex <= 0)
if (c.autoRet == 1)
c.npcIndex = i;
if(c.attackTimer <= 3 || c.attackTimer == 0 && c.npcIndex == 0 && c.oldNpcIndex == 0) {
c.startAnimation(c.getCombat().getBlockEmote());
}
if(c.respawnTimer <= 0) {
int damage = 0;
if(npcs[i].attackType == 0) {
damage = Misc.random(npcs[i].maxHit);
if (10 + Misc.random(c.getCombat().calculateMeleeDefence()) > Misc.random(Server.npcHandler.npcs[i].attack)) {
damage = 0;
}
if(c.prayerActive[18]) { // protect from melee
damage = 0;
}
if (c.playerLevel[3] - damage < 0) {
damage = c.playerLevel[3];
}
}
if(npcs[i].attackType == 1) { // range
damage = Misc.random(npcs[i].maxHit);
if (10 + Misc.random(c.getCombat().calculateRangeDefence()) > Misc.random(Server.npcHandler.npcs[i].attack)) {
damage = 0;
}
if(c.prayerActive[17]) { // protect from range
damage = 0;
}
if (c.playerLevel[3] - damage < 0) {
damage = c.playerLevel[3];
}
}
if(npcs[i].attackType == 2) { // magic
damage = Misc.random(npcs[i].maxHit);
boolean magicFailed = false;
if (10 + Misc.random(c.getCombat().mageDef()) > Misc.random(Server.npcHandler.npcs[i].attack)) {
damage = 0;
magicFailed = true;
}
if(c.prayerActive[16]) { // protect from magic
damage = 0;
magicFailed = true;
}
if (c.playerLevel[3] - damage < 0) {
damage = c.playerLevel[3];
}
if(npcs[i].endGfx > 0 && (!magicFailed || isFightCaveNpc(i))) {
c.gfx100(npcs[i].endGfx);
} else {
c.gfx100(85);
}
}
if (npcs[i].attackType == 3) { //fire breath
int anti = c.getPA().antiFire();
if (anti == 0) {
damage = Misc.random(30) + 10;
c.sendMessage("You are badly burnt by the dragon fire!");
} else if (anti == 1)
damage = Misc.random(20);
else if (anti == 2)
damage = Misc.random(5);
if (c.playerLevel[3] - damage < 0)
damage = c.playerLevel[3];
c.gfx100(npcs[i].endGfx);
}
handleSpecialEffects(c, i, damage);
c.logoutDelay = System.currentTimeMillis(); // logout delay
//c.setHitDiff(damage);
c.handleHitMask(damage);
c.playerLevel[3] -= damage;
c.getPA().refreshSkill(3);
c.updateRequired = true;
//c.setHitUpdateRequired(true);
}
}
}
public void handleSpecialEffects(Client c, int i, int damage) {
if (npcs[i].npcType == 2892 || npcs[i].npcType == 2894) {
if (damage > 0) {
if (c != null) {
if (c.playerLevel[5] > 0) {
c.playerLevel[5]--;
c.getPA().refreshSkill(5);
c.getPA().appendPoison(12);
}
}
}
}
}
public static void startAnimation(int animId, int i) {
npcs[i].animNumber = animId;
npcs[i].animUpdateRequired = true;
npcs[i].updateRequired = true;
}
public boolean goodDistance(int objectX, int objectY, int playerX, int playerY, int distance) {
for (int i = 0; i <= distance; i++) {
for (int j = 0; j <= distance; j++) {
if ((objectX + i) == playerX && ((objectY + j) == playerY || (objectY - j) == playerY || objectY == playerY)) {
return true;
} else if ((objectX - i) == playerX && ((objectY + j) == playerY || (objectY - j) == playerY || objectY == playerY)) {
return true;
} else if (objectX == playerX && ((objectY + j) == playerY || (objectY - j) == playerY || objectY == playerY)) {
return true;
}
}
}
return false;
}
public int getMaxHit(int i) {
switch (npcs[i].npcType) {
case 2558:
if (npcs[i].attackType == 2)
return 28;
else
return 68;
case 2562:
return 31;
case 2550:
return 36;
}
return 1;
}
public boolean loadAutoSpawn(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String[] token3 = new String[10];
boolean EndOfFile = false;
int ReadMode = 0;
BufferedReader characterfile = null;
try {
characterfile = new BufferedReader(new FileReader("./"+FileName));
} catch(FileNotFoundException fileex) {
Misc.println(FileName+": file not found.");
return false;
}
try {
line = characterfile.readLine();
} catch(IOException ioexception) {
Misc.println(FileName+": error loading file.");
return false;
}
while(EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token2 = token2.trim();
token2_2 = token2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token3 = token2_2.split("\t");
if (token.equals("spawn")) {
newNPC(Integer.parseInt(token3[0]), Integer.parseInt(token3[1]), Integer.parseInt(token3[2]), Integer.parseInt(token3[3]), Integer.parseInt(token3[4]), getNpcListHP(Integer.parseInt(token3[0])));
}
} else {
if (line.equals("[ENDOFSPAWNLIST]")) {
try { characterfile.close(); } catch(IOException ioexception) { }
return true;
}
}
try {
line = characterfile.readLine();
} catch(IOException ioexception1) { EndOfFile = true; }
}
try { characterfile.close(); } catch(IOException ioexception) { }
return false;
}
public int getNpcListAttackSound(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].attackSound;
}
}
}
return 0;
}
public int getNpcListBlockSound(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].blockSound;
}
}
}
return 0;
}
public int getNpcListDieSound(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
System.out.println("Die Sound: "+NpcList[i].dieSound);
return NpcList[i].dieSound;
}
}
}
return 0;
}
public int getNpcListHP(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].npcHealth;
}
}
}
return 0;
}
public int getNpcListMaxHit(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].maxHit;
}
}
}
return 0;
}
public int getNpcListAttack(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].attack;
}
}
}
return 0;
}
public int getNpcListDefence(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].defence;
}
}
}
return 0;
}
public String getNpcListName(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].npcName.replace("_", " ");
}
}
}
return "nothing";
}
public static int getAttackEmote(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].atkanim;
}
}
}
return 0;
}
public static int getBlockEmote(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].blockanim;
}
}
}
return 0;
}
public static int getDeadEmote(int npcId) {
for (int i = 0; i < maxListedNPCs; i++) {
if (NpcList[i] != null) {
if (NpcList[i].npcId == npcId) {
return NpcList[i].dieanim;
}
}
}
return 0;
}
public void loadDrops(String FileName) {
String line = "";
boolean EndOfFile = false;
int ReadMode = 0;
BufferedReader file = null;
try {
file = new BufferedReader(new FileReader(FileName));
} catch(FileNotFoundException fileex) {
return;
}
try {
line = file.readLine();
} catch(IOException ioexception) {
return;
}
while(EndOfFile == false && line != null) {
line = line.trim();
try {
line = file.readLine();
if(line.equals(".")) {
file.close();
return;
}
String[] split = line.split(" ");
if(!(line.startsWith("//")) || !line.startsWith("."))
drop[Integer.parseInt(split[0])].addDrop(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
} catch(IOException ioexception1) { EndOfFile = true; }
}
try {
file.close();
} catch(IOException ioexception) {
}
}
public boolean loadNPCList(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String[] token3 = new String[10];
boolean EndOfFile = false;
int ReadMode = 0;
BufferedReader characterfile = null;
try {
characterfile = new BufferedReader(new FileReader("./"+FileName));
} catch(FileNotFoundException fileex) {
Misc.println(FileName+": file not found.");
return false;
}
try {
line = characterfile.readLine();
} catch(IOException ioexception) {
Misc.println(FileName+": error loading file.");
return false;
}
while(EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token2 = token2.trim();
token2_2 = token2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token2_2 = token2_2.replaceAll("\t\t", "\t");
token3 = token2_2.split("\t");
if (token.equals("npc")) {
if(token3.length == 4) {
newNPCList(Integer.parseInt(token3[0]), token3[1], Integer.parseInt(token3[2]), Integer.parseInt(token3[3]), 0, 0, 0, 0x326, 404, 2304);
} else {
newNPCList(Integer.parseInt(token3[0]), token3[1], Integer.parseInt(token3[2]), Integer.parseInt(token3[3]), Integer.parseInt(token3[4]), Integer.parseInt(token3[5]), Integer.parseInt(token3[6]), Integer.parseInt(token3[7]), Integer.parseInt(token3[8]), Integer.parseInt(token3[9]));
}
}
} else {
if (line.equals("[ENDOFNPCLIST]")) {
try { characterfile.close(); } catch(IOException ioexception) { }
return true;
}
}
try {
line = characterfile.readLine();
} catch(IOException ioexception1) { EndOfFile = true; }
}
try { characterfile.close(); } catch(IOException ioexception) { }
return false;
}
public boolean loadNPCSounds(String FileName) {
String line = "";
boolean EndOfFile = false;
int ReadMode = 0;
BufferedReader file = null;
try {
file = new BufferedReader(new FileReader("./"+FileName));
} catch(FileNotFoundException fileex) {
return false;
}
try {
line = file.readLine();
} catch(IOException ioexception) {
return false;
}
while(EndOfFile == false && line != null) {
line = line.trim();
try {
line = file.readLine();
if(line.equals(".")) {
file.close();
return true;
}
String[] split = line.split(" ");
if(!line.startsWith("//") && !line.startsWith(".")) {
newNPCSound(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
}
} catch(IOException ioexception1) { EndOfFile = true; }
}
try {
file.close();
} catch(IOException ioexception) {
}
return false;
}
}