Exemplo n.º 1
0
 def level_up(self,num_levels,stat_array=None,increase_level=True,increase_stats=True):
     max_level=max_level_dict(self.game,self.current_class())
     if type(num_levels) == str:
         if num_levels.isnumeric():
             num_levels=int(num_levels)
             num_levels=num_levels-self.current_level()
         elif num_levels == 'max':
             num_levels=max_level-self.current_level()
         elif num_levels == 'promo':
             assert self.can_promote()
             mpl=self.min_promo_level(promo_path=0)
             if mpl <= self.current_level():
                 return
             else:
                 num_levels=mpl-self.current_level()
         else:
             message='\'num_levels\' must be numeric, \'max\', or \'promo\', if it is a string.'
             messageWriter(message)
     else:
         assert type(num_levels) == int
     if num_levels == 0:
         return
     else:
         assert num_levels >= 0
     if increase_level:
         assert self.current_level()+num_levels <= max_level
     if stat_array is None:
         stat_array=self.growth_rates
     if increase_level:
         index=self.current_index()
         self.my_levels[index]+=num_levels
     if increase_stats:
         self.my_stats=self.my_stats+stat_array*num_levels/100
     return self.cap_stats()
Exemplo n.º 2
0
 def equip_scroll(self,scroll_name=None):
     assert self.game == '5'
     assert len(self.unit_info['Scrolls']) <= 7
     scrolls=scroll_equipper()
     scrolls.columns=self.stat_names
     scroll_name=crusader_name(scroll_name)
     if scroll_name is None:
         for name in self.unit_info['Scrolls']:
             scrolls.drop(name,inplace=True)
         scrolls=scrolls.to_string()
         print(scrolls)
         return
     elif scroll_name in self.unit_info['Scrolls']:
         message='You already have the %s scroll equipped.'%scroll_name
         messageWriter(message)
     self.unit_info['Scrolls'].append(scroll_name)
     raw_growths=array(self.unit_info['Base Growths'])
     for name in self.unit_info['Scrolls']:
         augment=scrolls.loc[name].to_numpy()
         raw_growths=raw_growths+augment
     capped_growths=list()
     for g in raw_growths:
         if g < 0:
             g=0
         capped_growths.append(g)
     self.growth_rates=array(capped_growths)
Exemplo n.º 3
0
 def __init__(self, program_name, use_nickname=False):
     pdict = program_dict
     if program_name in pdict.keys():
         self.episode_list = pdict[program_name]
     else:
         program_file = sep.join(('.', 'metadata', 'my-programs.csv'))
         message=(
             'The program: ``%s\'\' is not in the list of known television programs. A complete list can be found in:\n'%program_name,\
             program_file
             )
         messageWriter(message)
     self.folder_title = titleExtractor(self.episode_list, True)
     if not use_nickname:
         self.display_title = titleExtractor(self.episode_list, False)
     else:
         self.display_title = program_name
     self.main_dirs = list()
     self.data_dirs = list()
     for name in ('tables', 'text'):
         name = sep.join(['.', name])
         self.main_dirs.append(name)
         name = sep.join([name, self.folder_title])
         self.data_dirs.append(name)
     self.table_dir = self.data_dirs[0]
     self.text_dir = self.data_dirs[1]
     self.output_dir = sep.join(('.', 'output'))
     self.metadata = sep.join(('.', 'metadata'))
     self.log = sep.join((self.metadata, 'unicode-dict.csv'))
