battleman.py: Added the ability to enter commands all at once, to avoid needing the lengthy entry process.
This commit is contained in:
parent
9e5dcc90f7
commit
33f44545bd
125
battleman.py
125
battleman.py
|
@ -12,11 +12,6 @@
|
|||
# * an option for passing in multiple files that contain combatant definitions
|
||||
# * down combatants go into a separate list
|
||||
|
||||
# dependencies:
|
||||
# * second wind
|
||||
# ** conditions
|
||||
|
||||
|
||||
from dice import Dice
|
||||
import sys
|
||||
|
||||
|
@ -307,6 +302,13 @@ class Battle():
|
|||
return None
|
||||
|
||||
|
||||
def get_combatant(self, index):
|
||||
if index in self.combatant_hash:
|
||||
return self.combatant_hash[index]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def choose_combatant(self):
|
||||
print self.format_combatants()
|
||||
index = input_int('choose combatant')
|
||||
|
@ -353,11 +355,14 @@ class Battle():
|
|||
return ret.rstrip()
|
||||
|
||||
|
||||
# Returns a formatted string with all of the combatants
|
||||
# Returns a formatted string with just the current group
|
||||
def format_current_group(self):
|
||||
if self.validate_started():
|
||||
return self.validate_started()
|
||||
|
||||
ret = ''
|
||||
|
||||
g = self.groups[current]
|
||||
g = self.groups[self.current]
|
||||
if g.is_solo_group():
|
||||
ret = ret + '{}\n'.format(g.members[0])
|
||||
else:
|
||||
|
@ -369,7 +374,8 @@ class Battle():
|
|||
|
||||
|
||||
def next_combatant(self):
|
||||
if not self.validate_started():
|
||||
if self.validate_started():
|
||||
print self.validate_started()
|
||||
return
|
||||
|
||||
g = self.get_current_group()
|
||||
|
@ -395,9 +401,8 @@ class Battle():
|
|||
|
||||
def validate_started(self):
|
||||
if not self.is_started():
|
||||
print('Error: you can only run this command after starting the battle')
|
||||
return False
|
||||
return True
|
||||
return 'Error: you can only run this command after starting the battle'
|
||||
return None
|
||||
|
||||
|
||||
battle = Battle()
|
||||
|
@ -427,30 +432,31 @@ def main():
|
|||
|
||||
def do_prompt():
|
||||
print('')
|
||||
comm = input_str('', default='?', show_default=False, prompt_str='>')
|
||||
(comm, rdata) = input_str('', default='?', show_default=False, prompt_str='>').partition(' ')[::2]
|
||||
data = rdata.split(' ')
|
||||
|
||||
if comm == '?':
|
||||
do_help()
|
||||
elif comm == 'a':
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif comm == 'p':
|
||||
print battle.format_current_group()
|
||||
elif comm == 'l':
|
||||
print battle.format_combatants()
|
||||
elif comm == 'l':
|
||||
print battle.format_current_group()
|
||||
elif comm == 'b':
|
||||
battle.begin()
|
||||
elif comm == 'd':
|
||||
do_damage()
|
||||
do_damage(data)
|
||||
elif comm == 'h':
|
||||
do_heal()
|
||||
do_heal(data)
|
||||
elif comm == 's':
|
||||
do_surge()
|
||||
do_surge(data)
|
||||
elif comm == 'so':
|
||||
do_surge(heal=False)
|
||||
do_surge(data, heal=False)
|
||||
elif comm == 'sw':
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif comm == 'c':
|
||||
do_add_condition()
|
||||
do_add_condition(data)
|
||||
elif comm == 'r':
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif comm == 'n':
|
||||
|
@ -461,30 +467,81 @@ def do_prompt():
|
|||
sys.exit(0)
|
||||
|
||||
|
||||
def do_damage():
|
||||
c = battle.choose_combatant()
|
||||
amount = input_int('damage')
|
||||
def do_damage(data):
|
||||
if (data):
|
||||
if len(data) != 2:
|
||||
print ('Error: wrong number of arguments')
|
||||
|
||||
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()
|
||||
amount = input_int('damage')
|
||||
|
||||
c.damage(amount)
|
||||
|
||||
|
||||
def do_heal():
|
||||
c = battle.choose_combatant()
|
||||
amount = input_int('amount')
|
||||
def do_heal(data):
|
||||
if (data):
|
||||
if len(data) != 2:
|
||||
print ('Error: wrong number of arguments')
|
||||
|
||||
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()
|
||||
amount = input_int('amount')
|
||||
|
||||
c.heal(amount)
|
||||
|
||||
|
||||
def do_surge(heal=True):
|
||||
c = battle.choose_combatant()
|
||||
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
|
||||
|
||||
else:
|
||||
c = battle.choose_combatant()
|
||||
|
||||
c.use_surge(heal)
|
||||
|
||||
|
||||
def do_add_condition():
|
||||
c = battle.choose_combatant()
|
||||
name = input_str('condition name')
|
||||
ctype = input_str('condition type', default='s', show_default=True)
|
||||
duration=None
|
||||
if ctype == 't':
|
||||
duration = input_int('duration')
|
||||
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')
|
||||
|
||||
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()
|
||||
name = input_str('condition name')
|
||||
ctype = input_str('condition type', default='s', show_default=True)
|
||||
duration=None
|
||||
if ctype == 't':
|
||||
duration = input_int('duration')
|
||||
|
||||
c.add_condition(name, ctype, duration)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user