Esempio n. 1
0
File: Wizard.py Progetto: lowhrtz/gm
def wizard_accept( fields, pages ):
    character_dict = pages['ReviewPage'].make_character_dict()

    data_list = [
        character_dict['unique_id'],
        character_dict['Name'],
        character_dict['Level'],
        character_dict['XP'],
        character_dict['Gender'],
        character_dict['Alignment'],
        character_dict['Classes'],
        character_dict['Race'],
        character_dict['HP'],
        character_dict['Age'],
        character_dict['Height'],
        character_dict['Weight'],
        character_dict['Portrait'],
        character_dict['Portrait_Image_Type'],
        character_dict['STR'],
        character_dict['INT'],
        character_dict['WIS'],
        character_dict['DEX'],
        character_dict['CON'],
        character_dict['CHA'],
        ]

    DbQuery.begin()
    row_id = DbQuery.insertRow( 'Characters', data_list )

    for meta_row in character_dict['Characters_meta']:
        data_list = [
            meta_row['character_id'],
            meta_row['Type'],
            meta_row['Entry_ID'],
            meta_row['Data'],
            meta_row['Notes'],
        ]
        DbQuery.insertRow( 'Characters_meta', data_list )

    DbQuery.commit()

    return row_id
Esempio n. 2
0
def wizard_accept(fields, pages):
    character_dict = pages['ReviewPage'].make_character_dict()

    data_list = [
        character_dict['unique_id'],
        character_dict['Name'],
        character_dict['Level'],
        character_dict['XP'],
        character_dict['Gender'],
        character_dict['Alignment'],
        character_dict['Classes'],
        character_dict['Race'],
        character_dict['HP'],
        character_dict['Age'],
        character_dict['Height'],
        character_dict['Weight'],
        character_dict['Portrait'],
        character_dict['Portrait_Image_Type'],
        character_dict['STR'],
        character_dict['INT'],
        character_dict['WIS'],
        character_dict['DEX'],
        character_dict['CON'],
        character_dict['CHA'],
    ]

    DbQuery.begin()
    row_id = DbQuery.insertRow('Characters', data_list)

    for meta_row in character_dict['Characters_meta']:
        data_list = [
            meta_row['character_id'],
            meta_row['Type'],
            meta_row['Entry_ID'],
            meta_row['Data'],
            meta_row['Notes'],
        ]
        DbQuery.insertRow('Characters_meta', data_list)

    DbQuery.commit()

    return row_id
Esempio n. 3
0
    def accept(self, fields, pages, external_data):
        encounters = DbQuery.getTable('Encounters')
        encounters_indexed = {e['unique_id']: e for e in encounters}
        characters = DbQuery.getTable('Characters')
        characters_indexed = {c['unique_id']: c for c in characters}
        character_classes = DbQuery.getTable('Classes')
        c_classes_indexed = {c['unique_id']: c for c in character_classes}

        party_treasure = [
            t for t in self.campaign['Campaigns_meta']
            if t['Type'] == 'Party Treasure'
        ]
        everything_else = [
            e for e in self.campaign['Campaigns_meta']
            if e['Type'] != 'Party Treasure'
        ]
        # new_treasure = deepcopy(pages['Wrap Up'].treasure)
        new_treasure = {
            'cp': fields['CP'],
            'sp': fields['SP'],
            'ep': fields['EP'],
            'gp': fields['GP'],
            'pp': fields['PP'],
            'items': fields['Items'],
        }
        new_treasure_xp_value = Treasure.get_xp_value(new_treasure)
        for pt in party_treasure:
            t = pt['Data']
            t = json.loads(t)
            for k, v in t.items():
                # print(k, v)
                new_treasure[k] += v
        new_treasure_entry = {
            'Type': 'Party Treasure',
            'Entry_ID': None,
            'Data': json.dumps(new_treasure),
            'Notes': None
        }

        everything = everything_else + [
            new_treasure_entry,
        ]
        DbQuery.begin()
        DbQuery.deleteRow('Campaigns_meta', 'campaign_id',
                          self.campaign['unique_id'])
        for i in everything:
            row = self.campaign['unique_id'], i['Type'], i['Entry_ID'], i[
                'Data'], i['Notes']
            DbQuery.insertRow('Campaigns_meta', row)
        # DbQuery.commit()
        self.campaign['Campaigns_meta'] = everything

        encounter_id = pages['Encounter Tracker'].encounter_id
        enemies_serialized = encounters_indexed[encounter_id]['enemy_team']
        enemies = json.loads(enemies_serialized)
        xp_total = sum(e['XP Value'] for e in enemies)
        if fields['Include Treasure XP']:
            xp_total += new_treasure_xp_value
        pc_team = external_data['PC Team']
        xp_eligible = []
        for pc in pc_team:
            pc_id = pc['unique_id']
            pc = characters_indexed[pc_id]
            current_hp = get_character_hp(pc)
            if current_hp > 0:
                xp_eligible.append(pc)
        num_of_eligible = len(xp_eligible)
        xp_per = xp_total // num_of_eligible
        # print(xp_total, num_of_eligible, xp_per)
        from decimal import Decimal
        for pc in xp_eligible:
            pc_id = pc['unique_id']
            xp_list = str(pc['XP']).split('/')
            add_xp = xp_per // len(xp_list)
            pc_class_list = pc['Classes'].split('/')
            if len(pc_class_list) == 1:
                cl = c_classes_indexed[pc_class_list[0]]
                xp_bonus_string = cl['Experience_Bonus']
                xp_bonus = SystemSettings.parse_xp_bonus(xp_bonus_string, pc)
                if xp_bonus:
                    add_xp = int(add_xp *
                                 (1 + Decimal(xp_bonus) / Decimal(100)))
            new_xp_list = [int(xp) + add_xp for xp in xp_list]
            new_xp = '/'.join(str(xp) for xp in new_xp_list)
            DbQuery.update_cols('Characters', 'unique_id', pc_id, ('XP', ),
                                (new_xp, ))
        DbQuery.commit()