diff --git a/core/src/com/riiablo/attributes/Attributes.java b/core/src/com/riiablo/attributes/Attributes.java index 0245479e..06f9d4c1 100644 --- a/core/src/com/riiablo/attributes/Attributes.java +++ b/core/src/com/riiablo/attributes/Attributes.java @@ -224,13 +224,23 @@ public final class Attributes implements Iterable { return agg.containsAny(stat); } + /** + * NOTE: This method returns a reused StatRef tuple which should not be + * saved. Consecutive calls to this method will change the state of the + * tuple, so only use this if you want to retrieve the value as a temp + * cache. If you want to retrieve multiple stats, + * {@link #get(short, StatRef)} should be used instead. + */ public StatRef get(final short stat) { return agg.get(stat); } - public StatRef getCopy(final short stat) { - final StatRef ref = agg.get(stat); - return ref != null ? ref.copy() : null; + /** + * @see #get(short) + */ + public StatRef get(final short stat, final StatRef dst) { + assert dst != null : "dst is null when it is asserted that you should have created one to reuse!"; + return agg.get(stat, dst); } public StatRef set(final short stat, final short srcStat) { diff --git a/core/src/com/riiablo/attributes/StatListRef.java b/core/src/com/riiablo/attributes/StatListRef.java index d3fe81ff..5fb0f26d 100644 --- a/core/src/com/riiablo/attributes/StatListRef.java +++ b/core/src/com/riiablo/attributes/StatListRef.java @@ -90,6 +90,12 @@ public final class StatListRef implements Iterable { return tuple.update(index); } + public StatRef get(final short stat, final StatRef dst) { + final int index = indexOf(stat); + if (index < 0) return null; + return dst.update(stats, list, index); + } + StatRef first(final short stat) { final int index = stats.firstIndexOf(list, stat); if (index < 0) return null; diff --git a/core/src/com/riiablo/attributes/StatRef.java b/core/src/com/riiablo/attributes/StatRef.java index d3d00df9..5f6831ea 100644 --- a/core/src/com/riiablo/attributes/StatRef.java +++ b/core/src/com/riiablo/attributes/StatRef.java @@ -3,6 +3,10 @@ package com.riiablo.attributes; import com.riiablo.codec.excel.ItemStatCost; public final class StatRef { + public static StatRef obtain() { + return new StatRef(); + } + StatList stats; int list; int index;