diff options
| -rw-r--r-- | src/main/java/tlIItools/Affix.java | 53 | ||||
| -rw-r--r-- | src/main/java/tlIItools/AffixGroup.java | 88 | ||||
| -rw-r--r-- | src/main/java/tlIItools/AffixLister.java | 45 | ||||
| -rw-r--r-- | src/main/java/tlIItools/AffixSet.java | 7 | ||||
| -rw-r--r-- | src/main/java/tlIItools/EffectGroup.java | 6 |
5 files changed, 145 insertions, 54 deletions
diff --git a/src/main/java/tlIItools/Affix.java b/src/main/java/tlIItools/Affix.java index 62766b8c..f8d0c84a 100644 --- a/src/main/java/tlIItools/Affix.java +++ b/src/main/java/tlIItools/Affix.java @@ -67,13 +67,13 @@ public class Affix { /** The types of equipment this can spawn on. */ public List<String> equipTypes; - /** The types of equipment this can't spawn on. */ + /** The types of equipment this can spawn on. */ public List<String> nonequipTypes; - /** Places to get this enchantment from; */ + /** The types of equipment this can spawn on. */ public List<String> enchantSources; - /** The socketable types this spawns on. */ + /** The types of equipment this can spawn on. */ public List<String> socketableTypes; /** The effects attached to this affix. */ @@ -131,30 +131,29 @@ public class Affix { } return true; } - - /** Gets the name of 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 name of the affix group */ - public String getAffixGroupName() { - StringBuilder sb = new StringBuilder(); - - for (Effect eft : effects) sb.append(eft.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(); + + /** 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 */ + public AffixGroup toAffixGroup() { + AffixGroup group = new AffixGroup(); + + 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 @@ -181,7 +180,7 @@ public class Affix { /** Add an equip type to the right set of equip types. * - * @param type The equip type to add. */ + * @param equipType The equip type to add. */ public void addEquipType(String equipType) { if (inNonEquip) { nonequipTypes.add(equipType); diff --git a/src/main/java/tlIItools/AffixGroup.java b/src/main/java/tlIItools/AffixGroup.java index 7ae57453..4069c632 100644 --- a/src/main/java/tlIItools/AffixGroup.java +++ b/src/main/java/tlIItools/AffixGroup.java @@ -1,5 +1,9 @@ package tlIItools; +import java.util.*; + +import tlIItools.Affix.*; + /** * Represents a 'group' of related affixes. * @@ -8,4 +12,88 @@ package tlIItools; * * @author Ben Culkin */ public class AffixGroup { + public List<EffectGroup> effects; + /** The types of equipment this can spawn on. */ + public List<String> enchantSources; + /** The types of equipment this can spawn on. */ + public List<String> equipTypes; + /** The types of equipment this can spawn on. */ + public List<String> nonequipTypes; + /** The types of equipment this can spawn on. */ + public List<String> socketableTypes; + + /** The type of thing this affix applies to. */ + public AffixType type = AffixType.ITEM; + + /** Create a new affix group. */ + public AffixGroup() { + effects = new ArrayList<>(); + enchantSources = new ArrayList<>(); + equipTypes = new ArrayList<>(); + nonequipTypes = new ArrayList<>(); + socketableTypes = new ArrayList<>(); + } + + /** Determine whether this affix group contains a particular affix. + * + * 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). + * + * @param afx The affix to check if it is in the affix group with. + * + * @return Whether or the specified affix is in this affix group. */ + public boolean contains(Affix afx) { + 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(); + } + + @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); + + return sb.toString(); + } + + @Override + public int hashCode() { + return Objects.hash(effects, enchantSources, equipTypes, nonequipTypes, + socketableTypes, type); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AffixGroup other = (AffixGroup) obj; + return Objects.equals(effects, other.effects) + && Objects.equals(enchantSources, other.enchantSources) + && Objects.equals(equipTypes, other.equipTypes) + && Objects.equals(nonequipTypes, other.nonequipTypes) + && Objects.equals(socketableTypes, other.socketableTypes) + && type == other.type; + } } diff --git a/src/main/java/tlIItools/AffixLister.java b/src/main/java/tlIItools/AffixLister.java index 3d5519d3..27b21508 100644 --- a/src/main/java/tlIItools/AffixLister.java +++ b/src/main/java/tlIItools/AffixLister.java @@ -49,9 +49,7 @@ public class AffixLister { * @return The listed affix set. */ @SuppressWarnings("unused") public static AffixSet listAffixes(String[] args) { - AffixSet affixSetByName = new AffixSet(); - - boolean doingArgs = true; + boolean doingArgs = true; boolean omitZeros = false; boolean listZeros = false; @@ -66,8 +64,8 @@ public class AffixLister { boolean outputAffixGroups = false; OutputStream affixGroupDest = null; - Map<String, Set<Affix>> groupContents = affixSetByName.affixGroups; - Set<Affix> nonGroupContents = affixSetByName.ungroupedAffixes; + Map<String, Set<Affix>> groupContents = new HashMap<>(); + Set<Affix> nonGroupContents = new HashSet<>(); NameFileReader nfr = new NameFileReader(false); nfr.groupRx = ".*/mods/([^/]+)/*"; @@ -298,24 +296,23 @@ public class AffixLister { errOut.println(); if (outputAffixGroups) { - for (Entry<String, Set<Affix>> ent : - affixSetByContents.affixGroups .entrySet()) { - - String groupName = ent.getKey(); - Set<Affix> affixes = ent.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 - } - } + for (Entry<AffixGroup, Set<Affix>> entry + : affixSetByContents.affixGroups.entrySet()) { + AffixGroup groupName = entry.getKey(); + Set<Affix> 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 + } + } } long endTime = System.nanoTime(); @@ -330,6 +327,6 @@ public class AffixLister { "\tOptions: Name Mode: %s, Special-case zero weight: %s, Noting zero-weight in special case: %s\n", nameMode, !listZeros, !omitZeros); - return affixSetByName; + return affixSetByContents; } } diff --git a/src/main/java/tlIItools/AffixSet.java b/src/main/java/tlIItools/AffixSet.java index d6b950f6..91c0dcd9 100644 --- a/src/main/java/tlIItools/AffixSet.java +++ b/src/main/java/tlIItools/AffixSet.java @@ -18,7 +18,7 @@ public class AffixSet { * * An affix group is a set of affixes that generally have the same or * similar effects, but have different intensities or spawn levels. */ - public Map<String, Set<Affix>> affixGroups; + public Map<AffixGroup, Set<Affix>> affixGroups; /** All of the ungrouped affixes contained in this set. */ public Set<Affix> ungroupedAffixes; @@ -34,12 +34,13 @@ public class AffixSet { * * @param afx The affix to add. */ public void addAffixByContents(Affix afx) { - String afxGroup = afx.getAffixGroupName(); + AffixGroup group = afx.toAffixGroup(); + String afxGroup = group.toString(); if (afxGroup.equals("")) { ungroupedAffixes.add(afx); } else { - affixGroups.compute(afxGroup, (key, val) -> { + affixGroups.compute(group, (key, val) -> { if (val == null) { Set<Affix> afxSet = new HashSet<>(); afxSet.add(afx); diff --git a/src/main/java/tlIItools/EffectGroup.java b/src/main/java/tlIItools/EffectGroup.java index 29e51d25..7938e0dd 100644 --- a/src/main/java/tlIItools/EffectGroup.java +++ b/src/main/java/tlIItools/EffectGroup.java @@ -2,6 +2,12 @@ package tlIItools; import java.util.*; +/** An 'effect group'. + * + * This groups similar effects together, the same way affix groups group affixs + * together. + * + * @author Ben Culkin */ public class EffectGroup { /** The name of the effect. */ public String name; |
