From 52fde623efda05b76a8bd445c69848711393c9ab Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 6 Jul 2012 22:02:02 -0400 Subject: [PATCH] Added code to represent minions, and to kill multiple minions with one command. --- battleman.py | 10 ++++++++++ lib/battle.py | 25 +++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/battleman.py b/battleman.py index 55fc6d3..71e50b3 100755 --- a/battleman.py +++ b/battleman.py @@ -205,6 +205,16 @@ class CommandParser(Cmd): c.damage(amount) + def do_minionkill(self, line): + """damage [index list] + Deals 1 damage to each of the specified combatants. Used to indicate minion death""" + + data = parse_data(line) + + for index in data: + self.btl.get_combatant(int(index)).damage(1) + + def do_heal(self, line): """heal [index] [amount] Heal hit points for the specified combatant""" diff --git a/lib/battle.py b/lib/battle.py index 6568265..6f24ac4 100644 --- a/lib/battle.py +++ b/lib/battle.py @@ -384,12 +384,13 @@ class CombatGroup(): class Combatant(): next_index = 0 - def __init__(self, name, hp, pc=False, init_mod=0, surges=0, ap=0, sw=0, recharges=[]): + def __init__(self, name, hp, pc=False, init_mod=0, surges=0, ap=0, sw=0, recharges=[], minion=False): self.name = name self.max_hp = hp self.hp = self.max_hp self.temp_hp = 0 self.pc = pc + self.minion = minion self.surges = surges self.ap = ap self.sw = sw @@ -517,7 +518,8 @@ class Combatant(): self.hp -= amount - print '{} took {} points of damage.'.format(self, amount) + if not self.minion: + print '{} took {} points of damage.'.format(self, amount) if self.is_down(): print '{} is down!'.format(self) @@ -655,7 +657,12 @@ recharge powers: 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.values()])) + if self.minion: + hp_s = 'minion' + else: + hp_s = '{} hp'.format(self.hp) + + return hp_s + temp_info + bloodied + ', '.join([x['name'] for x in self.conditions.values()]) def format_condition_summary(self, initial=''): @@ -754,9 +761,9 @@ def _build_group_from_file_data(data): else: gname = data['name'] + minion = bool(data['minion']) count = int(data['count']) - members = {} for i in range(count): if count > 1: @@ -765,13 +772,19 @@ def _build_group_from_file_data(data): name = data['name'] c = Combatant(name, int(data['hp']), data['pc'], int(data['init']), int(data['surges']), - int(data['ap']), int(data['sw']), data['recharges']) + int(data['ap']), int(data['sw']), data['recharges'], data['minion']) members[c.index] = c return CombatGroup(gname, members, int(data['init'])) def _validate_group_data(data): + if not 'hp' in data: + data['hp'] = 1 + + if not 'minion' in data: + data['minion'] = False + if not 'pc' in data: data['pc'] = False @@ -795,4 +808,4 @@ def _validate_group_data(data): else: data['sw'] = 0 - return 'name' in data and 'hp' in data + return 'name' in data