def read_attribute_as_char(item, offset, char_count, bits_per_char): item_code = '' for _ in range(char_count): # Reach each char individually char = chr(read_bits(item, offset, bits_per_char)) offset += bits_per_char if char == ' ': break item_code += char return item_code, offset
def get_item_code(item): # Get the item code if Item.is_ear( item ): # Ears lack the bits that indicate item code, but they have a specific ear indicator return 'ear' item_code = '' for i in range(4): # Reach each char individually char = chr(read_bits(item, 76 + i * 8, 8)) if char != ' ': # Item codes are 4 bytes long but most of them have a space as the last char which # should be ignored item_code += char return item_code
def get_set_id(self, item): # Get the set id of the item. if self.rarity is not Rarity.SET: # First, make sure it's actually a set item return None # The relevant bit offset depends on whether the item has multiple graphics and/or is class specific offset = 156 if self.has_multiple_pictures(item): offset += 3 if self.is_class_specific(item): offset += 11 # Once the set id is obtained, get the "true" set id from item_data.py # The set id as given in the item data actually indicates the specific item and not the set, i.e. Sigon parts # have different ids in the 35-40 range, Death's set is 47-49, etc. We want a single id for each set. return get_true_set_id(read_bits(item, offset, 12))
def is_class_specific(item): # The bits indicating if an item is class specific vary in location based on whether it has multiple pictures if Item.has_multiple_pictures(item): return read_bits(item, 158, 1) return read_bits(item, 155, 1)
def get_picture_id(item): # Return id of picture for items with multiple pictures if Item.is_simple(item) or not Item.has_multiple_pictures(item): return None return read_bits(item, 155, 3)
def has_multiple_pictures(item): # Used to indicate whether an item can have multiple graphics (like rings, amulets, jewels etc) return read_bits(item, 154, 1)
def get_rarity(item): if Item.is_simple(item): return None return Rarity(read_bits(item, 150, 4))
def is_simple(item): return read_bits(item, 37, 1)
def is_runeword(item): return read_bits(item, 42, 1)
def is_ear(item): return read_bits(item, 32, 1)
def get_position(item): # Get position in stash x_pos = read_bits(item, 65, 4) y_pos = read_bits(item, 69, 4) return x_pos, y_pos
def num_filled_sockets(item): # Return number of socketed items in item if Item.is_ear(item): return 0 return read_bits(item, 108, 3)
def read_attribute(item, offset, bits_to_read): return read_bits(item, offset, bits_to_read), offset + bits_to_read