Add enchantment parsing
This commit is contained in:
@@ -6,6 +6,7 @@ from enum import Enum
|
||||
|
||||
_data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
|
||||
_basetype_map = None
|
||||
_affix_map = None
|
||||
|
||||
|
||||
class Quality(Enum):
|
||||
@@ -35,14 +36,20 @@ class LowQualityType(Enum):
|
||||
@dataclass
|
||||
class Affix:
|
||||
name_id: int
|
||||
id: int | None = None # TODO: read this
|
||||
# TODO: data
|
||||
stat_id: int | None = None # TODO: These 3 should probably not be optional
|
||||
stat_values: list[int] | None = None
|
||||
stat_text: str | None = None
|
||||
|
||||
def print(self, indent=5):
|
||||
# TODO: name lookup
|
||||
# TODO: modified lookup
|
||||
# TODO: adding in data
|
||||
print(" " * indent, f"{self.name_id} {hex(self.name_id)}")
|
||||
if self.stat_text:
|
||||
subst_text = self.stat_text
|
||||
for i, val in enumerate(self.stat_values):
|
||||
replace = "{" + str(i) + "}"
|
||||
subst_text = subst_text.replace(replace, str(val))
|
||||
else:
|
||||
subst_text = "<No text>"
|
||||
print(" " * indent, f"{hex(self.name_id)}: {subst_text}")
|
||||
|
||||
|
||||
def txtbits(bits: bitarray) -> str:
|
||||
@@ -121,6 +128,17 @@ class Item:
|
||||
print(" " * indent, f"Runeword Id: {self.runeword_id}") # TODO: name lookup
|
||||
if self.personal_name:
|
||||
print(" " * indent, f"Personal name: {self.personal_name}")
|
||||
if self.defense:
|
||||
print(" " * indent, f"Defense: {self.defense}")
|
||||
if self.durability is not None:
|
||||
print(
|
||||
" " * indent,
|
||||
f"Durability: {self.durability} out of {self.max_durability}",
|
||||
)
|
||||
if self.sockets:
|
||||
print(" " * indent, f"Num Sockets: {self.sockets}")
|
||||
if self.quantity:
|
||||
print(" " * indent, f"Quantity: {self.quantity}")
|
||||
if with_raw:
|
||||
print(" " * indent, "Raw Item Data:")
|
||||
bits = bitarray(endian="little")
|
||||
@@ -136,3 +154,11 @@ def lookup_basetype(code: str) -> dict:
|
||||
with open(os.path.join(_data_path, "items.json")) as f:
|
||||
_basetype_map = json.load(f)
|
||||
return _basetype_map[code]
|
||||
|
||||
|
||||
def lookup_affix(code: int) -> dict:
|
||||
global _affix_map
|
||||
if _affix_map is None:
|
||||
with open(os.path.join(_data_path, "affixes.json")) as f:
|
||||
_affix_map = json.load(f)
|
||||
return _affix_map[str(code)]
|
||||
|
||||
Reference in New Issue
Block a user