diff --git a/battleman.py b/battleman.py index f0e59c1..b4d7131 100755 --- a/battleman.py +++ b/battleman.py @@ -11,6 +11,7 @@ # for resuming a battle later # * an option for passing in multiple files that contain combatant definitions # * down combatants go into a separate list +# * implement temporary hit points! from dice import Dice import sys @@ -97,6 +98,7 @@ class Combatant(): self.name = name self.max_hp = hp self.hp = self.max_hp + self.temp_hp = 0 self.pc = pc self.surges = surges self.ap = ap @@ -121,6 +123,12 @@ class Combatant(): def damage(self, amount): was_bloodied = self.is_bloodied() + if self.temp_hp > 0: + self.temp_hp -= amount + if self.temp_hp < 0: + amount = abs(self.temp_hp) + self.temp_hp = 0 + self.hp -= amount if self.is_down(): @@ -129,6 +137,23 @@ class Combatant(): print('{} ({}) is bloodied! Remaining hp: {}'.format(self.name, self.index, self.hp)) + def heal(self, amount): + was_down = self.is_down() + was_bloodied = self.is_bloodied() + + if self.hp < 0: + self.hp = 0 + + self.hp = min(self.hp + amount, self.max_hp + self.temp_hp) + + if was_down: + print('{} ({}) is conscious.'.format(self.name, self.index)) + if was_bloodied and not self.is_bloodied(): + print('{} ({}) is no longer bloodied.'.format(self.name, self.index)) + elif was_bloodied and self.is_bloodied(): + print('{} ({}) is still bloodied.'.format(self.name, self.index)) + + def is_bloodied(self): return self.hp <= self.max_hp / 2 @@ -223,13 +248,13 @@ class Battle(): self.groups.sort(reverse=True, key=lambda group: group.init) self.current = 0 - self.round = 1 print '\nInitiative Roster:\n' for g in self.groups: print '{} ({})'.format(g.name, g.init) print '' + self.next_round() self.get_current_group().begin_turn() @@ -293,6 +318,11 @@ class Battle(): c.damage(amount) + def heal_damage(self, index, amount): + c = self.combatant_hash[index] + c.heal(amount) + + def validate_started(self): if not self.is_started(): print('Error: you can only run this command after starting the battle') @@ -342,7 +372,7 @@ def do_prompt(): elif comm == 'd': do_damage() elif comm == 'h': - print('Sorry, this is still a stub function.') + do_heal() elif comm == 's': print('Sorry, this is still a stub function.') elif comm == 'c': @@ -364,6 +394,13 @@ def do_damage(): battle.deal_damage(index, amount) +def do_heal(): + print battle.list_combatants() + index = input_int('choose combatant') + amount = input_int('amount') + battle.heal_damage(index, amount) + + def do_help(): print("""Possible commands: ? - print this help menu (yay, you already figured that one out)