/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.gamecontent;
import java.io.File;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.datasets.LesserBindedValue;
import static transientlibs.bindedobjects.gamecontent.CombatEffect.lastCombatEffect;
import transientlibs.processors.combat.CombatStats;
import transientlibs.processors.misc.Detonator;
import transientlibs.tex.ActList;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;
/**
*
* @author kibertoad
*/
public class CombatEffect extends LesserBindedValue {
public CombatStats stats = new CombatStats();
public ReqList reqsToActivate = new ReqList();
public static ReqList globalReqs = new ReqList();
public static ReqList globalActivationReq = new ReqList();
public static ActList globalActs = new ActList();
public static ArrayList<String> globalTags = new ArrayList<String>();
public static String globalGroup = "-";
public static ArrayList<CombatEffect> combatEffects = new ArrayList<CombatEffect>();
public static CombatEffect lastCombatEffect;
public static void loadAllCombatEffects() {
File dir = new File(Detonator.INSTANCE.currentModule.dirName + "combat");
String[] fileList = dir.list();
if (fileList == null) {
Log.warn(Detonator.INSTANCE.currentModule.dirName + "combat");
Log.warn("Specified directory does not exist!");
} else {
for (int x = 0; x < fileList.length; x++) {
if (fileList[x].endsWith(".dat")) {
Log.info(fileList[x]);
//loadMap("maps/" + fileList[x]);
globalActs.clear();
globalActivationReq.clear();
globalTags.clear();
globalReqs.clear();
globalGroup = "-";
loadCombatEffect("combat/" + fileList[x]);
}
}
}
}
public static void loadCombatEffect(String fromFile) {
if (StringAnalyst.isFileExist(fromFile)) {
StringAnalyst reader = new StringAnalyst();
reader.openFile(fromFile);
while (!reader.eof) {
reader.readRow();
analyzeStringForCombatEffects(reader);
}
reader.closeFile();
}
}
public static void analyzeStringForCombatEffects(StringAnalyst analyst) {
analyzeStringForCombatEffects("-NO-", analyst);
}
public static void continousAnalysisForCombatEffect(StringAnalyst analyst) {
// texBlockActive = true;
do {
analyst.readRow();
analyzeStringForCombatEffects(analyst);
} while ((!analyst.eof) && (!"endtex".equals(analyst.lastStr)));
}
public static void analyzeStringForCombatEffects(String getString, StringAnalyst analyst) {
if (!"-NO-".equals(getString)) {
analyst.fullStr = getString;
}
analyst.getNextString();
String nowStr = analyst.lastStr;
boolean withResult = false;
String token;
if (nowStr.equals("combateffect")) {
combatEffects.add(new CombatEffect());
lastCombatEffect = combatEffects.get(combatEffects.size() - 1);
lastCombatEffect.ID = analyst.getBinding(Binding.combatEffectBinding);
//ReqList.lastReqList = lastCombatEffect.trainReqs;
withResult = true;
}
if (nowStr.equals("name")) {
lastCombatEffect.LName.value = analyst.getNextString();
withResult = true;
}
if (nowStr.equals("damage")) {
token = analyst.getNextString();
if (token.equals("dices")) {
lastCombatEffect.stats.damageDices.value = analyst.getNextNumber();
}
if (token.equals("sides")) {
lastCombatEffect.stats.damageSides.value = analyst.getNextNumber();
}
if (token.equals("modifier")) {
lastCombatEffect.stats.damageBonus.value = analyst.getNextNumber();
}
withResult = true;
}
if (nowStr.equals("accuracy")) {
token = analyst.getNextString();
if (token.equals("dices")) {
lastCombatEffect.stats.hitDices.value = analyst.getNextNumber();
}
if (token.equals("sides")) {
lastCombatEffect.stats.hitSides.value = analyst.getNextNumber();
}
if (token.equals("modifier")) {
lastCombatEffect.stats.hitBonus.value = analyst.getNextNumber();
}
withResult = true;
}
if (nowStr.equals("evasion")) {
}
if (nowStr.equals("range")) {
}
if (nowStr.equals("speed")) {
}
if (nowStr.equals("desc")) {
lastCombatEffect.desc = analyst.restOfRow();
withResult = true;
}
if ((withResult == false) && (nowStr.length() > 2) && (!nowStr.startsWith("//"))) {
Log.error("Unknown string: " + nowStr);
}
}
@Override
public String name() {
return LName.value;
}
}