Quick and dirty initial commit to share progress

This commit is contained in:
2023-10-21 14:52:16 +02:00
commit a741aa6ff0
10 changed files with 480 additions and 0 deletions

67
d2warehouse/item.py Normal file
View File

@@ -0,0 +1,67 @@
from bitarray import bitarray
from dataclasses import dataclass
from enum import Enum
class Quality(Enum):
LOW = 1
NORMAL = 2
HIGH = 3
MAGIC = 4
SET = 5
RARE = 6
UNIQUE = 7
CRAFTED = 8
def __str__(self) -> str:
return self.name.capitalize()
def txtbits(bits: bitarray) -> str:
txt = "".join(str(b) for b in bits)
grouped = [txt[i : i + 8] for i in range(0, len(txt), 8)]
return " ".join(grouped)
@dataclass
class Item:
raw_data: bytes
is_identified: bool
is_socketed: bool
is_beginner: bool
is_simple: bool
is_ethereal: bool
is_personalized: bool
is_runeword: bool
pos_x: int
pos_y: int
kind: str
uid: int | None
lvl: int | None
quality: Quality | None
graphic: int | None
inherent: int | None
def print(self, indent=5):
properties = []
print(" " * indent, self.kind)
if self.lvl:
print(" " * indent, f"ilvl {self.lvl}")
if self.is_simple:
properties.append("Simple")
else:
properties.append("Extended")
if self.is_ethereal:
properties.append("Ethereal")
if not self.is_identified:
properties.append("Unidentified")
if self.is_socketed:
properties.append("Socketed")
if properties:
print(" " * indent, ", ".join(properties))
print(" " * indent, f"at {self.pos_x}, {self.pos_y}")
bits = bitarray(endian="little")
bits.frombytes(self.raw_data)
print(" " * indent, txtbits(bits))
print("")
print("")