From 2f81b826524599859ce4c8bf6164bab83debf662 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Thu, 2 Jul 2020 16:01:39 -0400 Subject: Implement affix grouping by contents Implements a basic way to 'group' affixes together. An affix group is a collection of affixes which generally provide the same benefits, but at varying levels. For example, '+2 strength' and '+4 strength' would be considered grouped affixes, assuming that they were spawning on the same items and such --- src/main/java/tlIItools/AffixSet.java | 41 +++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/main/java/tlIItools/AffixSet.java') diff --git a/src/main/java/tlIItools/AffixSet.java b/src/main/java/tlIItools/AffixSet.java index 8f59d7b4..569649ec 100644 --- a/src/main/java/tlIItools/AffixSet.java +++ b/src/main/java/tlIItools/AffixSet.java @@ -1,9 +1,9 @@ package tlIItools; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; +import java.util.HashSet; import java.util.Map; +import java.util.Set; /** * Container of a set of affixes. * @@ -13,15 +13,15 @@ public class AffixSet { /** * All of the affix groups contained in this set. * - * An affix group is a set of affixs that generally have the same or - * similiar effects, but have different intensities or spawn levels. + * 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> affixGroups; + public Map> affixGroups; /** * All of the ungrouped affixes contained in this set. */ - public List ungroupedAffixes; + public Set ungroupedAffixes; /** * Create a new blank affix set. @@ -29,6 +29,33 @@ public class AffixSet { public AffixSet() { affixGroups = new HashMap<>(); - ungroupedAffixes = new ArrayList<>(); + ungroupedAffixes = new HashSet<>(); + } + + /** + * Add an affix to this set. + * + * @param afx The affix to add. + */ + public void addAffixByContents(Affix afx) { + String afxGroup = afx.getAffixGroupName(); + + if (afxGroup.equals("")) { + ungroupedAffixes.add(afx); + } else { + affixGroups.compute(afxGroup, (key, val) -> { + if (val == null) { + Set afxSet = new HashSet<>(); + + afxSet.add(afx); + + return afxSet; + } else { + val.add(afx); + + return val; + } + }); + } } } -- cgit v1.2.3