mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-04 15:27:30 +07:00
Added int flags parameter to AttributesUpdater to specify which lists to include
Added int flags parameter to AttributesUpdater to specify which lists to include AttributesUpdater checks and logs if flags includes more than 1 set (unusual) Renamed set item constants and methods within SetListFlags to be more consistent Added Aldur's Advance StatListLabeler test Added runes to Grief StatListLabeler test
This commit is contained in:
@ -9,21 +9,30 @@ import com.riiablo.logger.MDC;
|
||||
public class AttributesUpdater {
|
||||
private static final Logger log = LogManager.getLogger(AttributesUpdater.class);
|
||||
|
||||
public Attributes update(Attributes attrs, Attributes opAttrs) {
|
||||
log.traceEntry("update(attrs: {}, opAttrs: {})", attrs, opAttrs);
|
||||
return update(attrs, opAttrs, null);
|
||||
public Attributes update(Attributes attrs, int listFlags, Attributes opAttrs) {
|
||||
log.tracefEntry("update(attrs: %s, listFlags: 0x%x, opAttrs: %s)", attrs, listFlags, opAttrs);
|
||||
return update(attrs, listFlags, opAttrs, null);
|
||||
}
|
||||
|
||||
public Attributes update(Attributes attrs, Attributes opAttrs, CharStats.Entry charStats) {
|
||||
log.traceEntry("update(attrs: {}, opAttrs: {}, charStats: {})", attrs, opAttrs, charStats);
|
||||
public Attributes update(Attributes attrs, int listFlags, Attributes opAttrs, CharStats.Entry charStats) {
|
||||
log.tracefEntry("update(attrs: %s, listFlags: 0x%x, opAttrs: %s, charStats: %s)", attrs, listFlags, opAttrs, charStats);
|
||||
if (!(attrs instanceof AggregateAttributes)) return attrs; // no-op
|
||||
if (!(attrs instanceof GemAttributes)) {
|
||||
final int setItemListCount = StatListFlags.countSetItemFlags(listFlags);
|
||||
if (setItemListCount > 1) {
|
||||
log.warnf("listFlags(0x%x) contains more than 1 set list", listFlags);
|
||||
}
|
||||
}
|
||||
|
||||
final StatList list = attrs.list();
|
||||
if (list.isEmpty()) return attrs;
|
||||
final StatListGetter base = attrs.base();
|
||||
final StatListBuilder agg = attrs.aggregate().builder();
|
||||
final StatListBuilder rem = attrs.remaining().builder();
|
||||
for (StatListGetter stats : list.listIterator()) {
|
||||
update(opAttrs, charStats, stats, base, agg, rem);
|
||||
for (int i = 0, s = list.numLists(); i < s; i++) {
|
||||
if (((listFlags >> i) & 1) == 1) {
|
||||
update(opAttrs, charStats, list.get(i), base, agg, rem);
|
||||
}
|
||||
}
|
||||
|
||||
return attrs;
|
||||
@ -89,6 +98,7 @@ public class AttributesUpdater {
|
||||
final short statId = Stat.index(op_stat);
|
||||
final StatGetter opStat = agg.get(statId);
|
||||
if (opStat != null) {
|
||||
log.trace("Aggregating stat({})", stat.debugString());
|
||||
final int opValue = op(charStats, agg, stat, opStat, op, op_base, op_param);
|
||||
opStat.add(opValue);
|
||||
ops++;
|
||||
@ -117,12 +127,14 @@ public class AttributesUpdater {
|
||||
case 7: return 0; // by-time percent
|
||||
case 8:
|
||||
if (charStats == null) return 0;
|
||||
log.trace("Aggregating stat({})", stat.debugString());
|
||||
agg.add(stat);
|
||||
//mod.set(stat.id);
|
||||
return stat.value() * charStats.ManaPerMagic; // max mana
|
||||
case 9:
|
||||
if (charStats == null) return 0;
|
||||
if (opStat.id() == Stat.maxhp) { // only increment vit on maxhp op
|
||||
log.trace("Aggregating stat({})", stat.debugString());
|
||||
agg.add(stat);
|
||||
//mod.set(stat.id);
|
||||
}
|
||||
|
@ -13,13 +13,15 @@ public class StatListFlags {
|
||||
|
||||
static final int FLAG_NONE = 0;
|
||||
static final int FLAG_MAGIC = 1 << ITEM_MAGIC_LIST;
|
||||
static final int FLAG_SET_2 = 1 << ITEM_SET_LIST + 0;
|
||||
static final int FLAG_SET_3 = 1 << ITEM_SET_LIST + 1;
|
||||
static final int FLAG_SET_4 = 1 << ITEM_SET_LIST + 2;
|
||||
static final int FLAG_SET_5 = 1 << ITEM_SET_LIST + 3;
|
||||
static final int FLAG_SET_6 = 1 << ITEM_SET_LIST + 4;
|
||||
static final int FLAG_SET_2 = 1 << (ITEM_SET_LIST + 0);
|
||||
static final int FLAG_SET_3 = 1 << (ITEM_SET_LIST + 1);
|
||||
static final int FLAG_SET_4 = 1 << (ITEM_SET_LIST + 2);
|
||||
static final int FLAG_SET_5 = 1 << (ITEM_SET_LIST + 3);
|
||||
static final int FLAG_SET_6 = 1 << (ITEM_SET_LIST + 4);
|
||||
static final int FLAG_RUNE = 1 << ITEM_RUNE_LIST;
|
||||
|
||||
static final int ITEM_SET_MASK = FLAG_SET_2 | FLAG_SET_3 | FLAG_SET_4 | FLAG_SET_5 | FLAG_SET_6;
|
||||
|
||||
static String itemToString(int i) {
|
||||
switch (i) {
|
||||
case ITEM_MAGIC_LIST:
|
||||
@ -38,7 +40,24 @@ public class StatListFlags {
|
||||
}
|
||||
}
|
||||
|
||||
static int getItemSetFlags(int numItems) {
|
||||
static int countSetItemFlags(int flags) {
|
||||
return Integer.bitCount(flags & ITEM_SET_MASK);
|
||||
}
|
||||
|
||||
static int getSetItemEquippedFlag(int numItems) {
|
||||
if (numItems < 0 || numItems > 6) {
|
||||
log.warn("numItems({}) not within [0..6]", numItems);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (numItems < 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1 << (ITEM_SET_LIST + (numItems - 2));
|
||||
}
|
||||
|
||||
static int getSetItemFlags(int numItems) {
|
||||
int flags = FLAG_NONE;
|
||||
switch (numItems) {
|
||||
case 6: flags |= FLAG_SET_6; // fall-through
|
||||
|
@ -21,9 +21,12 @@ import com.riiablo.mpq.MPQFileHandleResolver;
|
||||
import static com.riiablo.attributes.StatListFlags.FLAG_MAGIC;
|
||||
import static com.riiablo.attributes.StatListFlags.FLAG_RUNE;
|
||||
import static com.riiablo.attributes.StatListFlags.GEM_SHIELD_LIST;
|
||||
import static com.riiablo.attributes.StatListFlags.GEM_WEAPON_LIST;
|
||||
import static com.riiablo.attributes.StatListFlags.ITEM_MAGIC_LIST;
|
||||
import static com.riiablo.attributes.StatListFlags.ITEM_RUNE_LIST;
|
||||
import static com.riiablo.attributes.StatListFlags.NUM_ITEM_LISTS;
|
||||
import static com.riiablo.attributes.StatListFlags.getSetItemEquippedFlag;
|
||||
import static com.riiablo.attributes.StatListFlags.getSetItemFlags;
|
||||
|
||||
public class StatListLabelerTest {
|
||||
@BeforeClass
|
||||
@ -83,10 +86,18 @@ public class StatListLabelerTest {
|
||||
Attributes stats = genItemAttrs(Gdx.files.internal("test/Grief.d2i").readBytes(), 197, 0x12, FLAG_RUNE).reset();
|
||||
|
||||
AttributesUpdater updater = new AttributesUpdater();
|
||||
updater.update(stats, attrs);
|
||||
updater.update(stats, FLAG_RUNE, attrs);
|
||||
|
||||
StatListLabeler labeler = newInstance();
|
||||
System.out.println(labeler.createLabel(stats.remaining(), attrs));
|
||||
System.out.println("----------");
|
||||
|
||||
updater.add(stats, genGemAttrs("r05").list(GEM_WEAPON_LIST), attrs);
|
||||
updater.add(stats, genGemAttrs("r03").list(GEM_WEAPON_LIST), attrs);
|
||||
updater.add(stats, genGemAttrs("r28").list(GEM_WEAPON_LIST), attrs);
|
||||
updater.add(stats, genGemAttrs("r23").list(GEM_WEAPON_LIST), attrs);
|
||||
updater.add(stats, genGemAttrs("r08").list(GEM_WEAPON_LIST), attrs);
|
||||
System.out.println(labeler.createLabel(stats.remaining(), attrs));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -95,7 +106,7 @@ public class StatListLabelerTest {
|
||||
Attributes stats = genItemAttrs(Gdx.files.internal("test/Annihilus.d2i").readBytes(), 172, -1, FLAG_MAGIC).reset();
|
||||
|
||||
AttributesUpdater updater = new AttributesUpdater();
|
||||
updater.update(stats, attrs);
|
||||
updater.update(stats, FLAG_MAGIC, attrs);
|
||||
|
||||
StatListLabeler labeler = newInstance();
|
||||
System.out.println(labeler.createLabel(stats.remaining(), attrs));
|
||||
@ -107,7 +118,19 @@ public class StatListLabelerTest {
|
||||
Attributes stats = genItemAttrs(Gdx.files.internal("test/Hunter's Bow of Blight.d2i").readBytes(), 196, -1, FLAG_MAGIC).reset();
|
||||
|
||||
AttributesUpdater updater = new AttributesUpdater();
|
||||
updater.update(stats, attrs);
|
||||
updater.update(stats, FLAG_MAGIC, attrs);
|
||||
|
||||
StatListLabeler labeler = newInstance();
|
||||
System.out.println(labeler.createLabel(stats.remaining(), attrs));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Tirant_Aldurs_Advance() {
|
||||
Attributes attrs = genCharacterAttrs(Gdx.files.internal("test/Tirant.d2s").readBytes(), 0x2fd, 0x33).reset();
|
||||
Attributes stats = genItemAttrs(Gdx.files.internal("test/Aldur's Advance.d2i").readBytes(), 202, -1, FLAG_MAGIC | getSetItemFlags(4)).reset();
|
||||
|
||||
AttributesUpdater updater = new AttributesUpdater();
|
||||
updater.update(stats, FLAG_MAGIC | getSetItemEquippedFlag(2), attrs);
|
||||
|
||||
StatListLabeler labeler = newInstance();
|
||||
System.out.println(labeler.createLabel(stats.remaining(), attrs));
|
||||
@ -119,7 +142,7 @@ public class StatListLabelerTest {
|
||||
Attributes stats = genItemAttrs(Gdx.files.internal("test/Spirit.d2i").readBytes(), 216, 0x19, FLAG_MAGIC | FLAG_RUNE).reset();
|
||||
|
||||
AttributesUpdater updater = new AttributesUpdater();
|
||||
updater.update(stats, attrs);
|
||||
updater.update(stats, FLAG_MAGIC | FLAG_RUNE, attrs);
|
||||
|
||||
StatListLabeler labeler = newInstance();
|
||||
System.out.println("----------");
|
||||
|
@ -27,7 +27,7 @@ import static com.riiablo.attributes.StatListFlags.FLAG_MAGIC;
|
||||
import static com.riiablo.attributes.StatListFlags.FLAG_NONE;
|
||||
import static com.riiablo.attributes.StatListFlags.FLAG_RUNE;
|
||||
import static com.riiablo.attributes.StatListFlags.NUM_ITEM_LISTS;
|
||||
import static com.riiablo.attributes.StatListFlags.getItemSetFlags;
|
||||
import static com.riiablo.attributes.StatListFlags.getSetItemFlags;
|
||||
|
||||
public class StatListWriterTest {
|
||||
@BeforeClass
|
||||
@ -129,7 +129,7 @@ public class StatListWriterTest {
|
||||
|
||||
@Test
|
||||
public void Aldurs_Advance() {
|
||||
testItem(Gdx.files.internal("test/Aldur's Advance.d2i").readBytes(), 202, -1, FLAG_MAGIC | getItemSetFlags(4));
|
||||
testItem(Gdx.files.internal("test/Aldur's Advance.d2i").readBytes(), 202, -1, FLAG_MAGIC | getSetItemFlags(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user