battleman.py: Implemented UI side of recharge powers.
This commit is contained in:
parent
fddb2bf8bb
commit
0afd59aa88
107
battleman.py
107
battleman.py
|
@ -104,12 +104,18 @@ class Combatant():
|
|||
self.surges = surges
|
||||
self.ap = ap
|
||||
self.sw = sw
|
||||
self.recharges = []
|
||||
self.conditions = {}
|
||||
self.index = Combatant.next_index
|
||||
self.next_condition_index = 0
|
||||
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):
|
||||
return "{}: {} ({})".format(self.index, self.name, self.format_health_summary())
|
||||
|
@ -192,8 +198,9 @@ class Combatant():
|
|||
else:
|
||||
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:
|
||||
if r['used']:
|
||||
if r['used']: # fixme: this line breaks
|
||||
# Roll to recharge
|
||||
d = Dice.from_str('1d6')
|
||||
n = d.roll()['total']
|
||||
|
@ -279,6 +286,25 @@ class Combatant():
|
|||
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):
|
||||
return self.hp <= self.max_hp / 2
|
||||
|
||||
|
@ -287,6 +313,21 @@ class Combatant():
|
|||
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):
|
||||
bloodied = ''
|
||||
temp_info = ''
|
||||
|
@ -313,6 +354,11 @@ class Combatant():
|
|||
|
||||
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
|
||||
|
@ -435,9 +481,9 @@ class Battle():
|
|||
|
||||
g = self.groups[self.current]
|
||||
if g.is_solo_group():
|
||||
ret = ret + '{}\n'.format(g.members[0])
|
||||
ret = '{}\n'.format(g.members[0].format_full_info())
|
||||
else:
|
||||
ret = ret + '{}:\n'.format(g.name)
|
||||
ret = ret + '{}'.format(g.name)
|
||||
for c in g.members:
|
||||
ret = ret + ' {}\n'.format(c)
|
||||
|
||||
|
@ -539,6 +585,8 @@ def do_prompt():
|
|||
do_remove_condition(data)
|
||||
elif comm == 'n':
|
||||
battle.next_combatant()
|
||||
elif comm == 'r':
|
||||
do_use_recharge_power(data)
|
||||
elif comm == 'w':
|
||||
do_wait(data)
|
||||
elif comm == 'W':
|
||||
|
@ -549,23 +597,23 @@ 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)
|
||||
b - begin the battle
|
||||
l - list combatants
|
||||
p - print info for combatant/group with initiative
|
||||
d - deal damage to someone
|
||||
h - heal someone
|
||||
t - add temporary hit points
|
||||
T - remove temporary hit points [stub]
|
||||
s - use a healing surge
|
||||
so - use a healing surge, but don't regain hit points
|
||||
sw - use a second wind
|
||||
c - apply a condition
|
||||
C - remove a condition
|
||||
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]
|
||||
q - quit""")
|
||||
? - print this help menu (yay, you already figured that one out)
|
||||
a - add more combatants (works during battle)
|
||||
b - begin the battle
|
||||
l - list combatants
|
||||
p - print info for combatant/group with initiative
|
||||
d - deal damage to someone
|
||||
h - heal someone
|
||||
t - add temporary hit points
|
||||
T - remove temporary hit points [stub]
|
||||
s - use a healing surge
|
||||
so - use a healing surge, but don't regain hit points
|
||||
sw - use a second wind
|
||||
c/C - apply / remove a condition
|
||||
r - use a rechargable power
|
||||
n - next (end the current combat group's turn)
|
||||
w/W - wait / unwait (remove a combatant from the initiative order and into a separate pool, then put them back) [stub]
|
||||
q - quit""")
|
||||
|
||||
|
||||
def do_add_combatants(data):
|
||||
|
@ -704,6 +752,23 @@ def do_remove_condition(data):
|
|||
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):
|
||||
do_stub()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user