Exemplo n.º 4
0
 def writeText(self, column):
     save_file = column + '.txt'
     save_file = self.outputFile(save_file)
     missing_columns = dict()
     with open(save_file, 'w', encoding='utf-8') as wfile:
         for x, y, files in walk(self.table_dir):
             files = filelistOrganizer(files)
             for file in files:
                 file = self.table_dir, file
                 file = sep.join(file)
                 data = pd.read_csv(file, index_col=0)
                 if column not in data.columns:
                     if file in missing_columns.keys():
                         missing_columns[file].append(column)
                     else:
                         missing_columns[file] = [column]
                     continue
                 for n, text in enumerate(data.loc[:, column], 1):
                     text = str(text)
                     text = replace_reserved_chars(text, self.metadata)
                     if not text.isascii():
                         self.logUnicodeText(text)
                     text = text.replace('\n', '\\par ')
                     text = text + '\n'
                     wfile.write(text)
     if missing_columns:
         for key, val in missing_columns.items():
             print(key, val)
         message = (
             'There were columns missing from some episode-tables. Please check the files listed above for more details.'
         )
         messageWriter(message)
Exemplo n.º 5
0
 def scoldUserAgain(self):
     scold = False
     for x, y, hasfiles in walk(self.text_dir):
         if not hasfiles:
             scold = True
     if scold:
         message = (
             'Text has not been scraped for %s. Please compile text with the compileText method.'
             % self.display_title)
         messageWriter(message)
Exemplo n.º 6
0
 def writeAllText(self):
     columns = 'title', 'date', 'summary'
     initial_count = lineCounter(self.log)
     for column in columns:
         self.writeText(column)
     final_count = lineCounter(self.log)
     diff = final_count - initial_count
     if diff > 0:
         message = (
             '%d new unicode character(s) have been encountered. Please revise the appropriate log accordingly: %s. For each character, write its TeX equivalent.'
             % (diff, self.log))
         messageWriter(message)
Exemplo n.º 7
0
 def scoldUser(self):
     scold = False
     if not exists(self.table_dir):
         scold = True
     else:
         for x, y, hasfiles in walk(self.table_dir):
             if not hasfiles:
                 scold = True
     if scold:
         message = (
             'No data has yet been scraped for %s. Please web-scrape the data first, then re-run the script. Try running the webScrape method.'
             % self.display_title)
         messageWriter(message)
Exemplo n.º 8
0
 def checkDates(self):
     file = self.outputFile(r'tex-date.txt')
     bad_lines = dict()
     with open(file) as rfile:
         for n, line in enumerate(rfile.readlines(), start=1):
             line = line.strip()
             if not dateValidator(line):
                 bad_lines[n] = line
     if bad_lines:
         for item in bad_lines.items():
             print(item)
         message=(
             'There were still some bad dates in tex-date.txt. Please fix the errors in the lines whose numbers are given above. Remember that the date must be of the form: (month) (day), (full-year). For example:\n',\
             todaysDate()
             )
         messageWriter(message)
Exemplo n.º 9
0
 def typeset(self):
     self.scoldUser()
     self.scoldUserAgain()
     self.recordProgramName()
     guide_loc = sep.join(('.', 'output'))
     pwd = getcwd()
     chdir(guide_loc)
     guide = 'guide.tex'
     system("pdflatex %s" % guide)
     src = guide[:-3] + 'pdf'
     if not exists(src):
         message = (
             'The .pdf file was not successfully compiled. Please e-mail the imbecile what wrote this program. Better yet, fix it yourself.'
         )
         messageWriter(message)
     system("pdflatex %s" % guide)
     chdir(pwd)
     message = 'Your .pdf file has been saved to:\n', sep.join(
         (guide_loc, src))
     messageWriter(message, error=False)
Exemplo n.º 10
0
 def fixDates(self):
     file = self.outputFile('date.txt')
     tex_file = self.outputFile('tex-date.txt')
     if exists(tex_file):
         message = (
             'The file containing the air-dates already exists. It is not recommended to overwrite it, if you\'ve edited it. In order to rewrite the file, please rerun the program after deleting: %s. To validate your manual corrections to the file, use the checkDates method.'
             % tex_file)
         messageWriter(message)
     old_dates = list()
     with open(file, 'r') as rfile:
         for line in rfile.readlines():
             line = line.strip()
             old_dates.append(line)
     bad_dates = monthRewriter(tex_file, old_dates)
     if bad_dates:
         for key, val in bad_dates.items():
             print(key, val)
         message = (
             'There were some bad dates in tex-date.txt. The errors and their line numbers are listed above. Please correct the errors shown above to proceed. Check your work with the checkDates method afterwards.'
         )
         messageWriter(message)
