Changed Item#update(CharData) to Item#update(Attributes,CharStats.Entry)

This is intended to decouple CharData from Attributes application for hirelings
This commit is contained in:
Collin Smith 2020-01-18 02:54:24 -08:00
parent a8999db873
commit b5303828a9
3 changed files with 23 additions and 23 deletions

View File

@ -176,7 +176,7 @@ public class CharData {
base.put(Stat.maxcoldresist, 75);
base.put(Stat.maxpoisonresist, 75);
stats.reset();
stats.update(this); // TODO: this need to be done whenever an item is changed
stats.update(stats, classId.entry()); // TODO: this need to be done whenever an item is changed
skills.clear();
chargedSkills.clear();
@ -203,7 +203,7 @@ public class CharData {
addItem(item); // A lot of this code is redundant
//item.load();
}
stats.update(this);
stats.update(stats, classId.entry());
updateStats();
}
@ -212,7 +212,7 @@ public class CharData {
final int alternate = getAlternate();
for (Item item : equipped.values()) {
if (item == null) continue;
item.update(this);
item.update(stats, classId.entry());
if (item.bodyLoc == BodyLoc.getAlternate(item.bodyLoc, alternate)) {
stats.add(item.props.remaining());
Stat stat;
@ -226,7 +226,7 @@ public class CharData {
stats.add(item.props.remaining());
}
}
stats.update(this);
stats.update(stats, classId.entry());
// FIXME: This corrects a mismatch between max and current, algorithm should be tested later for correctness in other cases
stats.get(Stat.maxstamina).set(stats.get(Stat.stamina));
@ -298,7 +298,7 @@ public class CharData {
break;
case EQUIPPED:
setEquipped(item.bodyLoc, item);
item.update(this);
item.update(stats, classId.entry());
if (item.bodyLoc == BodyLoc.getAlternate(item.bodyLoc, getAlternate())) {
stats.add(item.props.remaining());
Stat stat;
@ -309,7 +309,7 @@ public class CharData {
break;
case STORED:
store.get(item.storeLoc).add(item);
item.update(this);
item.update(stats, classId.entry());
if (item.storeLoc == INVENTORY && item.type.is(Type.CHAR)) {
stats.add(item.props.remaining());
}
@ -378,7 +378,7 @@ public class CharData {
public Item setEquipped(BodyLoc bodyLoc, Item item) {
Item oldItem = equipped.put(bodyLoc, item);
if (item != null) item.update(this);
if (item != null) item.update(stats, classId.entry());
updateSets(oldItem, item);
updateStats();
notifyEquippedChanged(bodyLoc, oldItem, item);

View File

@ -1,8 +1,8 @@
package com.riiablo.item;
import com.badlogic.gdx.utils.Array;
import com.riiablo.CharData;
import com.riiablo.Riiablo;
import com.riiablo.codec.excel.CharStats;
import com.riiablo.codec.excel.ItemStatCost;
public class Attributes {
@ -48,16 +48,16 @@ public class Attributes {
propertyLists.add(props);
}
public void update(CharData charData) {
public void update(Attributes attrs, CharStats.Entry charStats) {
for (PropertyList list : propertyLists) {
if (list != null) update(charData, list);
if (list != null) update(attrs, charStats, list);
}
}
private void update(CharData charData, PropertyList list) {
private void update(Attributes attrs, CharStats.Entry charStats, PropertyList list) {
for (Stat stat : list) {
if (stat.entry.op > 0) {
boolean empty = op(charData, stat, stat.entry);
boolean empty = op(attrs, charStats, stat, stat.entry);
if (empty) {
rem.addCopy(stat);
}
@ -70,10 +70,10 @@ public class Attributes {
}
}
private boolean op(CharData charData, Stat stat, ItemStatCost.Entry entry) {
private boolean op(Attributes attrs, CharStats.Entry charStats, Stat stat, ItemStatCost.Entry entry) {
int op = entry.op;
int op_base = entry.op_param > 0
? charData.getStats().get(Riiablo.files.ItemStatCost.index(entry.op_base)).val
? attrs.get(Riiablo.files.ItemStatCost.index(entry.op_base)).val
: 1;
int op_param = entry.op_param;
@ -83,7 +83,7 @@ public class Attributes {
int statId = Riiablo.files.ItemStatCost.index(op_stat);
Stat opstat = agg.get(statId);
if (opstat != null) {
opstat.add(op(charData, stat, base.get(statId), op, op_base, op_param));
opstat.add(op(charStats, stat, base.get(statId), op, op_base, op_param));
//mod.set(opstat.id);
opCount++;
}
@ -91,7 +91,7 @@ public class Attributes {
return opCount == 0;
}
private int op(CharData charData, Stat stat, Stat opstat, int op, int op_base, int op_param) {
private int op(CharStats.Entry charStats, Stat stat, Stat opstat, int op, int op_base, int op_param) {
switch (op) {
case 1: return (stat.val * opstat.val) / 100;
case 2: return (stat.val * op_base) / (1 << op_param);
@ -103,7 +103,7 @@ public class Attributes {
case 8:
agg.addCopy(stat);
//mod.set(stat.id);
return stat.val * charData.getCharacterClass().entry().ManaPerMagic; // max mana
return stat.val * charStats.ManaPerMagic; // max mana
case 9:
if (opstat.id == Stat.maxhp) { // only increment vit on maxhp op
agg.addCopy(stat);
@ -111,8 +111,8 @@ public class Attributes {
}
return stat.val // max hitpoints
* (opstat.id == Stat.maxhp
? charData.getCharacterClass().entry().LifePerVitality
: charData.getCharacterClass().entry().StaminaPerVitality);
? charStats.LifePerVitality
: charStats.StaminaPerVitality);
case 10: return 0; // no-op
case 11: return (stat.val * opstat.val) / 100; // TODO: modify field value? used with item_maxhp_percent and item_maxmana_percent
case 12: return 0; // no-op

View File

@ -10,13 +10,13 @@ import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.ObjectMap;
import com.riiablo.CharData;
import com.riiablo.CharacterClass;
import com.riiablo.Riiablo;
import com.riiablo.codec.DC6;
import com.riiablo.codec.Index;
import com.riiablo.codec.StringTBL;
import com.riiablo.codec.excel.Armor;
import com.riiablo.codec.excel.CharStats;
import com.riiablo.codec.excel.Gems;
import com.riiablo.codec.excel.Inventory;
import com.riiablo.codec.excel.ItemEntry;
@ -347,7 +347,7 @@ public class Item extends Actor implements Disposable {
return this;
}
public void update(CharData charData) {
public void update(Attributes attrs, CharStats.Entry charStats) {
if ((flags & COMPACT) == COMPACT) return;
props.reset();
if (stats[MAGIC_PROPS] != null) props.add(stats[MAGIC_PROPS]);
@ -369,12 +369,12 @@ public class Item extends Actor implements Disposable {
}
}
}
props.update(charData);
props.update(attrs, charStats);
}
public Details details() {
if (details == null) {
update(Riiablo.charData);
update(Riiablo.charData.getStats(), Riiablo.charData.getCharacterClass().entry());
details = new Details();
}
return details;