Added support for getting a stat from Attributes into a provided tuple

This commit is contained in:
Collin Smith
2020-09-10 16:58:44 -07:00
parent 8acfe5bc1f
commit d77a109be2
3 changed files with 23 additions and 3 deletions

View File

@ -224,13 +224,23 @@ public final class Attributes implements Iterable<StatRef> {
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) {

View File

@ -90,6 +90,12 @@ public final class StatListRef implements Iterable<StatRef> {
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;

View File

@ -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;