From fedb385feef3fb3e3419f4fc3c7d234fe8d5caec Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Thu, 31 Dec 2020 21:04:27 -0400 Subject: Work on affix groups more --- .gitignore | 1 + src/main/java/tlIItools/Affix.java | 114 ++++++++++++++++++++----------- src/main/java/tlIItools/AffixGroup.java | 75 +++++++++++++------- src/main/java/tlIItools/AffixLister.java | 43 +++++++----- src/main/java/tlIItools/AffixSet.java | 9 ++- src/main/java/tlIItools/EffectGroup.java | 16 ++++- src/main/java/tlIItools/LevelRange.java | 90 ++++++++++++++++++++++++ 7 files changed, 260 insertions(+), 88 deletions(-) create mode 100644 src/main/java/tlIItools/LevelRange.java diff --git a/.gitignore b/.gitignore index 2f3f6474..2a4c8b5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.class bin/ output/ +old-output/ tags synfiles basefiles diff --git a/src/main/java/tlIItools/Affix.java b/src/main/java/tlIItools/Affix.java index f8d0c84a..443e5095 100644 --- a/src/main/java/tlIItools/Affix.java +++ b/src/main/java/tlIItools/Affix.java @@ -49,12 +49,8 @@ public class Affix { * suffix. */ public String affixPrefix; - /* The min/max levels the affix can spawn at. */ - - /** The minimum level of an item this affix can spawn on. */ - public int minLevel; - /** The maximum level of an item this affix can spawn on. */ - public int maxLevel; + /** The min/max levels the affix can spawn at. */ + public LevelRange spawnRange = new LevelRange(); /** The spawn weight for the affix. */ public int weight; @@ -67,13 +63,11 @@ public class Affix { /** The types of equipment this can spawn on. */ public List equipTypes; - /** The types of equipment this can spawn on. */ + /** The types of equipment this can spawn on. */ public List nonequipTypes; - - /** The types of equipment this can spawn on. */ + /** The types of equipment this can spawn on. */ public List enchantSources; - - /** The types of equipment this can spawn on. */ + /** The types of equipment this can spawn on. */ public List socketableTypes; /** The effects attached to this affix. */ @@ -133,27 +127,29 @@ public class Affix { } /** Gets the 'affix group' that this affix is in. - * - * By 'affix group', what we mean is that it is essentially the same affix, with - * generally just differing levels/values. - * - * For instance, an affix that granted +2 strength, and one that granted +4 - * strength would be considered to be in the same affix group (assuming that - * both of those strength bonuses had the same effect name, and applied to the - * same sorts of items). - * - * @return The affix group */ + * + * By 'affix group', what we mean is that it is essentially the same affix, with + * generally just differing levels/values. + * + * For instance, an affix that granted +2 strength, and one that granted +4 + * strength would be considered to be in the same affix group (assuming that + * both of those strength bonuses had the same effect name, and applied to the + * same sorts of items). + * + * @return The affix group */ public AffixGroup toAffixGroup() { AffixGroup group = new AffixGroup(); - group.enchantSources = enchantSources; - group.equipTypes = equipTypes; - group.nonequipTypes = nonequipTypes; + group.enchantSources = enchantSources; + group.equipTypes = equipTypes; + group.nonequipTypes = nonequipTypes; group.socketableTypes = socketableTypes; + for (Effect eff : effects) group.effects.add(eff.group); return group; } + /* Are invalid equip types being added? * * NOTE: This is kinda bad practice. It should really be handled via two @@ -204,6 +200,56 @@ public class Affix { return intName; } + /** Print out a 'short-form' of this affix. + * + * @return The short form of this affix. */ + public String toShortString() { + StringBuilder sb = new StringBuilder(); + + sb.append(intName); + sb.append("\n"); + + if (affixSuffix != null) { + sb.append("\tSuffix: "); + sb.append(affixSuffix); + sb.append("\n"); + } + + if (affixPrefix != null) { + sb.append("\tPrefix: "); + sb.append(affixPrefix); + sb.append("\n"); + + } + + sb.append("\t"); + sb.append(spawnRange.toString()); + sb.append("\n"); + + sb.append("\tSpawn Weight: "); + sb.append(weight); + sb.append("\n"); + + if (slots == 0) { + sb.append("\tOccupies no slots\n"); + } else { + sb.append("\tSlots: "); + sb.append(slots); + sb.append("\n"); + } + + if (effects.size() != 0) { + sb.append("\tEffects: "); + for (Effect eft : effects) { + sb.append("\n\t\t"); + sb.append(eft.toString()); + } + sb.append("\n"); + } + + return sb.toString(); + } + /** Print out the full details of this affix. * * @return The full details of the affix. */ @@ -241,21 +287,7 @@ public class Affix { } sb.append("\t"); - if (minLevel <= 1 && maxLevel == 999) { - sb.append("No Level Range"); - } else if (minLevel != 1 && maxLevel != 999) { - sb.append("Level Range: "); - sb.append(minLevel); - sb.append("-"); - sb.append(maxLevel); - } else if (minLevel <= 1) { - sb.append("Max Level: "); - sb.append(maxLevel); - } else if (maxLevel == 999) { - sb.append("Minimum Level: "); - sb.append(minLevel); - } - + sb.append(spawnRange); sb.append("\n"); sb.append("\tSpawn Weight: "); @@ -377,9 +409,9 @@ public class Affix { errors.add(msg); } } else if (ln.contains("MIN_SPAWN_RANGE")) { - afx.minLevel = Integer.parseInt(splits[1]); + afx.spawnRange.minLevel = Integer.parseInt(splits[1]); } else if (ln.contains("MAX_SPAWN_RANGE")) { - afx.maxLevel = Integer.parseInt(splits[1]); + afx.spawnRange.maxLevel = Integer.parseInt(splits[1]); } else if (ln.contains("WEIGHT:")) { afx.weight = Integer.parseInt(splits[1]); } else if (ln.contains("SLOTS_OCCUPY")) { diff --git a/src/main/java/tlIItools/AffixGroup.java b/src/main/java/tlIItools/AffixGroup.java index 4069c632..61aab596 100644 --- a/src/main/java/tlIItools/AffixGroup.java +++ b/src/main/java/tlIItools/AffixGroup.java @@ -11,15 +11,15 @@ import tlIItools.Affix.*; * or have effects of differing intensity. * * @author Ben Culkin */ -public class AffixGroup { +public class AffixGroup implements Comparable { public List effects; - /** The types of equipment this can spawn on. */ + /** The types of enchanters who can add this. */ public List enchantSources; /** The types of equipment this can spawn on. */ public List equipTypes; - /** The types of equipment this can spawn on. */ + /** The types of equipment this cannot spawn on. */ public List nonequipTypes; - /** The types of equipment this can spawn on. */ + /** The types of equipment this can be socketed into on. */ public List socketableTypes; /** The type of thing this affix applies to. */ @@ -27,10 +27,10 @@ public class AffixGroup { /** Create a new affix group. */ public AffixGroup() { - effects = new ArrayList<>(); - enchantSources = new ArrayList<>(); - equipTypes = new ArrayList<>(); - nonequipTypes = new ArrayList<>(); + effects = new ArrayList<>(); + enchantSources = new ArrayList<>(); + equipTypes = new ArrayList<>(); + nonequipTypes = new ArrayList<>(); socketableTypes = new ArrayList<>(); } @@ -50,26 +50,53 @@ public class AffixGroup { return afx.toAffixGroup().equals(this); } - /** Get the 'header' for displaying this group - * - * @return The header for this group. */ - public String groupHeader() { - StringBuilder sb = new StringBuilder(); - - sb.append("ID: " + hashCode()); - - return sb.toString(); - } - + public String groupSummary() { + StringBuilder sb = new StringBuilder(); + + sb.append("Affix Type: "); + sb.append(type); + sb.append("\n"); +/* sb.append("Effects: \n"); + for (EffectGroup group : effects) { + sb.append("\t"); + sb.append(group); + sb.append("\n"); + } +*/ + + sb.append("Affix can spawn on: "); + sb.append(String.join(", ", equipTypes)); + sb.append("\nAffix can't spawn on: "); + sb.append(String.join(", ", nonequipTypes)); + sb.append("\n"); + + if (type == AffixType.SOCKETABLE) { + sb.append("Affix can be socketed into: "); + sb.append(String.join(", ", socketableTypes)); + sb.append("\n"); + } else if (type == AffixType.ENCHANTMENT) { + sb.append("Affix can be enchanted by: "); + sb.append(String.join(", ", socketableTypes)); + sb.append("\n"); + } + + return sb.toString(); + } + + @Override + public int compareTo(AffixGroup other) { + return toString().compareTo(other.toString()); + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); - for (EffectGroup group : effects) sb.append(group); - for (String enchantSource : enchantSources) sb.append(enchantSource); - for (String equipType : equipTypes) sb.append(equipType); - for (String nonEquipType : nonequipTypes) sb.append(nonEquipType); - for (String socketableType : socketableTypes) sb.append(socketableType); + for (EffectGroup group: effects) sb.append(group); + for (String enchantSource: enchantSources) sb.append(enchantSource); + for (String equipType: equipTypes) sb.append(equipType); + for (String nonEquipType: nonequipTypes) sb.append(nonEquipType); + for (String socketableType: socketableTypes) sb.append(socketableType); return sb.toString(); } diff --git a/src/main/java/tlIItools/AffixLister.java b/src/main/java/tlIItools/AffixLister.java index 27b21508..ddb7da8a 100644 --- a/src/main/java/tlIItools/AffixLister.java +++ b/src/main/java/tlIItools/AffixLister.java @@ -24,6 +24,8 @@ public class AffixLister { public static PrintStream normOut = System.out; /** The error output to use. */ public static PrintStream errOut = System.err; + /** The output to write affix groups to. */ + public static PrintStream affixGroupDest = null; /** Indicates how to treat affixes with regards to their names. */ public static enum NameMode { @@ -62,7 +64,6 @@ public class AffixLister { int groupCount = 0; boolean outputAffixGroups = false; - OutputStream affixGroupDest = null; Map> groupContents = new HashMap<>(); Set nonGroupContents = new HashSet<>(); @@ -297,22 +298,30 @@ public class AffixLister { if (outputAffixGroups) { for (Entry> entry - : affixSetByContents.affixGroups.entrySet()) { - AffixGroup groupName = entry.getKey(); - Set affixes = entry.getValue(); - - boolean isFirstAfx = true; - for (Affix afx : affixes) { - // @TODO actually implement this -bculkin, 12/29/2020 - - // Print the header for this group - if (isFirstAfx) { - isFirstAfx = false; - } - - // print this affix in the group format - } - } + : affixSetByContents.affixGroups.entrySet()) + { + AffixGroup group = entry.getKey(); + Set affixes = entry.getValue(); + + // Skip one-affix groups + if (affixes.size() == 1) continue; + + boolean isFirstAfx = true; + for (Affix afx : affixes) { + // @TODO actually implement this -bculkin, 12/29/2020 + + // Print the header for this group + if (isFirstAfx) { + isFirstAfx = false; + affixGroupDest.printf("Group ID %s (%d affixes)\n", + group.hashCode(), affixes.size()); + affixGroupDest.println(group.groupSummary()); + } + + affixGroupDest.println(afx.toShortString()); + // print this affix in the group format + } + } } long endTime = System.nanoTime(); diff --git a/src/main/java/tlIItools/AffixSet.java b/src/main/java/tlIItools/AffixSet.java index 91c0dcd9..fa5c8d19 100644 --- a/src/main/java/tlIItools/AffixSet.java +++ b/src/main/java/tlIItools/AffixSet.java @@ -9,8 +9,7 @@ public class AffixSet { private static class AffixComparator implements Comparator { @Override public int compare(Affix a1, Affix a2) { - if (a1.minLevel == a2.minLevel) return a1.maxLevel - a2.maxLevel; - else return a1.minLevel - a2.minLevel; + return a1.spawnRange.compareTo(a2.spawnRange); } } @@ -29,14 +28,14 @@ public class AffixSet { ungroupedAffixes = new TreeSet<>(new AffixComparator()); } - + /** Add an affix to this set. * * @param afx The affix to add. */ public void addAffixByContents(Affix afx) { AffixGroup group = afx.toAffixGroup(); - String afxGroup = group.toString(); - + String afxGroup = group.toString(); + if (afxGroup.equals("")) { ungroupedAffixes.add(afx); } else { diff --git a/src/main/java/tlIItools/EffectGroup.java b/src/main/java/tlIItools/EffectGroup.java index 7938e0dd..78e0324a 100644 --- a/src/main/java/tlIItools/EffectGroup.java +++ b/src/main/java/tlIItools/EffectGroup.java @@ -32,6 +32,20 @@ public class EffectGroup { /** Whether or not this effect is a 'transfer' effect (Applied to the enemy on a hit). */ public boolean isTransfer; + public String summary() { + StringBuilder sb = new StringBuilder(); + + // @TODO Ben Culkin 12/31/2020 :FancyEffectSummary + // + // EffectGroups should probably use something from EffectRepo to better + // output the summary for a particular group type + String fmt = "%s (name %s, damageType %s, hasDuration %s, stat %s, isBonus %s, ownerLevel %s, useGraph %s, graphOverride %s, exclusive %s, isTransfer %s)"; + + sb.append(String.format(fmt, type, name, damageType, hasDuration, statName, isStatBonus, ownerLevel, useGraph, graphOverride, exclusive, isTransfer)); + + return sb.toString(); + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -77,4 +91,4 @@ public class EffectGroup { && ownerLevel == other.ownerLevel && useGraph == other.useGraph; } -} \ No newline at end of file +} diff --git a/src/main/java/tlIItools/LevelRange.java b/src/main/java/tlIItools/LevelRange.java new file mode 100644 index 00000000..f899df12 --- /dev/null +++ b/src/main/java/tlIItools/LevelRange.java @@ -0,0 +1,90 @@ +package tlIItools; + +public class LevelRange implements Comparable { + /* + * if (minLevel <= 1 && maxLevel == 999) { + * sb.append("No Level Range"); + * } else if (minLevel != 1 && maxLevel != 999) { + * sb.append("Level Range: "); + * sb.append(minLevel); + * sb.append("-"); + * sb.append(maxLevel); + * } else if (minLevel <= 1) { + * sb.append("Max Level: "); + * sb.append(maxLevel); + * } else if (maxLevel == 999) { + * sb.append("Minimum Level: "); + * sb.append(minLevel); + * } */ + + public int minLevel; + public int maxLevel; + + public LevelRange() { + minLevel = 1; + maxLevel = 999; + } + + public LevelRange(int minLevel, int maxLevel) { + this.minLevel = minLevel; + this.maxLevel = maxLevel; + } + + private void clamp() { + minLevel = Math.max(1, minLevel); + maxLevel = Math.max(999, maxLevel); + } + + public boolean isUnrestricted() { + return minLevel <= 1 && maxLevel >= 999; + } + + public boolean noLowerBound() { + return minLevel <= 1; + } + + public boolean noUpperBound() { + return maxLevel >= 999; + } + + @Override + public String toString() { + clamp(); + + StringBuilder sb = new StringBuilder(); + + if (minLevel <= 1 && maxLevel >= 999) { + sb.append("No Level Range"); + } else if (minLevel > 1 && maxLevel < 999) { + sb.append("Level Range: "); + sb.append(minLevel); + sb.append("-"); + sb.append(maxLevel); + } else if (minLevel <= 1) { + sb.append("Max Level: "); + sb.append(maxLevel); + } else if (maxLevel >= 999) { + sb.append("Minimum Level: "); + sb.append(minLevel); + } + + return sb.toString(); + } + + @Override + public int compareTo(LevelRange other) { + if (this.equals(other)) return 0; + + // Unrestricted ranges sort above all others + if (isUnrestricted()) return 1; + + if (noLowerBound()) { + return maxLevel - other.maxLevel; + } else if (noUpperBound()) { + return minLevel - other.minLevel; + } else { + if (minLevel == other.minLevel) return maxLevel - other.maxLevel; + else return minLevel - other.minLevel; + } + } +} -- cgit v1.2.3