Add Enhanced, +Min/Max Damage exceptions to contrib/stats.py

Fixes https://gitlab.com/omicron-oss/d2warehouse/-/issues/1
This commit is contained in:
2023-10-24 15:13:57 +02:00
parent 4a57291ba0
commit d571d0efbb
4 changed files with 56 additions and 2 deletions

View File

@@ -27,6 +27,18 @@ special_stats = {
"poisonlength": None,
"mindamage": "dmg-norm",
"maxdamage": None,
"item_maxdamage_percent": "dmg%", # max before min for this stat
"item_mindamage_percent": None,
}
# Patching of missing data in properties.txt
# NOTE: Ideally we should implement the description functions referenced in itemstatcost.txt
# instead of relying on the debug tooltips of properties.txt, since the game does not
# actually use those, but rather they are present for the excel developers.
properties_patches = {
"dmg-min": {"stat1": "secondary_mindamage"},
"dmg-max": {"stat1": "secondary_maxdamage"},
"dmg%": {"stat1": "item_maxdamage_percent", "stat2": "item_mindamage_percent"},
}
properties = {}
@@ -34,6 +46,8 @@ stat_to_prop = {}
with open(os.path.join(path, "properties.txt")) as f:
reader = csv.DictReader(f, delimiter="\t")
for row in reader:
if row["code"] in properties_patches:
row.update(properties_patches[row["code"]])
if len(row["stat1"]) == 0 or len(row["*Tooltip"]) == 0:
continue
prop = {
@@ -94,3 +108,4 @@ for stat, statdat in itemstatcost.items():
with open("stats.json", "w", newline="\n") as f:
json.dump(stats, f, indent=4)
f.write("\n")

View File

@@ -63,6 +63,15 @@
"save_add": 0,
"save_param_bits": null
},
"17": {
"text": "+#% Enhanced Damage",
"save_bits": [
9,
9
],
"save_add": 0,
"save_param_bits": null
},
"19": {
"text": "+# to Attack Rating",
"save_bits": [
@@ -88,6 +97,22 @@
"save_add": 0,
"save_param_bits": null
},
"23": {
"text": "+# to Minimum Damage",
"save_bits": [
6
],
"save_add": 0,
"save_param_bits": null
},
"24": {
"text": "+# to Maximum Damage",
"save_bits": [
7
],
"save_add": 0,
"save_param_bits": null
},
"27": {
"text": "Regenerate Mana #%",
"save_bits": [
@@ -1639,4 +1664,4 @@
"save_add": 0,
"save_param_bits": null
}
}
}

View File

@@ -58,12 +58,15 @@ class Stat:
text: str | None = None
def print(self, indent=5):
print(" " * indent, str(self))
def __str__(self):
subst_text = self.text
for val in self.values:
subst_text = subst_text.replace("#", str(val), 1)
if self.parameter:
subst_text = re.sub(r"\[[^\]]*\]", str(self.parameter), subst_text, 1)
print(" " * indent, subst_text)
return subst_text
def txtbits(bits: bitarray) -> str:

View File

@@ -69,3 +69,14 @@ class ParseItemTest(unittest.TestCase):
self.assertEqual(item.quality, Quality.HIGH)
self.assertEqual(len(item.stats), 2)
self.assertEqual(item.sockets, 2)
def test_ed_max(self):
# test bugfix for https://gitlab.com/omicron-oss/d2warehouse/-/issues/1
data = bytes.fromhex(
"10008000050094e6095cd89f590b23557340c2629612233cf09010a14183094260109c6866232080cc7f"
)
data, item = parse_item(data)
self.assertEqual(data, b"")
self.assertEqual(item.code, "spr")
self.assertEqual(str(item.stats[0]), "+13% Enhanced Damage")
self.assertEqual(str(item.stats[2]), "+2 to Maximum Damage")