diff --git a/battleman.py b/battleman.py index 7c6454f..b26d405 100755 --- a/battleman.py +++ b/battleman.py @@ -90,6 +90,7 @@ class CombatGroup(): c.end_turn() + class Combatant(): next_index = 0 @@ -194,9 +195,13 @@ class Combatant(): print('{} is still bloodied.'.format(self)) + def add_temp_hp(self, amount): + self.temp_hp += amount + + def use_surge(self, heal=True): if self.surges <= 0: - print 'Error: {} has no healing surges.'.format(self.name) + print '{} has no healing surges.'.format(self) return self.surges -= 1 @@ -209,6 +214,20 @@ class Combatant(): self.heal(self.max_hp / 4) + def use_second_wind(self): + if self.sw <= 0: + print "{} doesn't have a second wind.".format(self) + return + + self.surges -= 1 + + print '{} got their second wind!'.format(self) + + # Now the actual effects of the SW + self.do_surge() + self.add_condition('Second Wind (+2 all def)', 't', 1) + + def is_bloodied(self): return self.hp <= self.max_hp / 2 @@ -242,26 +261,6 @@ class Combatant(): summary = summary + '{}: {} ({})\n'.format(index, c['name'], c['duration']) -def input_str(prompt, default=None, show_default=False, prompt_str=':'): - full_prompt = prompt - if default != None and show_default: - full_prompt = full_prompt + ' [{}]'.format(default) - full_prompt = full_prompt + '{} '.format(prompt_str) - - data = raw_input(full_prompt) - if not data: - if default == None: - print 'Error: you must provide a value!' - return input_str(prompt, default, show_default, prompt_str) - else: - return default - else: - return data - - -def input_int(prompt, default=None, show_default=True, prompt_str=':'): - return int(input_str(prompt, default, show_default)) - # data about the battle - includes combatant list, etc class Battle(): @@ -435,6 +434,10 @@ def do_prompt(): (comm, rdata) = input_str('', default='?', show_default=False, prompt_str='>').partition(' ')[::2] data = rdata.split(' ') + # To simplify our checks later + if data == ['']: + data = None + if comm == '?': do_help() elif comm == 'a': @@ -449,12 +452,14 @@ def do_prompt(): do_damage(data) elif comm == 'h': do_heal(data) + elif comm == 't': + do_add_temp_hp(data) elif comm == 's': do_surge(data) elif comm == 'so': do_surge(data, heal=False) elif comm == 'sw': - print('Sorry, this is still a stub function.') + do_second_wind(data) elif comm == 'c': do_add_condition(data) elif comm == 'r': @@ -470,11 +475,11 @@ def do_prompt(): def do_damage(data): if (data): if len(data) != 2: - print ('Error: wrong number of arguments') + print ('Error: wrong number of arguments.') c = battle.get_combatant(int(data[0])) if not c: - print ('Error: Invalid combatant index') + print ('Error: Invalid combatant index.') return amount = int(data[1]) @@ -492,7 +497,7 @@ def do_heal(data): c = battle.get_combatant(int(data[0])) if not c: - print ('Error: Invalid combatant index') + print ('Error: Invalid combatant index.') return amount = int(data[1]) @@ -503,14 +508,32 @@ def do_heal(data): c.heal(amount) -def do_surge(data, heal=True): +def do_add_temp_hp(data): if (data): - if len(data) != 1: + if len(data) != 2: print ('Error: wrong number of arguments') c = battle.get_combatant(int(data[0])) if not c: - print ('Error: Invalid combatant index') + print ('Error: Invalid combatant index.') + return + + amount = int(data[1]) + else: + c = battle.choose_combatant() + amount = input_int('amount') + + c.add_temp_hp(amount) + + +def do_surge(data, heal=True): + if (data): + if len(data) != 1: + print ('Error: wrong number of arguments.') + + c = battle.get_combatant(int(data[0])) + if not c: + print ('Error: Invalid combatant index.') return else: @@ -519,12 +542,28 @@ def do_surge(data, heal=True): c.use_surge(heal) +def do_second_wind(data): + if (data): + if len(data) != 1: + print ('Error: wrong number of arguments.') + + c = battle.get_combatant(int(data[0])) + if not c: + print ('Error: Invalid combatant index.') + return + + else: + c = battle.choose_combatant() + + c.use_second_wind() + + def do_add_condition(data): duration = None if data: if len(data) < 2 or (len(data) == 3 and data[2] == 't'): - print ('Error: wrong number of arguments') + print ('Error: wrong number of arguments.') c = battle.get_combatant(int(data[0])) name = data[1] @@ -555,10 +594,10 @@ l - list combatants p - print info for combatant/group with initiative d - deal damage to someone h - heal someone -t - add temporary hit points to someone [stub] +t - add temporary hit points s - use a healing surge so - use a healing surge, but don't regain hit points -sw - use your second wind (current combat group only) [stub] +sw - use a second wind c - apply a condition [stub] r - remove a condition (this can also happen automatically) [stub] n - next (end the current combat group's turn) @@ -566,5 +605,26 @@ w - wait (remove a combatant from the initiative order and into a separate pool q - quit""") +def input_str(prompt, default=None, show_default=False, prompt_str=':'): + full_prompt = prompt + if default != None and show_default: + full_prompt = full_prompt + ' [{}]'.format(default) + full_prompt = full_prompt + '{} '.format(prompt_str) + + data = raw_input(full_prompt) + if not data: + if default == None: + print 'Error: you must provide a value!' + return input_str(prompt, default, show_default, prompt_str) + else: + return default + else: + return data + + +def input_int(prompt, default=None, show_default=True, prompt_str=':'): + return int(input_str(prompt, default, show_default)) + + if __name__ == '__main__': main()