/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.gamecontent;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.datasets.LesserBindedValue;
import transientlibs.bindedobjects.core.LinkedValue;
import transientlibs.objects.creatures.Person;
import transientlibs.objects.creatures.PersonalityTrait;
import transientlibs.tex.StringAnalyst;
/**
*
* @author kibertoad
*/
public class Npc extends LesserBindedValue {
public static ArrayList<Npc> Npcs = new ArrayList<Npc>();
public Person person = new Person();
public static Npc lastNpc;
public static void loadNpc (){
if (StringAnalyst.isFileExist("npcs.dat")) {
StringAnalyst reader = new StringAnalyst();
reader.openFile("npcs.dat");
while (!reader.eof) {
reader.readRow();
analyzeStringForNpcs (reader);
}
reader.closeFile();
}
}
public static void analyzeStringForNpcs (StringAnalyst analyst) {
analyzeStringForNpcs ("-NO-", analyst);
}
public static void analyzeStringForNpcs (String getString, StringAnalyst analyst) {
if (!"-NO-".equals(getString)) {analyst.fullStr = getString;}
analyst.getNextString();
String nowStr = analyst.lastStr;
boolean withResult = false;
if (nowStr.equals("npc")) {
Npcs.add (new Npc ());
lastNpc = Npcs.get(Npcs.size()-1);
lastNpc.ID = analyst.getBinding (Binding.npcBinding);
//ReqList.lastReqList = lastNpc.trainReqs;
withResult = true;
}
if (nowStr.equals("name")) {
lastNpc.LName.value = analyst.getNextString();
withResult = true;
}
if (nowStr.equals("desc")) {
lastNpc.desc = analyst.restOfRow();
withResult = true;
}
if (nowStr.equals("trait")) {
LinkedValue<PersonalityTraits> trait = lastNpc.person.personality.get(analyst.readBinding(Binding.personalityTraitBinding));
trait.valueReference.value = analyst.getNextNumber();
withResult = true;
}
if (nowStr.equals("interest")) {
LinkedValue<Domain> trait = lastNpc.person.interests.get(analyst.readBinding(Binding.domainBinding));
trait.valueReference.value = analyst.getNextNumber();
withResult = true;
}
if ((withResult == false) && (nowStr.length()>2) && (!nowStr.startsWith("//"))) {
Log.error("Unknown string: "+nowStr); }
}
public static LesserBindedValue getByID (int setID) {
return Npcs.get(setID);
};
public static LesserBindedValue getByCode (String setCode) {
return getByID (Binding.getBinding(Binding.npcBinding, setCode));
};
}