Added type marker to Attributes

Added byte type value to represent what kind of attrs it is
Rolled GemAttributes into AggregateAttributes
GemAttributes are now marked using added marker
`Complex` attribute lists have types > 0
StatListWrapper set to type 0
This commit is contained in:
Collin Smith
2020-09-06 00:42:20 -07:00
parent 1dabb6f6b8
commit 9ed7b82c08
5 changed files with 59 additions and 29 deletions

View File

@ -10,6 +10,10 @@ public class AggregateAttributes extends Attributes {
final StatList agg = StatList.obtain(1);
final StatList rem = StatList.obtain(1);
AggregateAttributes(byte type) {
super(type);
}
@Override
public StatListGetter base() {
if (!base.contains(0)) base.newList(0);

View File

@ -4,37 +4,60 @@ import android.support.annotation.CallSuper;
import java.util.Iterator;
public abstract class Attributes implements Iterable<StatGetter> {
/**
* an arithmetic association of StatList
*
* item property lists will be frozen after creation
* base stats should be mutable for players, monsters
*
* descriptions
*/
public static AggregateAttributes aggregateAttributes() {
return new AggregateAttributes();
return new AggregateAttributes(Attributes.AGGREGATE);
}
public static GemAttributes gemAttributes() {
return new GemAttributes();
public static AggregateAttributes gemAttributes() {
return new AggregateAttributes(Attributes.GEM);
}
public static StatListWrapper wrappedAttributes(StatList stats) {
return new StatListWrapper(stats);
}
private StatList stats;
/**
* TODO: Hopefully this doesn't come back to bite me in the ass, but I
* decided to go the route of using a marker to tell if the attrs
* supports aggregation. By default the answer is no (i.e., an attrs
* that wraps a StatList, such as a monster). It's also important to
* keep track of whether or not the attrs represents a gem list,
* because that subclass was removed when I realized gems have a
* required level, and are aggregates. Not going to worry too much
* about it now, I think this will work until it doesn't.
*/
public static final byte WRAPPER = 0;
public static final byte AGGREGATE = 1;
public static final byte GEM = 2;
Attributes() {
this.stats = StatList.obtain();
private StatList stats;
private byte type;
Attributes(byte type) {
this(type, StatList.obtain());
}
Attributes(StatList stats) {
Attributes(byte type, StatList stats) {
this.type = type;
this.stats = stats;
}
void setType(byte type) {
this.type = type;
}
public byte type() {
return type;
}
public boolean isType(byte type) {
return this.type == type;
}
public boolean isSimpleType() {
return type <= 0;
}
/**
* Returns the number of properties contained within {@link #aggregate()}.
*/

View File

@ -16,17 +16,23 @@ public class AttributesUpdater {
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);
switch (attrs.type()) {
case Attributes.AGGREGATE: {
final int setItemListCount = StatListFlags.countSetItemFlags(listFlags);
if (setItemListCount > 1) {
log.warnf("listFlags(0x%x) contains more than 1 set list", listFlags);
}
break;
}
} else {
final int gemListCount = StatListFlags.countGemFlags(listFlags);
if (gemListCount > 1) {
log.warnf("listFlags(0x%x) contains more than 1 gem list", listFlags);
case Attributes.GEM: {
final int gemListCount = StatListFlags.countGemFlags(listFlags);
if (gemListCount > 1) {
log.warnf("listFlags(0x%x) contains more than 1 gem list", listFlags);
}
break;
}
default: // no-op
return attrs;
}
final StatList list = attrs.list();

View File

@ -1,3 +0,0 @@
package com.riiablo.attributes;
public class GemAttributes extends AggregateAttributes {}

View File

@ -2,7 +2,7 @@ package com.riiablo.attributes;
public class StatListWrapper extends Attributes {
StatListWrapper(StatList stats) {
super(stats);
super(Attributes.WRAPPER, stats);
}
@Override