From d34a557fc876e79e00bdc8981cae824d41d6d8e9 Mon Sep 17 00:00:00 2001 From: syntaxaire Date: Mon, 7 Aug 2023 13:17:48 -0400 Subject: [PATCH] Fix attribute ordering in character decoding Originally, attributes were serialized in "game order" (Strength first). At some point the game began serializing these in alphabetical order instead. Since we depended on game order, this swapped attributes around in the resulting tables. Decoding is now based on attribute name rather than any expected order. --- bot/helpers/qud_decode.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bot/helpers/qud_decode.py b/bot/helpers/qud_decode.py index cc78d41..a1a1a7c 100644 --- a/bot/helpers/qud_decode.py +++ b/bot/helpers/qud_decode.py @@ -9,8 +9,11 @@ from hagadias.qudtile import QudTile from bot.shared import gameroot + gamecodes = gameroot.get_character_codes() +ATTR_NAMES = ("Strength", "Agility", "Toughness", "Intelligence", "Willpower", "Ego") + class Character: """Represents a Caves of Qud player character. This class is intended for modern build codes @@ -52,7 +55,9 @@ def __init__(self, code: dict): case ['XRL.CharacterBuilds.Qud.QudAttributesModule', *_]: pointspurchased = module['data']['PointsPurchased'] base = 10 if self.genotype == 'Mutated Human' else 12 - self.attributes = [base + attr for name, attr in pointspurchased.items()] + self.attributes = [] + for attribute in ATTR_NAMES: + self.attributes.append(base + pointspurchased[attribute]) case ['XRL.CharacterBuilds.Qud.QudCustomizeCharacterModule', *_]: self.name = module['data']['name'] self.pet = module['data']['pet'] @@ -69,11 +74,10 @@ def __init__(self, code: dict): def make_sheet(self) -> str: """Build a printable character sheet for the Character.""" attr_widths = (11, 11, 11, 14, 14, 14) - attr_names = ('Strength:', 'Agility:', 'Toughness:', 'Intelligence:', 'Willpower:', 'Ego:') attr_strings = [] - for width, attr_text, attr, bonus in zip(attr_widths, - attr_names, + for width, attr_name, attr, bonus in zip(attr_widths, + ATTR_NAMES, self.attributes, self.bonuses): # print a +/- in front of any existing bonus @@ -83,15 +87,15 @@ def make_sheet(self) -> str: bonus_text = f'{bonus}' # already has a minus sign else: bonus_text = '' - attr_strings.append(f'{attr_text:{width}}{attr:2}{bonus_text}') + attr_strings.append(f'{attr_name:{width}}{attr:2}{bonus_text}') if hasattr(self, 'name') and self.name is not None: title = f'{self.name} the {self.genotype} {self.subtype}' else: title = f'{self.genotype} {self.subtype}' charsheet = f"""{title} -{attr_strings[0]:18}{attr_strings[3]} -{attr_strings[1]:18}{attr_strings[4]} -{attr_strings[2]:18}{attr_strings[5]}""" +{attr_strings[0]:20}{attr_strings[3]} +{attr_strings[1]:20}{attr_strings[4]} +{attr_strings[2]:20}{attr_strings[5]}""" charsheet += f"\n{self.selection_noun}s: {', '.join(self.selections)}\n" charsheet += f"Starting location: {self.startinglocation}" return charsheet