From 294bb1ea6102f61f5b85cbd641b7cb857abe7362 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 2 Sep 2020 00:47:54 -0700 Subject: [PATCH] Moved stat entry query methods to Stat --- core/src/com/riiablo/attributes/Stat.java | 11 +++++ core/src/com/riiablo/attributes/StatList.java | 45 +++++++++---------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/core/src/com/riiablo/attributes/Stat.java b/core/src/com/riiablo/attributes/Stat.java index 1cc8e1c5..9f29febe 100644 --- a/core/src/com/riiablo/attributes/Stat.java +++ b/core/src/com/riiablo/attributes/Stat.java @@ -1,5 +1,8 @@ package com.riiablo.attributes; +import com.riiablo.Riiablo; +import com.riiablo.codec.excel.ItemStatCost; + @SuppressWarnings("unused") public class Stat { public static final short strength = 0; @@ -384,5 +387,13 @@ public class Stat { return ENCODED_COUNT[stat]; } + static ItemStatCost.Entry entry(short stat) { + return Riiablo.files.ItemStatCost.get(stat); + } + + static boolean hasParams(short stat) { + return false; // TODO: determine if stat requires params + } + private Stat() {} } diff --git a/core/src/com/riiablo/attributes/StatList.java b/core/src/com/riiablo/attributes/StatList.java index ad36a657..e3481919 100644 --- a/core/src/com/riiablo/attributes/StatList.java +++ b/core/src/com/riiablo/attributes/StatList.java @@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.math.NumberUtils; -import com.riiablo.Riiablo; import com.riiablo.codec.excel.ItemStatCost; import com.riiablo.logger.LogManager; import com.riiablo.logger.Logger; @@ -211,7 +210,7 @@ public final class StatList { assertMutable(); log.traceEntry("add(index: {}, value: {})", index, value); final short stat = ids[index]; - assert !hasParams(stat) : "stat(" + stat + ") requires params"; + assert !Stat.hasParams(stat) : "stat(" + stat + ") requires params"; assert encoding(stat) <= 2 : "#add() unsupported for encoding(" + encoding(stat) + ")"; if (log.debugEnabled()) log.debug( "add(stat: {} ({}), this: {}, src: {})", @@ -230,7 +229,7 @@ public final class StatList { public int add(int list, short stat, StatList src, int srcList) { assertMutable(); log.traceEntry("add(list: {}, stat: {}, src: {}, srcList: {})", list, stat, src, srcList); - assert !hasParams(stat) : "stat(" + stat + ") requires params"; + assert !Stat.hasParams(stat) : "stat(" + stat + ") requires params"; assert encoding(stat) <= 2 : "#add() unsupported for encoding(" + encoding(stat) + ")"; final int index = indexOf(list, stat, 0); final int otherIndex = src.indexOf(srcList, stat, 0); @@ -270,7 +269,7 @@ public final class StatList { if (true) throw new UnsupportedOperationException(); assertMutable(); log.traceEntry("sub(list: {}, stat: {}, src: {}, srcList: {})", list, stat, src, srcList); - assert !hasParams(stat) : "stat(" + stat + ") requires params"; + assert !Stat.hasParams(stat) : "stat(" + stat + ") requires params"; assert encoding(stat) <= 2 : "#sub() unsupported for encoding(" + encoding(stat) + ")"; final int index = indexOf(list, stat, 0); final int otherIndex = src.indexOf(srcList, stat, 0); @@ -319,18 +318,18 @@ public final class StatList { } public int put(int list, short stat, int value) { - assert !hasParams(stat) : "stat(" + stat + ") requires params"; + assert !Stat.hasParams(stat) : "stat(" + stat + ") requires params"; return put(list, stat, 0, value); } public int put(int list, short stat, long value) { - assert !hasParams(stat) : "stat(" + stat + ") requires params"; + assert !Stat.hasParams(stat) : "stat(" + stat + ") requires params"; assert value <= UINT_MAX_VALUE : "value(" + value + ") > " + UINT_MAX_VALUE; return put(list, stat, 0, _asInt(value)); } public int put(int list, short stat, float value) { - assert !hasParams(stat) : "stat(" + stat + ") requires params"; + assert !Stat.hasParams(stat) : "stat(" + stat + ") requires params"; assert entry(stat).ValShift == 8 : "entry.ValShift(" + entry(stat).ValShift + ") != " + 8; return put(list, stat, 0, _asInt(value)); } @@ -357,7 +356,7 @@ public final class StatList { } public int indexOf(int list, short stat) { - assert !hasParams(stat) : "stat(" + stat + ") requires params"; + assert !Stat.hasParams(stat) : "stat(" + stat + ") requires params"; return indexOf(list, stat, 0); } @@ -388,7 +387,7 @@ public final class StatList { } long asLong(int index) { - assert entry(ids[index]).Send_Bits >= Integer.SIZE : "entry.Send_Bits(" + entry(ids[index]).Send_Bits + ") < " + Integer.SIZE; + assert entry(index).Send_Bits >= Integer.SIZE : "entry.Send_Bits(" + entry(index).Send_Bits + ") < " + Integer.SIZE; return _asLong(values[index]); } @@ -401,7 +400,7 @@ public final class StatList { } float asFixed(int index) { - assert entry(ids[index]).ValShift == 8 : "entry.ValShift(" + entry(ids[index]).ValShift + ") != " + 8; + assert entry(index).ValShift == 8 : "entry.ValShift(" + entry(index).ValShift + ") != " + 8; return _asFixed(values[index]); } @@ -427,6 +426,14 @@ public final class StatList { return ids[index]; } + ItemStatCost.Entry entry(int index) { + return entry(ids[index]); + } + + ItemStatCost.Entry entry(short stat) { + return Stat.entry(stat); + } + public int encoding(int index) { return flags[index] & ENCODING_MASK; } @@ -564,11 +571,11 @@ public final class StatList { final byte flags = this.flags[index]; switch (flags & ENCODING_MASK) { default: // fall-through - case 0: return entry(ids[index]) + "(" + ids[index] + ")=" + ((flags & FLAG_PARAMS) == 0 ? asString(index) : (asString(index) + ":" + params[index])); - case 1: return entry(ids[index]) + "(" + ids[index] + ")=" + param1(index) + ":" + value1(index); - case 2: return entry(ids[index]) + "(" + ids[index] + ")=" + param1(index) + ":" + param2(index) + ":" + value1(index); - case 3: return entry(ids[index]) + "(" + ids[index] + ")=" + param1(index) + ":" + param2(index) + ":" + value1(index) + ":" + value2(index); - case 4: return entry(ids[index]) + "(" + ids[index] + ")=" + value1(index) + ":" + value2(index) + ":" + value3(index); + case 0: return entry(index) + "(" + ids[index] + ")=" + ((flags & FLAG_PARAMS) == 0 ? asString(index) : (asString(index) + ":" + params[index])); + case 1: return entry(index) + "(" + ids[index] + ")=" + param1(index) + ":" + value1(index); + case 2: return entry(index) + "(" + ids[index] + ")=" + param1(index) + ":" + param2(index) + ":" + value1(index); + case 3: return entry(index) + "(" + ids[index] + ")=" + param1(index) + ":" + param2(index) + ":" + value1(index) + ":" + value2(index); + case 4: return entry(index) + "(" + ids[index] + ")=" + value1(index) + ":" + value2(index) + ":" + value3(index); } } @@ -597,14 +604,6 @@ public final class StatList { .build(); } - private static ItemStatCost.Entry entry(short stat) { - return Riiablo.files.ItemStatCost.get(stat); - } - - private static boolean hasParams(short stat) { - return false; // TODO: determine if stat requires params - } - public IndexIterator indexIterator(int list) { return INDEX_ITERATOR == null ? INDEX_ITERATOR = new IndexIterator().reset(list)