mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-20 19:49:47 +07:00
Added set detection on item loading Added Player owner reference to Item Added Player owner to format methods for stats
This commit is contained in:
parent
150494b45e
commit
a0a09d1a1a
@ -6,14 +6,17 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.badlogic.gdx.utils.IntIntMap;
|
||||
import com.riiablo.CharacterClass;
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.COF;
|
||||
import com.riiablo.codec.D2S;
|
||||
import com.riiablo.codec.excel.Armor;
|
||||
import com.riiablo.codec.excel.Sets;
|
||||
import com.riiablo.codec.excel.Weapons;
|
||||
import com.riiablo.item.BodyLoc;
|
||||
import com.riiablo.item.Item;
|
||||
import com.riiablo.item.Quality;
|
||||
import com.riiablo.map.DT1.Tile;
|
||||
import com.riiablo.map.Map;
|
||||
import com.riiablo.server.Connect;
|
||||
@ -104,6 +107,11 @@ public class Player extends Entity {
|
||||
EnumMap<BodyLoc, Item> equipped = new EnumMap<>(BodyLoc.class);
|
||||
final Set<SlotListener> SLOT_LISTENERS = new CopyOnWriteArraySet<>();
|
||||
|
||||
/** total number of items equipped for each set */
|
||||
public final IntIntMap SETS_EQUIP = new IntIntMap();
|
||||
/** total number of owned items for each set item */
|
||||
public final IntIntMap SETS_OWNS = new IntIntMap();
|
||||
|
||||
public Player(String name, CharacterClass characterClass) {
|
||||
this(name, characterClass.id);
|
||||
stats = new StatsImpl(name, characterClass.id);
|
||||
@ -144,7 +152,15 @@ public class Player extends Entity {
|
||||
private void loadEquipped(EnumMap<BodyLoc, Item> items) {
|
||||
equipped.putAll(items);
|
||||
for (java.util.Map.Entry<BodyLoc, Item> entry : items.entrySet()) {
|
||||
entry.getValue().load();
|
||||
Item item = entry.getValue();
|
||||
item.setOwner(this);
|
||||
if (item.quality == Quality.SET) {
|
||||
SETS_OWNS.getAndIncrement(item.qualityId, 0, 1);
|
||||
Sets.Entry set = Riiablo.files.SetItems.get(item.qualityId).getSet();
|
||||
int id = Riiablo.files.Sets.index(set.index);
|
||||
SETS_EQUIP.getAndIncrement(id, 0, 1);
|
||||
}
|
||||
item.load();
|
||||
if (DEBUG_EQUIP) Gdx.app.debug(TAG, entry.getKey() + ": " + entry.getValue());
|
||||
}
|
||||
}
|
||||
@ -152,6 +168,10 @@ public class Player extends Entity {
|
||||
private void loadInventory(Array<Item> items) {
|
||||
inventory.addAll(items);
|
||||
for (Item item : items) {
|
||||
item.setOwner(this);
|
||||
if (item.quality == Quality.SET) {
|
||||
SETS_OWNS.getAndIncrement(item.qualityId, 0, 1);
|
||||
}
|
||||
item.load();
|
||||
if (DEBUG_INV) Gdx.app.debug(TAG, item.gridX + "," + item.gridY + ": " + item);
|
||||
}
|
||||
|
@ -152,6 +152,8 @@ public class Item extends Actor implements Disposable {
|
||||
|
||||
public Details details;
|
||||
|
||||
public Player owner;
|
||||
|
||||
public static Item loadFromStream(BitStream bitStream) {
|
||||
return new Item().read(bitStream);
|
||||
}
|
||||
@ -362,6 +364,16 @@ public class Item extends Actor implements Disposable {
|
||||
return (T) base;
|
||||
}
|
||||
|
||||
public void setOwner(Player owner) {
|
||||
if (this.owner != owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
|
||||
public Player getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringBuilder builder = new ToStringBuilder(this);
|
||||
@ -862,11 +874,11 @@ public class Item extends Actor implements Disposable {
|
||||
if (Item.this.type.is(Type.GEM) || Item.this.type.is(Type.RUNE)) {
|
||||
assert stats.length == NUM_GEM_PROPS;
|
||||
add().height(font.getLineHeight()).space(SPACING).row();
|
||||
add(new Label(Riiablo.string.lookup("GemXp3") + " " + stats[WEAPON_PROPS].copy().reduce().get().format(), font, Riiablo.colors.white)).center().space(SPACING).row();
|
||||
String tmp = stats[ARMOR_PROPS].copy().reduce().get().format();
|
||||
add(new Label(Riiablo.string.lookup("GemXp3") + " " + stats[WEAPON_PROPS].copy().reduce().get().format(owner), font, Riiablo.colors.white)).center().space(SPACING).row();
|
||||
String tmp = stats[ARMOR_PROPS].copy().reduce().get().format(owner);
|
||||
add(new Label(Riiablo.string.lookup("GemXp4") + " " + tmp, font, Riiablo.colors.white)).center().space(SPACING).row();
|
||||
add(new Label(Riiablo.string.lookup("GemXp1") + " " + tmp, font, Riiablo.colors.white)).center().space(SPACING).row();
|
||||
add(new Label(Riiablo.string.lookup("GemXp2") + " " + stats[SHIELD_PROPS].copy().reduce().get().format(), font, Riiablo.colors.white)).center().space(SPACING).row();
|
||||
add(new Label(Riiablo.string.lookup("GemXp2") + " " + stats[SHIELD_PROPS].copy().reduce().get().format(owner), font, Riiablo.colors.white)).center().space(SPACING).row();
|
||||
add().height(font.getLineHeight()).space(SPACING).row();
|
||||
}
|
||||
|
||||
@ -953,7 +965,7 @@ public class Item extends Actor implements Disposable {
|
||||
}
|
||||
});
|
||||
for (Stat.Instance stat : aggregate) {
|
||||
String text = stat.format();
|
||||
String text = stat.format(owner);
|
||||
if (text == null) continue;
|
||||
add(new Label(text, font, Riiablo.colors.blue)).center().space(SPACING).row();
|
||||
}
|
||||
@ -983,13 +995,15 @@ public class Item extends Actor implements Disposable {
|
||||
add(new Label(itemFlags.toString(), font, Riiablo.colors.blue)).center().space(SPACING).row();
|
||||
}
|
||||
|
||||
// TODO: This can be cleaned up later -- add support for set detection
|
||||
if (quality == SET) {
|
||||
add().height(font.getLineHeight()).space(SPACING).row();
|
||||
Sets.Entry set = Riiablo.files.SetItems.get(qualityId).getSet();
|
||||
add(new Label(Riiablo.string.lookup(set.name), font, Riiablo.colors.gold)).space(SPACING).row();
|
||||
for (SetItems.Entry item : set.getItems()) {
|
||||
add(new Label(Riiablo.string.lookup(item.index), font, Riiablo.colors.red)).space(SPACING).row();
|
||||
int numOwned = owner.SETS_OWNS.get(Riiablo.files.SetItems.index(item.index), 0);
|
||||
Label label = new Label(Riiablo.string.lookup(item.index), font,
|
||||
numOwned > 0 ? Riiablo.colors.green : Riiablo.colors.red);
|
||||
add(label).space(SPACING).row();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.riiablo.codec.excel.ItemStatCost;
|
||||
import com.riiablo.codec.excel.SkillDesc;
|
||||
import com.riiablo.codec.excel.Skills;
|
||||
import com.riiablo.codec.util.BitStream;
|
||||
import com.riiablo.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -532,17 +533,18 @@ public class Stat {
|
||||
"ModStre9e", "ModStre9g", "ModStre9d", "ModStre9f",
|
||||
};
|
||||
|
||||
public String format() {
|
||||
return format(false);
|
||||
public String format(Player owner) {
|
||||
return format(owner, entry.descfunc, entry.descval, entry.descstrpos, entry.descstrneg, entry.descstr2);
|
||||
}
|
||||
|
||||
public String format(boolean group) {
|
||||
@Deprecated
|
||||
public String format(Player owner, boolean group) {
|
||||
return group
|
||||
? format(entry.dgrpfunc, entry.dgrpval, entry.dgrpstrpos, entry.dgrpstrneg, entry.dgrpstr2)
|
||||
: format(entry.descfunc, entry.descval, entry.descstrpos, entry.descstrneg, entry.descstr2);
|
||||
? format(owner, entry.dgrpfunc, entry.dgrpval, entry.dgrpstrpos, entry.dgrpstrneg, entry.dgrpstr2)
|
||||
: format(owner, entry.descfunc, entry.descval, entry.descstrpos, entry.descstrneg, entry.descstr2);
|
||||
}
|
||||
|
||||
public String format(int func, int valmode, String strpos, String strneg, String str2) {
|
||||
public String format(Player owner, int func, int valmode, String strpos, String strneg, String str2) {
|
||||
int value;
|
||||
CharStats.Entry entry;
|
||||
Skills.Entry skill;
|
||||
@ -827,7 +829,7 @@ public class Stat {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(int unused1, int unused2, String unused3, String unused4, String unused5) {
|
||||
public String format(Player unused0, int unused1, int unused2, String unused3, String unused4, String unused5) {
|
||||
if (stats.length == 2) {
|
||||
if (stats[0].value == stats[1].value) {
|
||||
return Riiablo.string.format(str, stats[1].value);
|
||||
@ -846,7 +848,7 @@ public class Stat {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stat + "(" + entry + ")" + "=" + Arrays.toString(stats) + " : " + format(0, 0, null, null, null);
|
||||
return stat + "(" + entry + ")" + "=" + Arrays.toString(stats) + " : " + format(null, 0, 0, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user