From 617c635206a377aa74b508ac52c6df5efd10d126 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 23 Mar 2012 12:14:00 -0400 Subject: [PATCH] battleman.py: Implemented healing surges, and refactored the combatant selection code in Battle --- battleman.py | 65 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/battleman.py b/battleman.py index 4ab8153..562b8d1 100755 --- a/battleman.py +++ b/battleman.py @@ -11,7 +11,11 @@ # 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! + +# dependencies: +# * second wind +# ** conditions + from dice import Dice import sys @@ -156,6 +160,17 @@ class Combatant(): print('{} ({}) is still bloodied.'.format(self.name, self.index)) + def use_surge(self, heal=True): + if self.surges <= 0: + print 'Error: {} has no healing surges'.format(self.name) + return + + self.surges -= 1 + print '{} spent a healing surge'.format(self) + if (heal): + self.heal(self.max_hp / 4) + + def is_bloodied(self): return self.hp <= self.max_hp / 2 @@ -242,6 +257,15 @@ class Battle(): return None + def choose_combatant(self): + print self.format_combatants() + index = input_int('choose combatant') + if index not in self.combatant_hash.keys(): + print 'Error: {} is not a valid index'.format(index) + return self.choose_combatant() + return self.combatant_hash[index] + + def begin(self): if self.is_started(): print("Error: battle is already running") @@ -319,16 +343,6 @@ class Battle(): print('Beginning round {}'.format(self.round)) - def deal_damage(self, index, amount): - c = self.combatant_hash[index] - 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') @@ -380,6 +394,10 @@ def do_prompt(): elif comm == 'h': do_heal() elif comm == 's': + do_surge() + elif comm == 'so': + do_surge(heal=False) + elif comm == 'sw': print('Sorry, this is still a stub function.') elif comm == 'c': print('Sorry, this is still a stub function.') @@ -394,17 +412,20 @@ def do_prompt(): def do_damage(): - print battle.format_combatants() - index = input_int('choose combatant') + c = battle.choose_combatant() amount = input_int('damage') - battle.deal_damage(index, amount) + c.damage(amount) def do_heal(): - print battle.format_combatants() - index = input_int('choose combatant') + c = battle.choose_combatant() amount = input_int('amount') - battle.heal_damage(index, amount) + c.heal(amount) + + +def do_surge(heal=True): + c = battle.choose_combatant() + c.use_surge(heal) def do_help(): @@ -415,12 +436,14 @@ b - begin the battle l - list combatants p - print info for combatant/group with initiative d - deal damage to someone -h - heal someone [stub] -s - let someone use a healing surge [stub] -sw - +h - heal someone +t - add temporary hit points to someone [stub] +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] c - apply a condition [stub] r - remove a condition (this can also happen automatically) [stub] -n - next (end the current combat group's turn) [stub] +n - next (end the current combat group's turn) w - wait (remove a combatant from the initiative order and into a separate pool) [stub] q - quit""")