From 8c613819790ae737150a9ad8bb82332a1aaab690 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Thu, 17 Jan 2019 18:33:14 -0400 Subject: Refactor AffixLister AffixLister got refactored some more, in preparation for adding the ability to load things that aren't affixes. --- src/main/java/tlIItools/Effect.java | 129 ++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'src/main/java/tlIItools/Effect.java') diff --git a/src/main/java/tlIItools/Effect.java b/src/main/java/tlIItools/Effect.java index 1c0af9af..3efec6de 100644 --- a/src/main/java/tlIItools/Effect.java +++ b/src/main/java/tlIItools/Effect.java @@ -16,6 +16,15 @@ import java.util.Scanner; * @author Ben Culkin */ public class Effect { + /** + * Count of all loaded effects. + */ + public static int effectCount = 0; + /** + * Do timing analysis when loading effects. + */ + public static boolean doTiming; + /** * The list of detail strings for skills. */ @@ -361,4 +370,124 @@ public class Effect { return sb.toString(); } + + public static Effect parseEffect(Affix afx, Scanner scn, String scnSource) { + return parseEffect(afx, scn, scnSource, new ArrayList<>()); + } + + public static Effect parseEffect(Affix afx, Scanner scn, String scnSource, List errs) { + Effect efct = new Effect(); + + long startTime = System.nanoTime(); + + efct.fName = scnSource; + + while (scn.hasNextLine()) { + String ln = scn.nextLine(); + ln = ln.replaceAll("\\p{Cntrl}", ""); + + if (ln.contains("[/EFFECT]")) break; + + String[] splits = ln.split(":"); + + // Empty field + if (splits.length == 1) continue; + + if (ln.contains("NAME")) { + efct.name = splits[1]; + } else if (ln.contains("DAMAGE_TYPE")) { + efct.damageType = splits[1]; + } else if (ln.contains("TYPE")) { + efct.type = splits[1]; + } else if (ln.contains("ACTIVATION")) { + switch (splits[1]) { + case "DYNAMIC": + case "PASSIVE": + // Passive is the default, and + // dynamic doesn't have much + // actual difference. + break; + case "TRANSFER": + efct.isTransfer = true; + break; + default: + errs.add(String.format("Malformed activation type: (%s) (%s) (%s)\n", splits[1], efct.name, afx.intName)); + } + } else if (ln.contains("DURATION")) { + if (splits[1].equals("ALWAYS")) { + efct.hasDuration = false; + + efct.duration = Double.POSITIVE_INFINITY; + } else if (splits[1].equals("INSTANT")) { + efct.hasDuration = false; + + efct.duration = Double.NaN; + } else if (splits[1].equals("PERCENT")) { + efct.hasDuration = false; + + efct.duration = Double.NaN; + + errs.add(String.format("WARN: Punting on DURATION:PERCENT for %s\n", scnSource)); + } else if (splits[1].equals("0")) { + efct.hasDuration = false; + efct.duration = 0.0; + } else { + efct.hasDuration = true; + + efct.duration = Double.parseDouble(splits[1]); + } + } else if (ln.contains("MIN:")) { + efct.minValue = Double.parseDouble(splits[1]); + } else if (ln.contains("MAX:")) { + efct.maxValue = Double.parseDouble(splits[1]); + } else if (ln.contains("USEOWNERLEVEL")) { + // We don't care about this, for now + } else if (ln.contains("LEVEL:")) { + efct.level = Integer.parseInt(splits[1]); + } else if (ln.contains("EXCLUSIVE")) { + efct.exclusive = Boolean.parseBoolean(splits[1]); + } else if (ln.contains("GRAPHOVERRIDE")) { + efct.graphOverride = splits[1]; + } else if (ln.contains("USEOWNERLEVEL")) { + efct.ownerLevel = Boolean.parseBoolean(splits[1]); + } else if (ln.contains("NOGRAPH")) { + efct.useGraph = Boolean.parseBoolean(splits[1]); + } else if (ln.contains("STATNAME")) { + efct.statName = splits[1]; + } else if (ln.contains("STATPERCENT")) { + efct.statPercent = Double.parseDouble(splits[1]); + } else if (ln.contains("STATMODIFIERISBONUS")) { + efct.isStatBonus = Boolean.parseBoolean(splits[1]); + } else if (ln.contains("RESISTANCE:")) { + efct.resist = Double.parseDouble(splits[1]); + } else if (ln.contains("FORCE:")) { + efct.resist = Double.parseDouble(splits[1]); + } else if (ln.contains("MIN_PER")) { + efct.minPer = Double.parseDouble(splits[1]); + } else if (ln.contains("MAX_PER")) { + efct.maxPer = Double.parseDouble(splits[1]); + } else if (ln.contains("RANGE:") || ln.contains("RADIUS")) { + efct.range = Double.parseDouble(splits[1]); + } else if (ln.contains("MAX_COUNT:") || ln.contains("MAX_TARGETS")) { + efct.maxCount = Double.parseDouble(splits[1]); + } else if (ln.contains("PULSE_RATE")) { + efct.pulse = Double.parseDouble(splits[1]); + } else if (ln.contains("CHANCE:")) { + // NOTE: Should really use its own field + efct.resist = Double.parseDouble(splits[1]); + } + } + + long endTime = System.nanoTime(); + if (doTiming) { + String fmt = "\t\tProcessed effect %s from %s in %d nanoseconds (%.2f seconds)\n"; + + double seconds = ((double)((endTime - startTime) / 1000000000)); + errs.add(String.format(fmt, efct.name, scnSource, endTime - startTime, seconds)); + } + + effectCount += 1; + + return efct; + } } -- cgit v1.2.3