Greatly improved logging of property lists and attributes for items

This commit is contained in:
Collin Smith 2020-08-19 22:00:02 -07:00
parent 0c883a9bc8
commit 6c5269c61e
4 changed files with 44 additions and 12 deletions

View File

@ -118,6 +118,23 @@ public class Item {
static final int SET_6_PROPS_FLAG = 1 << SET_PROPS + 4;
static final int RUNE_PROPS_FLAG = 1 << RUNE_PROPS;
static String getPropListString(int i) {
switch (i) {
case MAGIC_PROPS: return "MAGIC_PROPS";
case SET_PROPS:
case SET_PROPS + 1:
case SET_PROPS + 2:
case SET_PROPS + 3:
case SET_PROPS + 4:
return "SET_PROPS (" + (i + 1) + " items)";
case RUNE_PROPS:
return "RUNE_PROPS";
default:
assert false : "i(" + i + ") is not a valid prop list id!";
return String.valueOf(i);
}
}
static final int GEMPROPS_WEAPON = 0;
static final int GEMPROPS_ARMOR = 1;
static final int GEMPROPS_SHIELD = 2;

View File

@ -127,7 +127,12 @@ public class ItemReader {
PropertyList[] props = item.stats = new PropertyList[Item.NUM_PROPS];
for (int i = 0; i < Item.NUM_PROPS; i++) {
if (((listFlags >> i) & 1) == 1) {
props[i] = PropertyList.obtain().read(bits);
try {
Log.put("propList", Item.getPropListString(i));
props[i] = PropertyList.obtain().read(bits);
} finally {
Log.remove("propList");
}
}
}
}

View File

@ -2,8 +2,8 @@ package com.riiablo.item;
import java.util.Comparator;
import java.util.Iterator;
import org.apache.logging.log4j.Logger;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
@ -13,9 +13,11 @@ import com.riiablo.codec.excel.ItemStatCost;
import com.riiablo.codec.excel.Properties;
import com.riiablo.io.BitInput;
import com.riiablo.io.BitOutput;
import com.riiablo.log.Log;
import com.riiablo.log.LogManager;
public class PropertyList implements Iterable<Stat> {
private static final String TAG = "PropertyList";
private static final Logger log = LogManager.getLogger(PropertyList.class);
private static final int[] ATTRIBUTES = {Stat.strength, Stat.energy, Stat.dexterity, Stat.vitality};
private static final int[] RESISTS = {Stat.fireresist, Stat.lightresist, Stat.coldresist, Stat.poisonresist};
@ -80,9 +82,15 @@ public class PropertyList implements Iterable<Stat> {
}
public PropertyList read(BitInput bitStream) {
for (int prop; (prop = bitStream.read15u(Stat.BITS)) != Stat.NONE;) {
for (int j = prop, size = j + Stat.getNumEncoded(prop); j < size; j++) {
read(j, bitStream);
for (int prop; (prop = bitStream.read15u(Stat.BITS)) != Stat.NONE; ) {
final int numEncoded = Stat.getNumEncoded(prop);
try {
if (numEncoded > 1) Log.put("numEncoded", numEncoded);
for (int j = prop, size = j + numEncoded; j < size; j++) {
read(j, bitStream);
}
} finally {
Log.remove("numEncoded");
}
}
@ -347,7 +355,7 @@ public class PropertyList implements Iterable<Stat> {
props.put(inst.hash, inst);
return value;
case 18: // */time // TODO: Add support
Gdx.app.error(TAG, "Unsupported property function: " + prop.func[i]);
log.error("Unsupported property function: {}", prop.func[i]);
return Integer.MIN_VALUE;
case 19: // charged (skill)
value = Stat.encodeValue(3, min[i], min[i]); // charges
@ -390,7 +398,7 @@ public class PropertyList implements Iterable<Stat> {
case 4:
case 9:
default:
Gdx.app.error(TAG, "Unsupported property function: " + prop.func[i]);
log.error("Unsupported property function: {}", prop.func[i]);
return Integer.MIN_VALUE;
}
}

View File

@ -2,8 +2,7 @@ package com.riiablo.item;
import com.google.common.primitives.UnsignedInts;
import java.util.Arrays;
import com.badlogic.gdx.Gdx;
import org.apache.logging.log4j.Logger;
import com.riiablo.CharacterClass;
import com.riiablo.Riiablo;
@ -13,11 +12,12 @@ import com.riiablo.codec.excel.SkillDesc;
import com.riiablo.codec.excel.Skills;
import com.riiablo.io.BitInput;
import com.riiablo.io.BitOutput;
import com.riiablo.log.LogManager;
import com.riiablo.save.CharData;
@SuppressWarnings("unused")
public class Stat implements Comparable<Stat> {
private static final String TAG = "Stat";
private static final Logger log = LogManager.getLogger(Stat.class);
public static final int strength = 0;
public static final int energy = 1;
@ -492,6 +492,7 @@ public class Stat implements Comparable<Stat> {
val = bitStream.read31u(entry.Save_Bits) - entry.Save_Add;
hash = hash(stat, param);
modified = false;
log.trace("{}: {} {}", entry, val, param); // TODO: improve
return this;
}
@ -502,6 +503,7 @@ public class Stat implements Comparable<Stat> {
entry = Riiablo.files.ItemStatCost.get(stat);
hash = Stat.hash(stat, param);
modified = false;
log.trace("{}: {} {}", entry, val, param); // TODO: improve
return this;
}
@ -576,7 +578,7 @@ public class Stat implements Comparable<Stat> {
switch (entry.Encode) {
case 3:
case 4:
Gdx.app.error(TAG, "add unsupported when Encoding = " + entry.Encode);
log.error("add unsupported when Encoding = {}", entry.Encode);
break;
case 0:
case 1: