def initialize_page(self, fields, pages, external_data): t = time.time() self.encounter_id = f'encounter-{t}' hd_plus_minus_pattern = re.compile(r'^\d+[+-]\d+$') monster_team = external_data['Monster Team'] enemies = [] for enemy in monster_team: if enemy['TableName'] == 'Characters': enemy['XP Value'] = SystemSettings.get_xp_value(enemy) enemies.append(enemy) else: hd = enemy['HD'] if hd.isdigit(): roll_string = f'{hd}d8' hp = Dice.rollString(roll_string) elif hd_plus_minus_pattern.match(hd): hd_split = re.split(r'([+-])', hd) roll_string = f'{hd_split[0]}d8{hd_split[1]}{hd_split[2]}' hp = max(Dice.rollString(roll_string), 1) elif hd.endswith('hp'): roll_string = f'''{hd.replace('hp', '').strip()}''' hp = max(Dice.rollString(roll_string), 1) else: # hp = hd hd = Dice.rollString(hd) hp = Dice.rollString(f'{hd}d8') enemy['HP'] = hp enemy['XP Value'] = SystemSettings.get_xp_value(enemy) enemies.append(enemy) serialized_enemies = json.dumps(enemies) DbQuery.insertRow( 'Encounters', (self.encounter_id, '', serialized_enemies, self.campaign_id)) DbQuery.commit()
def remove_client(fields): current_client = fields['Client List Current'] DbQuery.deleteRow('WebApp', 'remote_addr', current_client['remote_addr']) DbQuery.commit() web_app = DbQuery.getTable('WebApp') return {'Client List': [(i['remote_addr'], i) for i in web_app]}
def validation(self): """ Метод выполняет валидацию текста пользователя путем разделения его на составляющие( команда и аргументы), проверки на существование в БД и проверки статуса в БД. """ if self.text[0] == '.' and self.text != '': split_text = self.text.split() if len(split_text) == 1: command = str(split_text[0]) args = ' ' else: command = str(split_text[0]) del split_text[0] args = ' '.join(split_text) query = "SELECT * FROM command WHERE command = '" + command + "'" dbq = DbQuery.Query(query) check_cmd = dbq.db_query_wrt() for row in check_cmd: if len(row) > 0: query = "SELECT turn FROM public.command WHERE command='" + str( command) + "'" dbq = DbQuery.Query(query) check_status = dbq.db_query_wrt() for row_two in check_status: if len(row_two) > 0: if row_two[0] is True: return command, args else: print('[DEBUG]: Command disabled') else: print('[DEBUG]: Command not existence')
def __init__(self): super().__init__(5, 'Proficiencies') self.set_subtitle('Choose available proficiencies') self.proficiency_table = [row for row in DbQuery.getTable('Items') if row['Is_Proficiency'].lower() == "yes"] self.class_table = DbQuery.getTable('Classes') self.race_table = DbQuery.getTable('Races') self.slots_remaining = 0 self.orig_proficiencies = [] self.specialised_list = [] self.double_specialised_list = [] self.shadow_list = None prof_data = { 'fill_avail': self.fill_proficiencies, 'slots': self.get_proficiency_slots, 'slots_name': 'Proficiency', # 'category_field': 'Damage_Type', # 'category_callback': self.get_category_tab_name, 'tool_tip': self.get_tool_tip, 'add': self.add_proficiency, 'remove': self.remove_proficiency, } proficiencies = Widget('Proficiencies', 'DualList', data=prof_data) self.add_row([proficiencies, ])
def change_character(fields): current_character = fields['Choose Character Data'] character_id = current_character['unique_id'] current_client = fields['Client List Current'] if current_client is None: return {} remote_addr = current_client['remote_addr'] DbQuery.updateRow('WebApp', 'remote_addr', remote_addr, (remote_addr, character_id)) DbQuery.commit() return {'Client List': DbQuery.getTable('WebApp')}
def fill_proficiencies( self ): self.specialised_list = [] self.double_specialised_list = [] class_dict = self.fields['Class'] race_dict = self.fields['Race'] item_dict_list = [ i for i in DbQuery.getTable( 'Items' ) if i['Is_Proficiency'] == 'yes' ] if 'classes' in class_dict: wp_list = [ cl['Weapons_Permitted' ] for cl in class_dict[ 'classes' ] ] weapons_permitted = self.race_wp( wp_list, race_dict['unique_id'], item_dict_list ) else: weapons_permitted = [ weapon.strip().lower() for weapon in class_dict['Weapons_Permitted'].split( ',' ) ] item_list = [] for item_dict in item_dict_list: item_tuple = ( item_dict['Name'], item_dict ) damage_type_list = [ damage_type.strip().lower() for damage_type in item_dict['Damage_Type'].split( ',' ) ] if 'any' in weapons_permitted: item_list.append( item_tuple ) elif any( weapon in item_dict['Name'].lower() for weapon in weapons_permitted ): item_list.append( item_tuple ) elif [ i for i in weapons_permitted if i in damage_type_list ]: item_list.append( item_tuple ) elif 'single-handed swords (except bastard swords)' in weapons_permitted: if item_dict['unique_id'].startswith( 'sword' ) and \ 'both-hand' not in damage_type_list and 'two-hand' not in damage_type_list: item_list.append( item_tuple ) return item_list
def prefill_bought_list(self): race_dict = self.fields['Race'] class_dict = self.fields['Class'] items_dict_list = DbQuery.getTable('Items') item_id_list = [] if race_dict['unique_id'] == 'elf' and 'fighter' in class_dict[ 'unique_id']: percent = Dice.randomInt(1, 100) if percent <= 5: item_id_list.append('armour_elfin_chain') if 'magic_user' in class_dict[ 'unique_id'] or 'illusionist' in class_dict['unique_id']: item_id_list.append('spellbook') if 'cleric' in class_dict['unique_id']: item_id_list.append('holy_symbol_pewter') if 'druid' in class_dict['unique_id']: item_id_list.append('holy_symbol_wooden') if 'thief' in class_dict['unique_id'] or 'assassin' in class_dict[ 'unique_id']: item_id_list.append('thieves_tools') item_list = [] for item_dict in items_dict_list: if item_dict['unique_id'] in item_id_list: item_list.append( (item_dict['Name'] + ' - ' + item_dict['Cost'], item_dict)) return item_list
def get_full_items(items): items_table = DbQuery.getTable('Items') items_indexed = {i['unique_id']: i for i in items_table} full_items = [] for item in items: if type(item) is tuple: gem_type, actual_value = item gem_type_list = [ i for i in items_table if i['Subcategory'] == gem_type ] gem_item = gem_type_list[Dice.randomInt( 0, len(gem_type_list) - 1)] gem_item = copy(gem_item) gem_item['Value'] = actual_value full_items.append(gem_item) elif type(item) is list: print('list:', item) else: item_dict = copy(items_indexed[item]) if item_dict['Category'] == 'Jewellery': item_dict['Value'] = Dice.rollString( item_dict['Value']) full_items.append(item_dict) return full_items
def get_save_background(environ): raw_post = environ.get('wsgi.input', '') post = raw_post.read(int(environ.get('CONTENT_LENGTH', 0))) post_dict = parse_qs(post.decode(), True) character_id = post_dict.get('character_id', None) background = post_dict.get('background', None) if character_id and background: character_id = character_id[0] background = background[0] characters = DbQuery.getTable('Characters') for c in characters: if c['unique_id'] == character_id: DbQuery.update_cols('Characters', 'unique_id', character_id, ['Background'], (background, )) DbQuery.commit() return get_existing_character(environ, character_id) return '<h1>Problem saving background!</h1>'
def get_available_races(self): race_dict_list = DbQuery.getTable('Races') #print 'STR: ' + self.fields['STR'] if self.fields['STR']: attribute_dict = { attr: int(self.fields[attr]) for attr in get_attribute_names() } else: attribute_dict = None if attribute_dict is None: return [(race['Name'], race) for race in race_dict_list] l = [] for race in race_dict_list: allowed = True for attr in get_attribute_names(): attr_cap = attr.capitalize() min_score = race['Minimum_' + attr_cap] max_score = race['Maximum_' + attr_cap] if not min_score <= attribute_dict[attr] <= max_score: allowed = False if allowed: l.append((race['Name'], race)) return l
def adjust_enemy_hp(dialog_return, fields, enemy_index): new_hp = dialog_return + fields[f'Current HP {enemy_index}'] en = enemies[enemy_index] if en['TableName'] == 'Monsters': enemies[enemy_index]['HP'] = new_hp serialized_enemies = json.dumps(enemies) DbQuery.update_cols('Encounters', 'unique_id', encounter_id, ('enemy_team', ), (serialized_enemies, )) DbQuery.commit() else: char_id = en['unique_id'] save_character_hp(char_id, new_hp) return { f'Current HP {enemy_index}': new_hp, }
def get_available_races( self ): race_dict_list = DbQuery.getTable( 'Races' ) #print 'STR: ' + self.fields['STR'] if self.fields['STR']: attribute_dict = { attr : int( self.fields[attr] ) for attr in get_attribute_names() } else: attribute_dict = None if attribute_dict is None: return [ ( race['Name'], race ) for race in race_dict_list ] l = [] for race in race_dict_list: allowed = True for attr in get_attribute_names(): attr_cap = attr.capitalize() min_score = race[ 'Minimum_' + attr_cap ] max_score = race[ 'Maximum_' + attr_cap ] if not min_score <= attribute_dict[attr] <= max_score: allowed = False if allowed: l.append( ( race['Name'], race ) ) return l
def ready_to_level_up(pc): classes_meta = DbQuery.getTable('Classes_meta') classes = pc['Classes'].split('/') xp = str(pc['XP']).split('/') level = str(pc['Level']).split('/') level_up_classes = [] for i, cl in enumerate(classes): cl_xp = int(xp[i]) cl_level = int(level[i]) xp_table = [row for row in classes_meta if row['class_id'] == cl and row['Type'] == 'xp table'] each = None for j, row in enumerate(xp_table): if row['Level'].lower() == 'each': each = j if each is not None: each = xp_table.pop(each) xp_table.sort(key=lambda x: int(x['Level'])) top_row = xp_table[len(xp_table) - 1] top_row_level = int(top_row['Level']) if cl_level > top_row_level: levels_past_top_row = (cl_xp - top_row['XP']) // each['XP'] if top_row_level + levels_past_top_row > cl_level: level_up_classes.append(cl) else: for j, row in enumerate(xp_table): if int(row['Level']) == cl_level + 1: if cl_xp >= row['XP']: level_up_classes.append(cl) break return level_up_classes
def get_character(environ): remote_addr = environ['REMOTE_ADDR'] webapp_table = DbQuery.getTable('WebApp') for entry in webapp_table: if entry['remote_addr'] == remote_addr: return get_existing_character(environ, entry['character_id']) return get_new_character(environ)
def ready_to_level_up( pc ): classes_meta = DbQuery.getTable( 'Classes_meta' ) classes = pc['Classes'].split( '/' ) xp = str( pc['XP'] ).split( '/' ) level = str( pc['Level'] ).split( '/' ) level_up_classes = [] for i, cl in enumerate( classes ): cl_xp = int( xp[i] ) cl_level = int( level[i] ) xp_table = [ row for row in classes_meta if row['class_id'] == cl and row['Type'] == 'xp table' ] each = None for j, row in enumerate( xp_table ): if row['Level'].lower() == 'each': each = j if each is not None: each = xp_table.pop( each ) xp_table.sort( key=lambda x: int( x['Level'] ) ) top_row = xp_table[ len( xp_table ) - 1 ] top_row_level = int( top_row['Level'] ) if cl_level > top_row_level: levels_past_top_row = ( cl_xp - top_row['XP'] ) // each['XP'] if top_row_level + levels_past_top_row > cl_level: level_up_classes.append( cl ) else: for j, row in enumerate( xp_table ): if int( row['Level'] ) == cl_level + 1: if cl_xp >= row['XP']: level_up_classes.append( cl ) break return level_up_classes
def get_classes_options(environ): if environ.get('REQUEST_METHOD', '') != 'POST': return '' # print(f'ip = {environ["REMOTE_ADDR"]}') raw_post = environ.get('wsgi.input', '') post = raw_post.read(int(environ.get('CONTENT_LENGTH', 0))) post_dict = parse_qs(post.decode(), True) race_id = post_dict.get('race_id', None) if not race_id: return '' race = SystemSettings.get_race_dict({'Race': race_id[0]}) class_options = [] for races_meta in race['Races_meta']: if races_meta['Type'] == 'class' and races_meta['Subtype'] == 'permitted class options': class_options_string = races_meta['Modified'] if not class_options_string: continue for class_option in class_options_string.split(','): class_option = class_option.strip() class_options.append((class_option.title().replace('_', ' '), class_option.replace('/', '_'))) if not class_options: classes = DbQuery.getTable('Classes') class_options = [(normal_class['Name'], normal_class['unique_id']) for normal_class in classes] return ' '.join([f'<option value="{i[0]}">{i[0]}</option>' for i in class_options])
def initialize_page( self, fields, pages, external_data ): pc = external_data['Character List Current'] classes = pc['Classes'].split( '/' ) level = str( pc['Level'] ).split( '/' ) self.ready_list = ready_to_level_up( pc ) self.ready_dict_list = [ cl for cl in DbQuery.getTable( 'Classes' ) if cl['unique_id'] in self.ready_list ] self.wizard_category = False self.priest_category = False self.proficiency_slots_available = 0 for cl in self.ready_dict_list: if cl['Category'] == 'wizard': self.wizard_category = cl if cl['Category'] == 'priest': self.priest_category == cl wpa = cl['Weapon_Proficiency_Advancement'].split('/') slots = int( wpa[0] ) per_level = int( wpa[1] ) pc_level = int( level[ classes.index( cl['unique_id'] ) ] ) if pc_level % per_level == 0: self.proficiency_slots_available = slots if self.wizard_category: self.next_page_id = pages['Spellbook'].get_page_id() elif self.proficiency_slots_available: self.next_page_id = pages['Proficiencies'].get_page_id() elif self.ready_list: self.next_page_id = pages['Review'].get_page_id() else: self.next_page_id = -1 return { 'Intro Text': 'There are no classes ready to level up for this character!', 'Intro Text2': '' }
def initialize_page(self, fields, pages, external_data): spells_table = DbQuery.getTable('Spells') pc = external_data['Character List Current'] wizard_category = pages['Level Up'].wizard_category other_spellcaster_category = pages['Level Up'].other_spellcaster_category if wizard_category: class_name = wizard_category['Name'] spell_type = wizard_category['Primary_Spell_List'].replace('_', ' ').title() else: class_name = other_spellcaster_category['Name'] spell_type = other_spellcaster_category['Primary_Spell_List'].replace('_', ' ').title() if spell_type != class_name: class_name = spell_type self.meta_row_type = 'DailySpells' if external_data['Daily Spells 2'] and\ external_data['Daily Spells 2'][0]['Type'].replace('_', ' ').title() == class_name: self.meta_row_type = 'DailySpells2' spell_ids = [] for meta_row in pc['Characters_meta']: if meta_row['Type'] == self.meta_row_type: spell_ids.append(meta_row['Entry_ID']) spells = [] for spell in spells_table: if spell['spell_id'] in spell_ids: for _ in range(spell_ids.count(spell['spell_id'])): spells.append(spell) self.set_subtitle('Choose Daily {} Spells'.format(class_name)) return {self.field_name: spells}
def get_choose_character(environ): if environ.get('REQUEST_METHOD', '') != 'POST': return '' raw_post = environ.get('wsgi.input', '') post = raw_post.read(int(environ.get('CONTENT_LENGTH', 0))) post_dict = parse_qs(post.decode(), True) character_id = post_dict.get('character_id', None) if character_id: character_id = character_id[0] pcs = environ['Extern'].get('PCs', []) for c in pcs: if c['unique_id'] == character_id: DbQuery.insertRow('WebApp', (environ['REMOTE_ADDR'], character_id)) DbQuery.commit() return get_character_html(c) return ''
def adjust_enemy_xp(dialog_return, fields, enemy_index): new_xp = dialog_return enemy = enemies[enemy_index] enemy['XP Value'] = new_xp serialized_enemies = json.dumps(enemies) DbQuery.update_cols('Encounters', 'unique_id', encounter_id, ('enemy_team', ), (serialized_enemies, )) DbQuery.commit() new_total = \ sum(fields[f] for f in fields if f.startswith('Current XP') and f != f'Current XP {enemy_index}')\ + new_xp return { f'Current XP {enemy_index}': new_xp, 'Total Label': f'<b>Total XP: </b>{new_total}', }
def get_available_classes( self ): if self.fields['STR']: attribute_dict = { attr : self.fields[attr] for attr in get_attribute_names() } else: attribute_dict = None class_dict_list = DbQuery.getTable( 'Classes' ) race = self.fields['Race'] all_normal_classes = [ ( cl['Name'], cl ) for cl in class_dict_list ] if not race and attribute_dict is None: return all_normal_classes class_option_list = [] for race_meta_dict in race['Races_meta']: if race_meta_dict['Type'] == 'class' and race_meta_dict['Subtype'] == 'permitted class options': class_options = race_meta_dict['Modified'] for class_option in class_options.split( ',' ): class_option = class_option.strip() if '/' in class_option: multiclass_dict = { 'unique_id' : class_option.replace( '/', '_' ), 'Name' : '', 'Primary_Spell_List' : [], 'classes' : [], } name_list = [] for cl in class_option.split( '/' ): class_record = self.find_class_record( cl, class_dict_list ) name_list.append( class_record['Name'] ) multiclass_dict['classes'].append( class_record ) if class_record['Primary_Spell_List'] != 'None' and SystemSettings.has_spells_at_level( 1, class_record ): multiclass_dict['Primary_Spell_List'].append( class_record['Primary_Spell_List'] ) multiclass_dict['Name'] = '/'.join( name_list ) option_tuple = ( multiclass_dict['Name'], multiclass_dict ) class_option_list.append( option_tuple ) else: class_record = self.find_class_record( class_option, class_dict_list ) option_tuple = ( class_record['Name'], class_record ) class_option_list.append( option_tuple ) if not class_option_list: class_option_list = all_normal_classes allowed_list = [] if attribute_dict is not None: attribute_dict = {k.lower():int(v) for k, v in attribute_dict.items()} allowed_normal_classes = [ normal_class['Name'] for normal_class in class_dict_list if self.class_allowed( normal_class, attribute_dict ) ] for class_option in class_option_list: class_option_allowed = True for class_option_item in class_option[0].split('/'): class_option_item = class_option_item.strip() if class_option_item not in allowed_normal_classes: class_option_allowed = False if class_option_allowed: allowed_list.append( class_option ) return allowed_list
def get_existing_character(_environ, character_id): # pcs = environ['Extern']['PCs'] pcs = DbQuery.getTable('Characters') pcs_indexed = {pc['unique_id']: pc for pc in pcs} # for c in pcs: # if c['unique_id'] == character_id: # # return SystemSettings.get_character_pdf_markup(c)[1] # return get_character_html(c) return get_character_html(pcs_indexed[character_id])
def fill_list( self ): spells_dict_list = DbQuery.getTable( 'Spells' ) self.wizard_type = self.pages['ChooseClassPage'].wizard_type spell_list = [] for spell_dict in spells_dict_list: if spell_dict['Type'] == self.wizard_type and spell_dict['Level'] == 1: spell_tuple = ( spell_dict['Name'], spell_dict ) spell_list.append( spell_tuple ) return spell_list
def fill_list(self): spells_dict_list = DbQuery.getTable('Spells') self.wizard_type = self.pages['ChooseClassPage'].wizard_type spell_list = [] for spell_dict in spells_dict_list: if spell_dict['Type'] == self.wizard_type and spell_dict[ 'Level'] == 1: spell_tuple = (spell_dict['Name'], spell_dict) spell_list.append(spell_tuple) return spell_list
def fill_list( self ): class_dict = self.fields['Class'] items_dict_list = DbQuery.getTable( 'Items' ) item_list = [] for item_dict in items_dict_list: if item_dict['Cost'].lower() != 'not sold' and not item_dict['Cost'].lower().startswith( 'proficiency' ): item_tuple = ( item_dict['Name'] + ' - ' + item_dict['Cost'], item_dict ) item_list.append( item_tuple ) return item_list
def save_character_hp(char_id, new_hp): meta_indexed = get_meta_indexed(pcs_indexed[char_id]) cur_hp_meta_row = meta_indexed.get('Current HP', None) if cur_hp_meta_row is None: cur_hp_insert_row = (char_id, 'Current HP', None, new_hp, None) DbQuery.insertRow('Characters_meta', cur_hp_insert_row) DbQuery.commit() else: DbQuery.update_cols('Characters_meta', 'character_id', char_id, ('Data', ), (new_hp, ), 'Type', 'Current HP') DbQuery.commit()
def initialize_page( self, fields, pages, external_data ): spells_table = DbQuery.getTable( 'Spells' ) pc = external_data['Character List Current'] spellbook_ids = [] for meta_row in pc['Characters_meta']: if meta_row['Type'] == 'Spellbook': spellbook_ids.append( meta_row['Entry_ID'] ) spellbook = [] for spell in spells_table: if spell['spell_id'] in spellbook_ids: spellbook.append( spell ) return { 'Spellbook': spellbook }
def __init__( self ): super( ProficiencyPage, self ).__init__( 4, 'Proficiencies' ) self.set_subtitle( 'Choose available proficiencies' ) self.proficiency_table = [ row for row in DbQuery.getTable( 'Items' ) if row['Is_Proficiency'].lower() == "yes" ] self.class_table = DbQuery.getTable( 'Classes' ) self.race_table = DbQuery.getTable( 'Races' ) self.slots_remaining = 0 prof_data = { 'fill_avail': self.fill_proficiencies, 'slots': self.get_proficiency_slots, 'slots_name': 'Proficiency', 'category_field': 'Damage_Type', 'tool_tip': self.get_tool_tip, 'add': self.add_proficiency, 'remove': self.remove_proficiency, } proficiencies = Widget( 'Proficiencies', 'DualList', data=prof_data ) self.add_row( [ proficiencies, ] )
def report_existence_check(): """ Метод проверяет существование таблицы с отчетом за текущий месяц. """ query = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='" + bot_config.report_name + "'" dbq = DbQuery.Query(query) check_exists = dbq.db_query_wrt() for row in check_exists: if len(row) > 0: return True else: return False
def fill_list(self): class_dict = self.fields['Class'] items_dict_list = DbQuery.getTable('Items') item_list = [] for item_dict in items_dict_list: if item_dict['Cost'].lower() != 'not sold' and not item_dict[ 'Cost'].lower().startswith('proficiency'): item_tuple = (item_dict['Name'] + ' - ' + item_dict['Cost'], item_dict) item_list.append(item_tuple) return item_list
def initialize_page(self, fields, pages, external_data): self.spell_slots = '1' spells_table = DbQuery.getTable('Spells') pc = external_data['Character List Current'] spellbook_ids = [] for meta_row in pc['Characters_meta']: if meta_row['Type'] == 'Spellbook': spellbook_ids.append(meta_row['Entry_ID']) spellbook = [] for spell in spells_table: if spell['spell_id'] in spellbook_ids: spellbook.append(spell) return {'Spellbook': spellbook}
def __init__(self, encounter_id): super().__init__(title='XP Breakdown') encounters = DbQuery.getTable('Encounters') encounters_indexed = {e['unique_id']: e for e in encounters} enemies_serialized = encounters_indexed[encounter_id]['enemy_team'] enemies = json.loads(enemies_serialized) def adjust_enemy_xp(dialog_return, fields, enemy_index): new_xp = dialog_return enemy = enemies[enemy_index] enemy['XP Value'] = new_xp serialized_enemies = json.dumps(enemies) DbQuery.update_cols('Encounters', 'unique_id', encounter_id, ('enemy_team', ), (serialized_enemies, )) DbQuery.commit() new_total = \ sum(fields[f] for f in fields if f.startswith('Current XP') and f != f'Current XP {enemy_index}')\ + new_xp return { f'Current XP {enemy_index}': new_xp, 'Total Label': f'<b>Total XP: </b>{new_total}', } # Define Widgets total_xp = 0 for i, e in enumerate(enemies): xp_value = e['XP Value'] if type(e['XP Value']) is int else 0 total_xp += xp_value n = Widget('Name', 'TextLabel', data=f'''<b>{e['Name']}</b>''') w = Widget(f'Current XP {i}_', 'SpinBox', enable_edit=False, data=xp_value) b = Widget(f'Adjust XP {i}', 'PushButton', data='Adjust XP') # Add Action self.add_action( Action('EntryDialog', b, w, callback=callback_factory_2param(adjust_enemy_xp, i))) # Initialize GUI self.add_row([n, w, b]) total_label = Widget('Total Label', 'TextLabel', data=f'<b>Total XP: </b>{total_xp}', col_span=3) self.add_row([total_label])
def turn_off(self, command): """ Метод изменения статуса команды на ВЫКЛ. :param command: Строка с командой(идет в качестве аргумента к основной команде). :type command: str """ if self.access_check(): query = "UPDATE public.command SET turn = false WHERE command = '" + command + "'" dbq = DbQuery.Query(query) dbq.db_query_nrt() return 'Команда успешно выключена' else: return bot_config.error_access_denied
def show_exam(): """ Метод, выводящий список аттестаций из БД. """ exam_list = 'Список экзаменов/зачетов: \n' query = "SELECT discipline, type_of_exam, date_exam FROM public.exam" dbq = DbQuery.Query(query) show = dbq.db_query_wrt() for row in show: exam_name = str(row[0]) exam_type = str(row[1]) exam_date = str(row[2]) exam_list = exam_list + exam_name + '(' + exam_type + '): ' + exam_date + '\n' return exam_list
def fill_list( self ): spells_dict_list = DbQuery.getTable( 'Spells' ) spell_list = [] if self.pages['SpellsPage'].multi_next_spell_type == self.pages['ChooseClassPage'].wizard_type: for spell_dict in self.fields['SpellbookList']: spell_tuple = (spell_dict['Name'], spell_dict) spell_list.append( spell_tuple ) else: for spell_dict in spells_dict_list: if spell_dict['Type'] == self.pages['SpellsPage'].multi_next_spell_type and spell_dict['Level'] == 1: spell_tuple = (spell_dict['Name'], spell_dict) spell_list.append( spell_tuple ) return spell_list
def fill_items(_owned_items, _fields): items = [ item for item in DbQuery.getTable('Items') if not item['Cost'].lower().startswith('proficiency') ] # These two lines sort the list to guarantee the tab order category_order = { 'General': 0, 'Weapon': 1, 'Armour': 2, 'Clothing': 3 } items.sort(key=lambda x: category_order.get( x.get('Category', 'General'), 4)) return items
def initialize_page(self, fields, pages, external_data): pc = external_data['Character List Current'] classes = pc['Classes'].split('/') level = str(pc['Level']).split('/') self.ready_list = ready_to_level_up(pc) self.ready_dict_list = [cl for cl in DbQuery.getTable('Classes') if cl['unique_id'] in self.ready_list] self.wizard_category = False self.other_spellcaster_category = False self.other_spellcaster_category2 = False self.proficiency_slots_available = 0 self.spell_classes = 0 for cl in self.ready_dict_list: wpa = cl['Weapon_Proficiency_Advancement'].split('/') slots = int(wpa[0]) per_level = int(wpa[1]) pc_level = int(level[classes.index(cl['unique_id'])]) # self.proficiency_slots_available = 2 if pc_level % per_level == 0: self.proficiency_slots_available = slots has_spells = SystemSettings.has_spells_at_level(pc_level + 1, cl) if cl['Category'] == 'wizard' and has_spells: self.wizard_category = cl self.spell_classes += 1 elif cl['Primary_Spell_List'] != 'None' and has_spells: if not self.other_spellcaster_category: self.other_spellcaster_category = cl else: self.other_spellcaster_category2 = cl self.spell_classes += 1 if self.wizard_category: self.next_page_id = pages['Spellbook'].get_page_id() elif self.other_spellcaster_category: self.next_page_id = pages['Daily Spells'].get_page_id() elif self.proficiency_slots_available: self.next_page_id = pages['Proficiencies'].get_page_id() elif self.ready_list: self.next_page_id = pages['Review'].get_page_id() else: self.next_page_id = -1 return { 'Intro Text': 'There are no classes ready to level up for this character!', 'Intro Text2': '' }
def fill_list(self): spells_dict_list = DbQuery.getTable('Spells') spell_list = [] if self.pages['SpellsPage'].multi_next_spell_type == self.pages[ 'ChooseClassPage'].wizard_type: for spell_dict in self.fields['SpellbookList']: spell_tuple = (spell_dict['Name'], spell_dict) spell_list.append(spell_tuple) else: for spell_dict in spells_dict_list: if spell_dict['Type'] == self.pages[ 'SpellsPage'].multi_next_spell_type and spell_dict[ 'Level'] == 1: spell_tuple = (spell_dict['Name'], spell_dict) spell_list.append(spell_tuple) return spell_list
def surname_check(surname): """ Метод проверяет наличие фамилии в таблице со студентами. :param surname: Поле с фамилией студента. :type surname: str """ query = "SELECT * FROM public.student WHERE surname='" + str( surname) + "'" dbq = DbQuery.Query(query) check_srn = dbq.db_query_wrt() for row in check_srn: if len(row) > 0: return True else: return False
def command_existence_check(self, command): """ Метод проверки существования команды в БД. :param command: Строка с командой. :type command: str """ query = "SELECT * FROM public.command WHERE command = '" + str( command) + "'" dbq = DbQuery.Query(query) check_exists = dbq.db_query_wrt() for row in check_exists: if len(row) > 0: return True, self else: return False, self
def __init__( self ): super( SpellbookPage, self ).__init__( 1, 'Spellbook' ) self.set_subtitle( 'Choose a spell to add to your spellbook' ) self.orig_spells = [] self.spell_slots = '1' self.spells_table = DbQuery.getTable( 'Spells' ) sb_data = { 'fill_avail': self.fill_spells, 'slots': self.get_spell_slots, 'slots_name': 'Spells', 'category_field': 'Level', 'tool_tip': self.get_tool_tip, 'add': self.add_spell, 'remove': self.remove_spell, } sb_list = Widget( 'Spellbook', 'DualList', align='Center', data=sb_data ) self.add_row( [ sb_list, ] )
def fill_list( self ): class_dict = self.fields['Class'] spells_dict_list = DbQuery.getTable( 'Spells' ) if 'classes' in class_dict: self.spell_types = class_dict['Primary_Spell_List'] if len(self.spell_types) > 1: self.multi_next_spell_type = self.spell_types[1] else: self.spell_types = [ class_dict['Primary_Spell_List'], ] spell_list = [] if self.spell_types[0] == self.pages['ChooseClassPage'].wizard_type: for spell_dict in self.fields['SpellbookList']: spell_tuple = ( spell_dict['Name'], spell_dict ) spell_list.append( spell_tuple ) else: for spell_dict in spells_dict_list: if spell_dict['Type'] == self.spell_types[0] and spell_dict['Level'] == 1: spell_tuple = ( spell_dict['Name'], spell_dict ) spell_list.append( spell_tuple ) return spell_list
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
def prefill_bought_list( self ): race_dict = self.fields['Race'] class_dict = self.fields['Class'] items_dict_list = DbQuery.getTable( 'Items' ) item_id_list = [] if race_dict['unique_id'] == 'elf' and 'fighter' in class_dict['unique_id']: percent = Dice.randomInt(1, 100) if percent <= 5: item_id_list.append( 'armour_elfin_chain' ) if 'magic_user' in class_dict['unique_id'] or 'illusionist' in class_dict['unique_id']: item_id_list.append( 'spellbook' ) if 'cleric' in class_dict['unique_id']: item_id_list.append( 'holy_symbol_pewter' ) if 'druid' in class_dict['unique_id']: item_id_list.append( 'holy_symbol_wooden' ) if 'thief' in class_dict['unique_id'] or 'assassin' in class_dict['unique_id']: item_id_list.append( 'thieves_tools' ) item_list = [] for item_dict in items_dict_list: if item_dict['unique_id'] in item_id_list: item_list.append( ( item_dict['Name'] + ' - ' + item_dict['Cost'], item_dict ) ) return item_list
def get_character_pdf_markup( character_dict ): class_table = DbQuery.getTable( 'Classes' ) race_table = DbQuery.getTable( 'Races' ) items_table = DbQuery.getTable( 'Items' ) spells_table = DbQuery.getTable( 'Spells' ) class_dict = { 'Name' : '', 'classes' : [] } classes_list = character_dict['Classes'].split( '/' ) for class_id in classes_list: for cl in class_table: if class_id == cl['unique_id']: if class_dict['Name'] == '': if len( classes_list ) == 1: class_dict = cl break class_dict['Name'] = cl['Name'] else: class_dict['Name'] += '/{}'.format( cl['Name'] ) class_dict['classes'].append(cl) level = character_dict['Level'] class_name = class_dict['Name'] class_font_size = '14px' class_padding = '0px' if len( class_name ) > 15: class_font_size = '8px' class_padding = '4px' for race in race_table: if race['unique_id'] == character_dict['Race']: race_dict = race portrait = character_dict['Portrait'] ext = character_dict['Portrait_Image_Type'] attr_dict = { 'STR' : character_dict['STR'], 'INT' : character_dict['INT'], 'WIS' : character_dict['WIS'], 'DEX' : character_dict['DEX'], 'CON' : character_dict['CON'], 'CHA' : character_dict['CHA'], } equip_id_list = [] spellbook_id_list = [] daily_spells_id_list = [] daily_spells2_id_list = [] proficiency_id_dict = {} for meta_row in character_dict['Characters_meta']: if meta_row['Type'] == 'Equipment': equip_id_list.append( meta_row['Entry_ID'] ) elif meta_row['Type'] == 'Treasure': if meta_row['Entry_ID'] == 'gp': gp = meta_row['Data'] elif meta_row['Entry_ID'] == 'pp': pp = meta_row['Data'] elif meta_row['Entry_ID'] == 'ep': ep = meta_row['Data'] elif meta_row['Entry_ID'] == 'sp': sp = meta_row['Data'] elif meta_row['Entry_ID'] == 'cp': cp = meta_row['Data'] elif meta_row['Type'] == 'Spellbook': spellbook_id_list.append( meta_row['Entry_ID'] ) elif meta_row['Type'] == 'DailySpells': daily_spells_id_list.append( meta_row['Entry_ID'] ) elif meta_row['Type'] == 'DailySpells2': daily_spells2_id_list.append( meta_row['Entry_ID'] ) elif meta_row['Type'] == 'Proficiency': proficiency_id_dict[ meta_row['Entry_ID'] ] = meta_row['Data'] proficiency_list = [] specialised_list = [] double_specialised_list = [] for prof in items_table: if prof['Is_Proficiency'].lower() == 'yes' and prof['unique_id'] in list( proficiency_id_dict.keys() ): prof_name = prof['Name'] prof_level = proficiency_id_dict[ prof['unique_id'] ] if prof_level == 'P': proficiency_list.append( prof ) elif prof_level == 'S': specialised_list.append( prof ) elif prof_level == '2XS': double_specialised_list.append( prof ) equipment_list = [] for equip in items_table: if equip['unique_id'] in equip_id_list: equipment_list.append( equip ) class_abilities = {} if 'classes' in class_dict: level_list = [ int(l) for l in level.split('/') ] for i, cl in enumerate( class_dict['classes'] ): class_abilities[ cl['Name'] ] = get_class_abilities( level_list[i], attr_dict, cl ) else: class_abilities[ class_dict['Name'] ] = get_class_abilities( level, attr_dict, class_dict ) race_abilities = get_race_abilities( race_dict ) spellbook = [] daily_spells = [] daily_spells2 = [] for spell in spells_table: if spell['spell_id'] in spellbook_id_list: spellbook.append( spell ) if spell['spell_id'] in daily_spells_id_list: daily_spells.append( spell ) if spell['spell_id'] in daily_spells2_id_list: daily_spells2.append( spell ) #print equipment_list saves_dict = get_saves( level, attr_dict, class_dict, race_dict ) movement_tuple = calculate_movement( race_dict, class_dict, attr_dict, equipment_list ) markup_template_dict = { 'class_font_size' : class_font_size, 'class_padding' : class_padding, 'name' : character_dict['Name'], 'gender' : character_dict['Gender'], 'class' : class_dict['Name'], 'alignment' : character_dict['Alignment'], 'race' : race_dict['Name'], 'xp' : character_dict['XP'], 'hp' : character_dict['HP'], 'ac' : calculate_ac( attr_dict, class_dict, race_dict, equipment_list ), 'level' : level, 'age' : character_dict['Age'], 'height': character_dict['Height'], 'weight': character_dict['Weight'], 'portrait': portrait, 'image_type': ext, 'tohit_row': '<td align=center>' + '</td><td align=center>'.join( get_tohit_row( level, class_dict, race_dict ) ) + '</td>', 'gp' : gp, 'pp' : pp, 'ep' : ep, 'sp' : sp, 'cp' : cp, 'movement_rate' : movement_tuple[0], 'movement_desc' : movement_tuple[1], 'nonproficiency_penalty' : get_non_proficiency_penalty( class_dict, race_dict ), } for attr_name in list( attr_dict.keys() ): markup_template_dict[attr_name] = attr_dict[attr_name] markup_template_dict[ attr_name + '_bonus' ] = get_attribute_bonus_string( attr_name, attr_dict[attr_name] ) for save in list( saves_dict.keys() ): markup_template_dict[save] = saves_dict[save] markup = '''\ <style type=text/css> .border { color: red; border-style: solid; border-color: purple; margin-right: 5px; } .bigger-font { font-size: 15px; } .smaller-font { font-size: 10px; } .pad-cell { padding-left: 5px; padding-right: 5px; } .pad-bottom { padding-bottom: 5px; } .pad-top-large { padding-top: 10px; } .pad-all { padding: 5px; } .no-pad { padding: 0px; } .lpad { padding-left: 15px; } .float-right { float: right; } .class-font { font-size: $class_font_size; padding-top: $class_padding; } .alignment-font { font-size: 10px; padding-top: 3px; } .attr-bonuses { font-size: 8px; vertical-align: middle; white-space: pre; } .tohit-table { border-style: solid; } .tohit-table > tr > td { padding: 2px; vertical-align: middle; } .equipment-table > tr > th { padding: 4px; align: center; font-size: 10px; } .equipment-table > tr > td { padding: 4px; align: center; font-size: 10px; } .equip-legend { font-size: 8px; } table.ability { font-size: 12px; } table.ability > tr > th { padding: 2px; } .pre { white-space: pre; } p.page-break { page-break-after:always; } </style> <h1 align=center>$name</h1> <table width=100%> <tr><td></td><td></td><td></td><td></td><td></td><td></td><td class=lpad align=center rowspan=5><img height=140 src=data:image;base64,$portrait /></td></tr> <tr><td class=pad-bottom><b>Name: </b></td><td align=right>$name</td><td class=lpad><b>XP: </b></td><td align=right>$xp</td><td class=lpad><b>Age: </b></td align=right><td align=right>$age</td></tr> <tr><td class=pad-bottom><b>Class: </b></td><td align=right class=class-font>$class</td><td class=lpad><b>HP: </b></td><td align=right>$hp</td><td class=lpad><b>Height: </b></td><td align=right>$height</td></tr> <tr><td class=pad-bottom><b>Alignment: </b></td><td align=right class=alignment-font>$alignment</td><td class=lpad><b>AC: </b></td><td align=right>$ac</td><td class=lpad><b>Weight: </b></td><td align=right>$weight</td></tr> <tr><td class=pad-bottom><b>Race: </b></td><td align=right>$race</td><td class=lpad><b>Level: </b></td><td align=right>$level</td><td class=lpad><b>Gender: </b></td><td align=right>$gender</td></tr> </table> <hr /> <table align=center><tr> <td> <table class='border bigger-font' border=2 ><tr><td> <table class=pad-cell> <tr><td align=right class=pad-cell>Str:</td><td align=right class=pad-cell>$STR</td><td class=attr-bonuses> $STR_bonus </td></tr> <tr><td align=right class=pad-cell>Int:</td><td align=right class=pad-cell>$INT</td><td class=attr-bonuses> $INT_bonus </td></tr> <tr><td align=right class=pad-cell>Wis:</td><td align=right class=pad-cell>$WIS</td><td class=attr-bonuses> $WIS_bonus </td></tr> <tr><td align=right class=pad-cell>Dex:</td><td align=right class=pad-cell>$DEX</td><td class=attr-bonuses> $DEX_bonus </td></tr> <tr><td align=right class=pad-cell>Con:</td><td align=right class=pad-cell>$CON</td><td class=attr-bonuses> $CON_bonus </td></tr> <tr><td align=right class=pad-cell>Cha:</td><td align=right class=pad-cell>$CHA</td><td class=attr-bonuses> $CHA_bonus </td></tr> </table> </td></tr></table> </td> <td> <table class=smaller-font align=center border=1> <tr><td colspan=2><h3 align=center>Saving Throws</h3></td></tr> <tr><td class=pad-cell>Aimed Magic Items</td><td class=pad-cell align=right>$Aimed_Magic_Items </td></tr> <tr><td class=pad-cell>Breath Weapon</td><td class=pad-cell align=right>$Breath_Weapons </td></tr> <tr><td class=pad-cell>Death, Paralysis, Poison</td><td class=pad-cell align=right>$Death_Paralysis_Poison </td></tr> <tr><td class=pad-cell>Petrifaction, Polymorph</td><td class=pad-cell align=right>$Petrifaction_Polymorph </td></tr> <tr><td class=pad-cell>Spells</td><td class=pad-cell align=right>$Spells </td></tr> </tr></table> </td> </tr></table> <hr /> <table class=tohit-table border=1 align=center> <tr><td><b>Enemy AC</b></td><td align=center> -10 </td><td align=center> -9 </td><td align=center> -8 </td><td align=center> -7 </td><td align=center> -6 </td><td align=center> -5 </td> <td align=center> -4 </td><td align=center> -3 </td><td align=center> -2 </td><td align=center> -1 </td><td align=center> 0 </td><td align=center> 1 </td> <td align=center> 2 </td><td align=center> 3 </td><td align=center> 4 </td><td align=center> 5 </td><td align=center> 6 </td><td align=center> 7 </td> <td align=center> 8 </td><td align=center> 9 </td><td align=center> 10 </td></tr> <tr><td><b>To Hit</b></td>$tohit_row</tr> </table> <hr /> <div class=pre align=center>GP: $gp PP: $pp EP: $ep SP: $sp CP: $cp</div> <hr /> <table align=center> <tr><th><h4>Equipment</h4></th></tr> <tr><td><table border=1 class=equipment-table> <tr><th>Name</th><th>Damage Vs S or M</th><th>Damage Vs L</th><th>Damage Type</th><th>RoF</th><th>Range</th><th>Max Move</th><th>AC Effect</th><th>Notes</th></tr> ''' # proficiency_page = self.pages['ProficiencyPage'] # specialised_list = proficiency_page.specialised_list # double_specialised_list = proficiency_page.double_specialised_list for equip in equipment_list: equip_name = equip['Name'] if equip in double_specialised_list: equip_name = equip_name + '<sup>‡</sup>' elif equip in specialised_list: equip_name = equip_name + '<sup>†</sup>' elif equip in proficiency_list: equip_name = equip_name + '*' equip_list = [ equip_name, equip['Damage_Vs_S_or_M'], equip['Damage_Vs_L'], equip['Damage_Type'], equip['Rate_of_Fire'], equip['Range'], equip['Max_Move_Rate'], str( equip['AC_Effect'] ), equip['Notes'] ] markup += '<tr><td align=center>' + '</td><td align=center>'.join( equip_list ) + '</td></tr>' markup += ''' </table></td></tr></table> <div align=center class="equip-legend pre">*=Proficient †=Specialised ‡=Double Specialised</div> <div><b>Movement Rate: </b>$movement_rate ft/round<br /> <b>Surprise: </b>$movement_desc<br /> <b>Non-Proficiency Penalty: </b>$nonproficiency_penalty</div> <p class=page-break></p> <h2>Ablities</h2> ''' if class_abilities: for cl in list( class_abilities.keys() ): markup += '\n<h5>{} Abilities</h5>\n'.format( cl ) for i, a in enumerate( class_abilities[cl] ): if a[0]: if i > 0: markup += '<br />' markup += '<b>{}: </b>{}\n'.format( *a ) else: markup += '<table class=ability align=center border=1>\n<tr>' for h in a[1][0]: markup += '<th align=center>{}</th>'.format(h) markup += '</tr>\n<tr>' for d in a[1][1]: markup += '<td align=center>{}</td>'.format(d) markup += '</tr>\n</table>\n' if race_abilities: markup += '\n<h5>{} Abilites</h5>\n'.format( race_dict['Name'] ) markup += '<ul>\n' for a in race_abilities: markup += '<li>' markup += a[0] if a[1]: markup += ' {}'.format( a[1] ) if a[2]: markup += ' {}'.format( a[2] ) markup += '</li>\n' markup += '</ul>\n' spellcaster = False if 'classes' in class_dict: level_list = [ int(l) for l in level.split( '/' ) ] for i, cl in enumerate( class_dict['classes'] ): if has_spells_at_level( level_list[i], cl ): spellcaster = True else: if has_spells_at_level( level, class_dict ): spellcaster = True if spellcaster: spell_item_string = ''' <h3>{Name}</h3> <b>Reversible: </b>{Reversible}<br/> <b>Level: </b>{Level}<br /> <b>Damage: </b>{Damage}<br /> <b>Range: </b>{Range}<br /> <b>Duration: </b>{Duration}<br /> <b>Area of Effect: </b>{Area_of_Effect}<br /> <b>Components: </b>{Components}<br /> <b>Casting Time: </b>{Casting_Time}<br /> <b>Saving Throw: </b>{Saving_Throw}<br /> <b>Description: </b><span class=pre>{Description}</span><br /><br /> ''' markup += '<p class=page-break></p>\n<h2>Spells</h2>\n' if spellbook: markup += '<h5>Spellbook</h5>\n<hr />' for spell in spellbook: markup += spell_item_string.format( **spell ) markup += '<hr />\n' if daily_spells: markup += '<h5>{} Daily Spells</h5>\n<hr />'.format( daily_spells[0]['Type'].title().replace( '_', ' ' ) ) for spell in daily_spells: markup += spell_item_string.format( **spell ) markup += '<hr />\n' if daily_spells2: markup += '<h5>{} Daily Spells</h5>\n<hr />'.format( daily_spells2[0]['Type'].title().replace( '_', ' ' ) ) for spell in daily_spells2: markup += spell_item_string.format( **spell ) markup += '<hr />\n' t = Template(markup) final_markup = t.safe_substitute( markup_template_dict ) return ( '{}.pdf'.format( character_dict['Name'] ), final_markup )
def prefill_chosen_spells( self ): spells_dict_list = DbQuery.getTable( 'Spells' ) return prefill_chosen_spells( self.wizard_type, spells_dict_list )