package com.rs.utils;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import com.rs.game.World;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.npc.NPC;
import com.rs.game.player.content.custom.RightsManager;
public class NPCSpawning {
private static final Map<Integer, Class<?>> CUSTOM_NPCS = new HashMap<Integer, Class<?>>();
public static void npcSpawn() {
int size = 0;
boolean ignore = false;
try {
for (String string : FileUtilities.readFile("data/npcs/npcspawns.txt")) {
if (string.startsWith("//") || string.equals("")) {
continue;
}
if (string.contains("/*")) {
ignore = true;
continue;
}
if (ignore) {
if (string.contains("*/")) {
ignore = false;
}
continue;
}
String[] spawn = string.split(" ");
@SuppressWarnings("unused")
int id = Integer.parseInt(spawn[0]), x = Integer
.parseInt(spawn[1]), y = Integer.parseInt(spawn[2]), z = Integer
.parseInt(spawn[3]), faceDir = Integer
.parseInt(spawn[4]);
NPC npc = null;
Class<?> npcHandler = CUSTOM_NPCS.get(id);
if (npcHandler == null) {
npc = new NPC(id, new WorldTile(x, y, z), -1, true, false);
} else {
npc = (NPC) npcHandler.getConstructor(int.class).newInstance(i d);
}
if (npc != null) {
WorldTile spawnLoc = new WorldTile(x, y, z);
npc.setLocation(spawnLoc);
World.spawnNPC(npc.getId(), spawnLoc, -1, true, false);
size++;
}
}
} catch (NumberFormatException e1) {
e1.printStackTrace();
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (SecurityException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
} catch (NoSuchMethodException e1) {
e1.printStackTrace();
}
System.err.println("Loaded " + size + " custom npc spawns!");
}
}