battleman.py: Implemented UI side of recharge powers.

This commit is contained in:
Anna Rose 2012-03-25 01:53:32 -04:00
parent fddb2bf8bb
commit 0afd59aa88

View File

@ -104,12 +104,18 @@ class Combatant():
self.surges = surges self.surges = surges
self.ap = ap self.ap = ap
self.sw = sw self.sw = sw
self.recharges = []
self.conditions = {} self.conditions = {}
self.index = Combatant.next_index self.index = Combatant.next_index
self.next_condition_index = 0 self.next_condition_index = 0
Combatant.next_index += 1 Combatant.next_index += 1
self.recharges = {}
recharge_index = 0
for r in recharges:
r['index'] = recharge_index
self.recharges[recharge_index] = r
recharge_index += 1
def __str__(self): def __str__(self):
return "{}: {} ({})".format(self.index, self.name, self.format_health_summary()) return "{}: {} ({})".format(self.index, self.name, self.format_health_summary())
@ -192,8 +198,9 @@ class Combatant():
else: else:
print('{} is still affected by {} ({} round{} left).'.format(self, c['name'], c['duration'], 's'[c['duration']==1:])) print('{} is still affected by {} ({} round{} left).'.format(self, c['name'], c['duration'], 's'[c['duration']==1:]))
# fixme: print message when this succeeds
for r in self.recharges: for r in self.recharges:
if r['used']: if r['used']: # fixme: this line breaks
# Roll to recharge # Roll to recharge
d = Dice.from_str('1d6') d = Dice.from_str('1d6')
n = d.roll()['total'] n = d.roll()['total']
@ -279,6 +286,25 @@ class Combatant():
self.add_condition('Second Wind (+2 all def)', 't', 1) self.add_condition('Second Wind (+2 all def)', 't', 1)
def use_recharge_power(self, index):
if index not in self.recharges:
print "Error: Invalid recharge index"
return
self.recharges[index]['used'] = True
def choose_recharge_power(self):
print self.format_recharge_summary()
index = input_int('choice')
if index not in self.recharges:
print 'Error: {} is not a valid index'.format(index)
return self.choose_recharge_power()
return self.recharges[index]
def is_bloodied(self): def is_bloodied(self):
return self.hp <= self.max_hp / 2 return self.hp <= self.max_hp / 2
@ -287,6 +313,21 @@ class Combatant():
return self.hp <= 0 return self.hp <= 0
def format_full_info(self):
return """{name}
{separator}
index: {index}
hp: {hp}/{max_hp}
temp hp: {temp_hp}
surges: {surge}
ap: {ap}
sw: {sw}
conditions:
{conditions}
recharge powers:
{recharge}""".format(index=self.index, name=self.name, hp=self.hp, max_hp=self.max_hp, temp_hp=self.temp_hp, surge=self.surges, ap=self.ap, sw=self.sw, conditions=self.format_condition_summary(), recharge=self.format_recharge_summary(), separator='='*len(self.name))
def format_health_summary(self): def format_health_summary(self):
bloodied = '' bloodied = ''
temp_info = '' temp_info = ''
@ -313,6 +354,11 @@ class Combatant():
return summary.rstrip() return summary.rstrip()
def format_recharge_summary(self):
summary = ''
for (index, r) in self.recharges.items():
summary = summary + '{}: {} (Recharge: {}, Available: {})\n'.format(index, r['name'], r['value'], ['Yes', 'No'][ r['used'] ])
return summary.rstrip()
# data about the battle - includes combatant list, etc # data about the battle - includes combatant list, etc
@ -435,9 +481,9 @@ class Battle():
g = self.groups[self.current] g = self.groups[self.current]
if g.is_solo_group(): if g.is_solo_group():
ret = ret + '{}\n'.format(g.members[0]) ret = '{}\n'.format(g.members[0].format_full_info())
else: else:
ret = ret + '{}:\n'.format(g.name) ret = ret + '{}'.format(g.name)
for c in g.members: for c in g.members:
ret = ret + ' {}\n'.format(c) ret = ret + ' {}\n'.format(c)
@ -539,6 +585,8 @@ def do_prompt():
do_remove_condition(data) do_remove_condition(data)
elif comm == 'n': elif comm == 'n':
battle.next_combatant() battle.next_combatant()
elif comm == 'r':
do_use_recharge_power(data)
elif comm == 'w': elif comm == 'w':
do_wait(data) do_wait(data)
elif comm == 'W': elif comm == 'W':
@ -561,10 +609,10 @@ T - remove temporary hit points [stub]
s - use a healing surge s - use a healing surge
so - use a healing surge, but don't regain hit points so - use a healing surge, but don't regain hit points
sw - use a second wind sw - use a second wind
c - apply a condition c/C - apply / remove a condition
C - remove a condition r - use a rechargable power
n - next (end the current combat group's turn) n - next (end the current combat group's turn)
wW - wait / unwait (remove a combatant from the initiative order and into a separate pool, then put them back) [stub] w/W - wait / unwait (remove a combatant from the initiative order and into a separate pool, then put them back) [stub]
q - quit""") q - quit""")
@ -704,6 +752,23 @@ def do_remove_condition(data):
c.remove_condition(index) c.remove_condition(index)
def do_use_recharge_power(data):
if len(data) >= 1:
c = battle.get_combatant(int(data[0]))
if not c:
print ('Error: Invalid combatant index.')
return
else:
c = battle.choose_combatant()
if len(data) >= 2:
index = int(data[1])
else:
index = c.choose_recharge_power()['index']
c.use_recharge_power(index)
def do_wait(data): def do_wait(data):
do_stub() do_stub()