battleman.py: Implemented second wind and temporary hp.

This commit is contained in:
Anna Rose 2012-03-23 17:09:23 -04:00
parent 33f44545bd
commit d09245db4c

View File

@ -90,6 +90,7 @@ class CombatGroup():
c.end_turn() c.end_turn()
class Combatant(): class Combatant():
next_index = 0 next_index = 0
@ -194,9 +195,13 @@ class Combatant():
print('{} is still bloodied.'.format(self)) print('{} is still bloodied.'.format(self))
def add_temp_hp(self, amount):
self.temp_hp += amount
def use_surge(self, heal=True): def use_surge(self, heal=True):
if self.surges <= 0: if self.surges <= 0:
print 'Error: {} has no healing surges.'.format(self.name) print '{} has no healing surges.'.format(self)
return return
self.surges -= 1 self.surges -= 1
@ -209,6 +214,20 @@ class Combatant():
self.heal(self.max_hp / 4) self.heal(self.max_hp / 4)
def use_second_wind(self):
if self.sw <= 0:
print "{} doesn't have a second wind.".format(self)
return
self.surges -= 1
print '{} got their second wind!'.format(self)
# Now the actual effects of the SW
self.do_surge()
self.add_condition('Second Wind (+2 all def)', 't', 1)
def is_bloodied(self): def is_bloodied(self):
return self.hp <= self.max_hp / 2 return self.hp <= self.max_hp / 2
@ -242,26 +261,6 @@ class Combatant():
summary = summary + '{}: {} ({})\n'.format(index, c['name'], c['duration']) summary = summary + '{}: {} ({})\n'.format(index, c['name'], c['duration'])
def input_str(prompt, default=None, show_default=False, prompt_str=':'):
full_prompt = prompt
if default != None and show_default:
full_prompt = full_prompt + ' [{}]'.format(default)
full_prompt = full_prompt + '{} '.format(prompt_str)
data = raw_input(full_prompt)
if not data:
if default == None:
print 'Error: you must provide a value!'
return input_str(prompt, default, show_default, prompt_str)
else:
return default
else:
return data
def input_int(prompt, default=None, show_default=True, prompt_str=':'):
return int(input_str(prompt, default, show_default))
# data about the battle - includes combatant list, etc # data about the battle - includes combatant list, etc
class Battle(): class Battle():
@ -435,6 +434,10 @@ def do_prompt():
(comm, rdata) = input_str('', default='?', show_default=False, prompt_str='>').partition(' ')[::2] (comm, rdata) = input_str('', default='?', show_default=False, prompt_str='>').partition(' ')[::2]
data = rdata.split(' ') data = rdata.split(' ')
# To simplify our checks later
if data == ['']:
data = None
if comm == '?': if comm == '?':
do_help() do_help()
elif comm == 'a': elif comm == 'a':
@ -449,12 +452,14 @@ def do_prompt():
do_damage(data) do_damage(data)
elif comm == 'h': elif comm == 'h':
do_heal(data) do_heal(data)
elif comm == 't':
do_add_temp_hp(data)
elif comm == 's': elif comm == 's':
do_surge(data) do_surge(data)
elif comm == 'so': elif comm == 'so':
do_surge(data, heal=False) do_surge(data, heal=False)
elif comm == 'sw': elif comm == 'sw':
print('Sorry, this is still a stub function.') do_second_wind(data)
elif comm == 'c': elif comm == 'c':
do_add_condition(data) do_add_condition(data)
elif comm == 'r': elif comm == 'r':
@ -470,11 +475,11 @@ def do_prompt():
def do_damage(data): def do_damage(data):
if (data): if (data):
if len(data) != 2: if len(data) != 2:
print ('Error: wrong number of arguments') print ('Error: wrong number of arguments.')
c = battle.get_combatant(int(data[0])) c = battle.get_combatant(int(data[0]))
if not c: if not c:
print ('Error: Invalid combatant index') print ('Error: Invalid combatant index.')
return return
amount = int(data[1]) amount = int(data[1])
@ -492,7 +497,7 @@ def do_heal(data):
c = battle.get_combatant(int(data[0])) c = battle.get_combatant(int(data[0]))
if not c: if not c:
print ('Error: Invalid combatant index') print ('Error: Invalid combatant index.')
return return
amount = int(data[1]) amount = int(data[1])
@ -503,14 +508,32 @@ def do_heal(data):
c.heal(amount) c.heal(amount)
def do_surge(data, heal=True): def do_add_temp_hp(data):
if (data): if (data):
if len(data) != 1: if len(data) != 2:
print ('Error: wrong number of arguments') print ('Error: wrong number of arguments')
c = battle.get_combatant(int(data[0])) c = battle.get_combatant(int(data[0]))
if not c: if not c:
print ('Error: Invalid combatant index') print ('Error: Invalid combatant index.')
return
amount = int(data[1])
else:
c = battle.choose_combatant()
amount = input_int('amount')
c.add_temp_hp(amount)
def do_surge(data, heal=True):
if (data):
if len(data) != 1:
print ('Error: wrong number of arguments.')
c = battle.get_combatant(int(data[0]))
if not c:
print ('Error: Invalid combatant index.')
return return
else: else:
@ -519,12 +542,28 @@ def do_surge(data, heal=True):
c.use_surge(heal) c.use_surge(heal)
def do_second_wind(data):
if (data):
if len(data) != 1:
print ('Error: wrong number of arguments.')
c = battle.get_combatant(int(data[0]))
if not c:
print ('Error: Invalid combatant index.')
return
else:
c = battle.choose_combatant()
c.use_second_wind()
def do_add_condition(data): def do_add_condition(data):
duration = None duration = None
if data: if data:
if len(data) < 2 or (len(data) == 3 and data[2] == 't'): if len(data) < 2 or (len(data) == 3 and data[2] == 't'):
print ('Error: wrong number of arguments') print ('Error: wrong number of arguments.')
c = battle.get_combatant(int(data[0])) c = battle.get_combatant(int(data[0]))
name = data[1] name = data[1]
@ -555,10 +594,10 @@ l - list combatants
p - print info for combatant/group with initiative p - print info for combatant/group with initiative
d - deal damage to someone d - deal damage to someone
h - heal someone h - heal someone
t - add temporary hit points to someone [stub] t - add temporary hit points
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 your second wind (current combat group only) [stub] sw - use a second wind
c - apply a condition [stub] c - apply a condition [stub]
r - remove a condition (this can also happen automatically) [stub] r - remove a condition (this can also happen automatically) [stub]
n - next (end the current combat group's turn) n - next (end the current combat group's turn)
@ -566,5 +605,26 @@ w - wait (remove a combatant from the initiative order and into a separate pool
q - quit""") q - quit""")
def input_str(prompt, default=None, show_default=False, prompt_str=':'):
full_prompt = prompt
if default != None and show_default:
full_prompt = full_prompt + ' [{}]'.format(default)
full_prompt = full_prompt + '{} '.format(prompt_str)
data = raw_input(full_prompt)
if not data:
if default == None:
print 'Error: you must provide a value!'
return input_str(prompt, default, show_default, prompt_str)
else:
return default
else:
return data
def input_int(prompt, default=None, show_default=True, prompt_str=':'):
return int(input_str(prompt, default, show_default))
if __name__ == '__main__': if __name__ == '__main__':
main() main()