From 7a0505fdf193d30dc910c8cf9f258f970b84790f Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 23 Mar 2012 21:46:53 -0400 Subject: [PATCH] battleman.py: Added ability to add groups on the fly --- battleman.py | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/battleman.py b/battleman.py index 4227ffc..89da090 100755 --- a/battleman.py +++ b/battleman.py @@ -25,16 +25,16 @@ class CombatGroup(): # the group @classmethod def from_input(cls): - name = input_str("Name: ") + name = input_str("name") hp = input_int('hp') init_mod = input_int('init mod', 0) ap = input_int('action points', 0) surges = input_int('healing surges', 0) recharges = [] - recharge = '-1' + recharge = [''] while True: - recharge = input_str("recharge: ").split(',') + recharge = input_str("recharge", default='').split(',') if recharge == ['']: break else: @@ -327,10 +327,29 @@ class Battle(): def add_group(self, group): - self.groups.append(group) + # If battle is already going, need to know + # where in the init order the new mooks go + if battle.is_started(): + if group.is_solo_group() and group.members[0].pc: + group.set_init(input_int('Initiative for {}'.format(group.name))) + else: + group.roll_init() + + added = False + for i in range(len(self.groups)): + if group.init > self.groups[i].init: + self.groups.insert(i, group) + added = True + break + + if not added: + self.groups.append(group) + else: + self.groups.append(group) + for c in group.members: self.combatant_hash[c.index] = c - + def get_current_group(self): if self.current != -1: @@ -460,11 +479,6 @@ def main(): battle.add_group(CombatGroup("Barglins", [Combatant("Barglin", hp=1), Combatant("Barglin", hp=1)], 3)) battle.add_group(CombatGroup("Orcs of Baz", [Combatant("Orc", hp=32), Combatant("Orc", hp=32)], 1)) - # ngroups = input_int('Number of enemy groups:') - # for i in range(1, ngroups+1): - # print("Adding enemy group {}".format(i)) - # battle.add_group(CombatGroup.from_input()) - print "Welcome to 4e Battle Manager.\n" print battle @@ -484,7 +498,7 @@ def do_prompt(): if comm == '?': do_help() elif comm == 'a': - print('Sorry, this is still a stub function.') + do_add_combatants(data) elif comm == 'p': print battle.format_current_group() elif comm == 'l': @@ -518,7 +532,7 @@ def do_prompt(): def do_help(): print("""Possible commands: ? - print this help menu (yay, you already figured that one out) -a - add more combatants (works during battle) [stub] +a - add more combatants (works during battle) b - begin the battle l - list combatants p - print info for combatant/group with initiative @@ -535,6 +549,13 @@ w - wait (remove a combatant from the initiative order and into a separate pool q - quit""") +def do_add_combatants(data): + ngroups = input_int('number of groups') + for i in range(1, ngroups+1): + print("Adding group {}".format(i)) + battle.add_group(CombatGroup.from_input()) + + def do_damage(data): if len(data) >= 1: c = battle.get_combatant(int(data[0]))