Exemplo n.º 11
0
def get_true_name(game, unit, fe4family=None):
    if fe4family is not None:
        my_dict = fe4_name_dict(fe4family)
        message=(
            '%s is not a father with a choice of brides.'%unit,\
            'Please check the \'fe_unit_list\' function for a list of valid options.',\
            'Be sure to pass \'fe4_fathers\' as the argument.'
            )
    else:
        my_dict = unit_name_dict(game)
        game_title = game_title_dict(reverse=True)[game]
        message=(
            '%s is not in FE%s: %s.'%(unit,game,game_title),\
            'Please check the \'fe_unit_list\' function for a list of valid names.'
            )
    if unit in my_dict.keys():
        return my_dict[unit]
    elif unit in my_dict.values():
        return unit
    else:
        messageWriter(message)
Exemplo n.º 12
0
 def __init__(self,game,unit,lyn_mode=None,father=None):
     assert type(game) in (str,int)
     if type(game) == int:
         game=str(game)
     assert game in (str(n) for n in range(4,10))
     if unit != 'L\'Arachel':
         unit=unit.capitalize()
     if game == '4':
         kids=fe4_name_dict('child')
         if unit in kids.keys() or unit in kids.values():
             father=str(father)
             father=father.capitalize()
             father=get_true_name(game,father,fe4family='father')
     if game == '7':
         lyndis_league=character_list(game,file_match='characters_base-stats1')
         if unit in lyndis_league:
             if lyn_mode is None:
                 message='Please choose a Boolean value for the \'lyn_mode\' option.'
                 messageWriter(message)
         else:
             lyn_mode=None
     if (game,unit) == ('7','Nils'):
         unit='Ninian'
     unit=get_true_name(game,unit)
     kwargs={
         'game':game,\
         'unit':unit,\
         'father':father,\
         'lyn_mode':lyn_mode
         }
     self.kwargs=kwargs.copy()
     self.unit_info=load_unit_info(**kwargs)
     self.game=self.unit_info.pop('Game')
     self.unit=self.unit_info.pop('Name')
     self.base_class=self.unit_info.pop('Class')
     self.base_level=self.unit_info.pop('Level')
     self.base_stats=load_character_bases(**kwargs).to_numpy()
     self.growth_rates=load_character_growths(**kwargs).to_numpy()
     d={}
     d['audit']='bases'
     d['class_name']=self.base_class
     kwargs.update(d)
     self.maximum_stats=load_class_maxes(**kwargs).to_numpy()
     self.promotions=load_class_promo_list(**kwargs)
     if self.promotions is not None:
         self.my_levels=[self.base_level,None]
         self.my_promotions=self.promotions.copy()
         self.my_classes=[self.base_class,None]
     else:
         self.my_levels=[None,self.base_level]
         self.my_promotions=None
         self.my_classes=[None,self.base_class]
     self.base_levels=self.my_levels.copy()
     self.base_classes=self.my_classes.copy()
     self.my_maxes=self.maximum_stats.copy()
     self.my_stats=array(self.base_stats,dtype='float64')
     if self.game == '5':
         self.unit_info['Base Growths']=self.growth_rates.copy()
         self.unit_info['Scrolls']=list()
         dd=DismountData()
         self.unit_info['Mounted']=dd.isMounted(self.base_class)
     self.stat_names=get_stat_names(self.game)
     self.unit_info['Growths Modifier']=None
     if self.game in ('4','5'):
         self.cutoff=None
     elif self.game == '9':
         self.cutoff=3
     else:
         self.cutoff=2