diff --git a/battleman.py b/battleman.py index 7ee64b0..40573f9 100755 --- a/battleman.py +++ b/battleman.py @@ -108,20 +108,54 @@ class Combatant(): self.ap = ap self.sw = sw self.recharges = [] - self.conditions = [] + self.conditions = {} self.index = Combatant.next_index + self.next_condition_index = 0 Combatant.next_index += 1 - def add_condition(self, name, cond_type, duration): + def __str__(self): + return "{}: {} ({})".format(self.index, self.name, self.format_health_summary()) + + + # cond_type can be 's' or 't', for 'save' or 'timed'. If it is 't', condition expires at the end of the players turn + # 'duration' rounds from now + def add_condition(self, name, cond_type, duration=None): condition = {} condition['name'] = name + condition['cond_type'] = cond_type condition['duration'] = duration - self.conditions.append(condition) + if cond_type == 'timed' and duration == None: + print('Error: specified a timed condition with no duration.') + return + self.conditions[self.next_condition_index] = condition + self.next_condition_index += 1 def end_turn(self): - pass # fixme - need to do a lot of stuff with conditions here + for (index, c) in self.conditions.items(): + if c['cond_type'] == 's': + r = None + if self.pc: + print('{}: save against {}.'.format(self, c['name'])) + r = input_int('saving throw') + else: + save_die = Dice.from_str('1d20') + r = save_die.roll()['total'] + + if r >= 10: + cond = self.conditions.pop(index) + print('{} successfully saved against {}.'.format(self, cond['name'])) + else: + print('{} failed a save against {}.'.format(self, c['name'])) + + elif c['cond_type'] == 't': + c['duration'] -= 1 + if c['duration'] < 0: + cond = self.conditions.pop(index) + print('{} no longer affected by {}.'.format(self, cond['name'])) + + # fixme: still need to add recharges def damage(self, amount): @@ -199,11 +233,18 @@ class Combatant(): if self.temp_hp > 0: temp_info = ', {} temp hp'.format(self.temp_hp) - return '{} hp{}{}{}'.format(self.hp, temp_info, bloodied, ', '.join([x.name for x in self.conditions])) + return '{} hp{}{}{}'.format(self.hp, temp_info, bloodied, ', '.join([x['name'] for x in self.conditions.values()])) - def __str__(self): - return "{}: {} ({})".format(self.index, self.name, self.format_health_summary()) + def format_condition_summary(self): + summary = self.name + ':\n' + for (index, c) in conditions.items(): + type_string = '' + if c.cond_type == 's': + type_string = 'Save Ends' + elif c.cond_type == 't': + type_string = '{} Round{}'.format(c.duration, 's'[c.duration==1:]) + summary = summary + '{}: {} ({})\n'.format(index, c['name'], c['duration']) def input_str(prompt, default=None, show_default=False, prompt_str=':'): @@ -409,7 +450,7 @@ def do_prompt(): elif comm == 'sw': print('Sorry, this is still a stub function.') elif comm == 'c': - print('Sorry, this is still a stub function.') + do_add_condition() elif comm == 'r': print('Sorry, this is still a stub function.') elif comm == 'n': @@ -437,6 +478,17 @@ def do_surge(heal=True): c.use_surge(heal) +def do_add_condition(): + c = battle.choose_combatant() + name = input_str('condition name') + ctype = input_str('condition type', default='s', show_default=True) + duration=None + if ctype == 't': + duration = input_int('duration') + + c.add_condition(name, ctype, duration) + + def do_help(): print("""Possible commands: ? - print this help menu (yay, you already figured that one out)