Preview:
Code:
<list>
<NPCDefinitions>
<id>0</id>
<size>1</size>
<name>Hans</name>
<description>Servant of the Duke of Lumbridge.</description>
<combatLevel>0</combatLevel>
<interactions>
<string>TALK-TO</string>
</interactions>
</NPCDefinitions>
<NPCDefinitions>
<id>1</id>
<size>1</size>
<name>Man</name>
<description>One of RuneScape's many citizens.</description>
<combatLevel>2</combatLevel>
<interactions>
<string>TALK-TO</string>
<string>ATTACK</string>
<string>PICKPOCKET</string>
</interactions>
</NPCDefinitions>
UPDATED*:
There is now 6,390 NPC Definitions (474 npcs)
created a loader, edited Graham's
Code:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.logging.Logger;
/**
* @author warsaw
*/
public class NPCDefinitions {
/**
* The XML file
*/
private static String FILE = "./data/npcDefinitions.xml";
/**
* logger
*/
private static final Logger logger = Logger.getLogger(NPCDefinitions.class.getName());
/**
* The definitions
*/
private static NPCDefinitions[] definitions = null;
/**
* Loads NPC Definitions
*
* @throws FileNotFoundException The file isn't there / missing
*/
@SuppressWarnings("unchecked")
public static void main(String args[]) throws FileNotFoundException {
logger.info("Loading NPC Definitions...");
List<NPCDefinitions> list = (List<NPCDefinitions>) xStreamManager.load(new FileInputStream(FILE));
definitions = new NPCDefinitions[list.size() + 1];
for (NPCDefinitions def : list) {
definitions[def.getId()] = def;
}
logger.info("Loaded " + list.size() + " npc definitions.");
}
/**
* The Id
*/
private int id;
/**
* The size
*/
private int size;
/**
* The name
*/
private String name;
/**
* The description
*/
private String description;
/**
* The combat level
*/
private int combatLevel;
/**
* The interactions.
*/
private String[] interactions;
/**
* The constructor
*/
public NPCDefinitions() {
}
/**
* Gets npc by Id
*
* @param id The NPC Id
* @return npcDefinition The npc definition
*/
public static NPCDefinitions forId(int id) {
NPCDefinitions definition = definitions[id];
if (definition == null) {
definition = createDefinition(id);
}
return definition;
}
/**
* Creates a definition by Id
*
* @param id The id
* @return def The NPC Definition
*/
public static NPCDefinitions createDefinition(int id) {
NPCDefinitions def = new NPCDefinitions();
def.id = id;
return def;
}
@Override
public String toString() {
return NPCDefinitions.class.getName() + "[id=" + id + " name=" + name + " description=" + description + " combat=" + combatLevel + "]";
}
/**
* Gets the id
*
* @return id The id
*/
public int getId() {
return id;
}
/**
* Gets the size
*
* @return size The size
*/
public int getSize() {
return size;
}
/**
* Gets the name
*
* @return name The NPC name
*/
public String getName() {
return name;
}
/**
* Gets the combat level
*
* @return combatLevel The combat level
*/
public int getCombatLevel() {
return combatLevel;
}
/**
* Gets the description
*
* @return description The description
*/
public String getDescription() {
return description;
}
/**
* Gets the interaction menu
*
* @return interactions The interactions
*/
public String[] getInteractions() {
return interactions;
}
}
NOTE
Getting interactions menu:
Example:
Code:
<interactions>
<string>TALK-TO</string>
<string>ATTACK</string>
<string>PICKPOCKET</string>
</interactions>
Code:
System.out.println(NPCDefinitions.forId(NPC_ID).getInteractions[0]);
Would print out
0 = the first option
1 = the second option
etc
File: Here