diff --git a/battleman.py b/battleman.py index 5c1f6ae..16629b9 100755 --- a/battleman.py +++ b/battleman.py @@ -5,6 +5,12 @@ # A table-top RPG battle flow manager # Tuned pretty specifically to D&D 4e for now... need a templatized system # to do anything fancier... may develop that at some point. +# +# future features: +# * keep a pickled file or a shelve db of the current state, and add a --resume option +# for resuming a battle later +# * an option for passing in multiple files that contain combatant definitions +# * down combatants go into a separate list from dice import Dice import sys @@ -133,7 +139,7 @@ class Combatant(): def input_int(prompt, default=-1): if default != -1: - prompt = prompt + '[{}]'.format(default) + prompt = prompt + ' [{}]'.format(default) prompt = prompt + ': ' data = raw_input(prompt) @@ -153,6 +159,19 @@ class Battle(): self.round = -1 + def __str__(self): + ret = '' + if self.is_started(): + ret = 'Battle underway, currently on round {}\n'.format(self.round) + else: + ret = 'Battle not yet started\n' + + ret = ret + 'Combatants:\n' + ret = ret + self.list_combatants() + + return ret + + def is_started(self): return self.current != None @@ -163,9 +182,8 @@ class Battle(): self.combatant_hash[c.index] = c - # fixme: still returns None after battle begins def get_current_group(self): - if self.current: + if self.current != -1: return self.groups[self.current] else: return None @@ -174,7 +192,6 @@ class Battle(): def begin(self): if self.is_started(): print("Error: battle is already running") - return for g in self.groups: if g.is_solo_group() and g.members[0].pc: @@ -190,14 +207,19 @@ class Battle(): print '{} ({})'.format(g.name, g.init) + # Returns a formatted string with all of the combatants def list_combatants(self): + ret = '' + for g in self.groups: if g.is_solo_group(): - print('{}: {}'.format(g.members[0].index, g.name)) + ret = ret + '{}: {}\n'.format(g.members[0].index, g.name) else: - print('{}:'.format(g.name)) + ret = ret + '{}:\n'.format(g.name) for c in g.members: - print('\t{}: {} ({})'.format(c.index, c.name, c.get_health_summary())) + ret = ret + '\t{}: {} ({})\n'.format(c.index, c.name, c.get_health_summary()) + + return ret.rstrip() def next_combatant(self): @@ -228,11 +250,15 @@ def main(): # print("Adding enemy group {}".format(i)) # battle.add_group(CombatGroup.from_input()) + print "Welcome to 4e Battle Manager.\nCurrent status:" + print battle + while True: do_prompt() def do_prompt(): + print('') comm = raw_input('> ') if comm == '?': @@ -267,7 +293,7 @@ def do_damage(): return battle.list_combatants() - index = input_int('choose combatant', battle.get_current_group().members[0]) + index = input_int('choose combatant', battle.get_current_group().members[0].index) amount = input_int('damage') battle.deal_damage(index, amount) @@ -285,8 +311,7 @@ c - apply a condition r - remove a condition (this can also happen automatically) n - next (end the current combat group's turn) w - wait (remove a combatant from the initiative order and into a separate pool) -q - quit -""") +q - quit""") if __name__ == '__main__':