Skip to content

Instantly share code, notes, and snippets.

@spheenik
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spheenik/c63eaeaadbeb01428144 to your computer and use it in GitHub Desktop.
Save spheenik/c63eaeaadbeb01428144 to your computer and use it in GitHub Desktop.
Example code for getting item names in clarity 1.
// e = hero entity
// n = num of item slot
public static String getItemName(Match match, Entity e, int num) {
int handle = e.getProperty(String.format("m_Inventory.m_hItems.%04d", num));
if (handle == Handle.MAX) {
return "";
}
Entity item = match.getEntities().getByHandle(handle);
String name = item.getProperty("m_iName");
String suffix = null;
Integer runeIdx = item.getDtClass().getPropertyIndex("m_iStoredRuneType");
if (runeIdx != null) {
RuneType rune = RuneType.forCode((int)item.getState()[runeIdx]);
if (rune != RuneType.NONE) {
suffix = rune.getDescription();
} else {
BottleChargeType bc = BottleChargeType.forCode((int)item.getProperty("m_iCurrentCharges"));
suffix = bc.getDescription();
}
}
return suffix != null ? String.format("%s_%s", name, suffix) : name;
}
public enum BottleChargeType {
EMPTY(0, "empty"),
SMALL(1, "small"),
MEDIUM(2, "medium"),
FULL(3, null);
private final int code;
private final String description;
private BottleChargeType(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static BottleChargeType forCode(int code) {
for (BottleChargeType t : values()) {
if (t.code == code) {
return t;
}
}
throw new RuntimeException("invalid bottle charge type");
}
}
public enum RuneType {
NONE(-1, null),
DOUBLE_DAMAGE(0, "doubledamage"),
HASTE(1, "haste"),
ILLUSION(2, "illusion"),
INVISIBILITY(3, "invisibility"),
REGENERATION(4, "regeneration");
private final int code;
private final String description;
private RuneType(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static RuneType forCode(int code) {
for (RuneType t : values()) {
if (t.code == code) {
return t;
}
}
throw new RuntimeException("invalid rune type");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment