From 2a6ab418ed67e6814ea6767e0454f67c5c3f98c3 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Fri, 12 Apr 2019 02:14:47 -0700 Subject: [PATCH] Improved stat and skill update support --- core/src/com/riiablo/CharData.java | 24 +++++++++++++++++-- .../com/riiablo/panel/SpellsQuickPanel.java | 7 +++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/src/com/riiablo/CharData.java b/core/src/com/riiablo/CharData.java index 0cd9ad88..c3bc2e5d 100644 --- a/core/src/com/riiablo/CharData.java +++ b/core/src/com/riiablo/CharData.java @@ -174,15 +174,33 @@ public class CharData { cursor = null; stats.reset(); for (Item item : d2s.items.items) { - addItem(item); + addItem(item); // A lot of this code is redundant //item.load(); } - stats.update(this); updateStats(); } private void updateStats() { + stats.reset(); + final int alternate = getAlternate(); + for (Item item : equipped.values()) { + item.update(); + if (item.bodyLoc == BodyLoc.getAlternate(item.bodyLoc, alternate)) { + stats.add(item.props.remaining()); + Stat stat; + if ((stat = item.props.get(Stat.armorclass)) != null) { + stats.aggregate().addCopy(stat); + } + } + } + for (Item item : store.get(StoreLoc.INVENTORY)) { + if (item.type.is(Type.CHAR)) { + stats.add(item.props.remaining()); + } + } + stats.update(this); + // This appears to be hard-coded in the original client int dex = stats.get(Stat.dexterity).value(); stats.aggregate().get(Stat.armorclass).add(dex / 4); @@ -300,6 +318,7 @@ public class CharData { Item oldItem = equipped.put(bodyLoc, item); if (item != null) item.update(); updateSets(oldItem, item); + updateStats(); notifyEquippedChanged(bodyLoc, oldItem, item); return oldItem; } @@ -317,6 +336,7 @@ public class CharData { d2s.header.alternate = alternate; Item LH = getEquipped(alternate > 0 ? BodyLoc.LARM2 : BodyLoc.LARM); Item RH = getEquipped(alternate > 0 ? BodyLoc.RARM2 : BodyLoc.RARM); + updateStats(); notifyEquippedAlternated(alternate, LH, RH); } } diff --git a/core/src/com/riiablo/panel/SpellsQuickPanel.java b/core/src/com/riiablo/panel/SpellsQuickPanel.java index 2840cf9f..a3321963 100644 --- a/core/src/com/riiablo/panel/SpellsQuickPanel.java +++ b/core/src/com/riiablo/panel/SpellsQuickPanel.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.assets.AssetDescriptor; +import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; @@ -126,7 +127,11 @@ public class SpellsQuickPanel extends Table implements Disposable, CharData.Skil @Override public void onChanged(CharData client, IntIntMap skills) { - for (IntIntMap.Entry skillId : Riiablo.charData.getSkills()) { + for (Table table : tables) { + for (Actor child : table.getChildren()) child.clear(); + table.clear(); + } + for (IntIntMap.Entry skillId : skills) { if (skillId.value <= 0) continue; // level <= 0 final Skills.Entry skill = Riiablo.files.skills.get(skillId.key);