battleman.py: Changed input functions to support partial data - they will prompt for anything that's missing.

This commit is contained in:
Anna Rose 2012-03-23 21:06:46 -04:00
parent 3c78f41b93
commit c3cc6d85e0

View File

@ -536,69 +536,62 @@ q - quit""")
def do_damage(data):
if (data):
if len(data) != 2:
print ('Error: wrong number of arguments.')
if len(data) >= 1:
c = battle.get_combatant(int(data[0]))
if not c:
print ('Error: Invalid combatant index.')
return
amount = int(data[1])
else:
c = battle.choose_combatant()
if len(data) >= 2:
amount = int(data[1])
else:
amount = input_int('damage')
c.damage(amount)
def do_heal(data):
if (data):
if len(data) != 2:
print ('Error: wrong number of arguments')
if len(data) >= 1:
c = battle.get_combatant(int(data[0]))
if not c:
print ('Error: Invalid combatant index.')
return
amount = int(data[1])
else:
c = battle.choose_combatant()
if len(data) >= 2:
amount = int(data[1])
else:
amount = input_int('amount')
c.heal(amount)
def do_add_temp_hp(data):
if (data):
if len(data) != 2:
print ('Error: wrong number of arguments')
if len(data) >= 1:
c = battle.get_combatant(int(data[0]))
if not c:
print ('Error: Invalid combatant index.')
return
amount = int(data[1])
else:
c = battle.choose_combatant()
if len(data) >= 2:
amount = int(data[1])
else:
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.')
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()
@ -606,15 +599,11 @@ def do_surge(data, heal=True):
def do_second_wind(data):
if (data):
if len(data) != 1:
print ('Error: wrong number of arguments.')
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()
@ -624,45 +613,42 @@ def do_second_wind(data):
def do_add_condition(data):
duration = None
if data:
if len(data) < 2 or (len(data) == 3 and data[2] == 't'):
print ('Error: wrong number of arguments.')
if len(data) >= 1:
c = battle.get_combatant(int(data[0]))
name = data[1]
ctype = 's'
if len(data) > 2:
ctype = data[2]
if ctype == 't':
duration = int(data[3])
else:
c = battle.choose_combatant()
if len(data) >= 2:
name = data[1]
else:
name = input_str('condition name')
if len(data) >= 3:
ctype = data[2]
else:
ctype = input_str('condition type', default='s', show_default=True)
duration=None
if ctype == 't':
if len(data) >= 4:
duration = int(data[3])
else:
duration = input_int('duration')
c.add_condition(name, ctype, duration)
def do_remove_condition(data):
if data:
if len(data) != 2:
print ('Error: wrong number of arguments.')
return
if len(data) >= 1:
c = battle.get_combatant(int(data[0]))
if not c:
print ('Error: Invalid combatant index.')
return
index = int(data[1])
else:
c = battle.choose_combatant()
if len(data) >= 2:
index = int(data[1])
else:
index = c.choose_condition()['index']
c.remove_condition(index)