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
103
battleman.py
103
battleman.py
|
@ -12,11 +12,6 @@
|
||||||
# * an option for passing in multiple files that contain combatant definitions
|
# * an option for passing in multiple files that contain combatant definitions
|
||||||
# * down combatants go into a separate list
|
# * down combatants go into a separate list
|
||||||
|
|
||||||
# dependencies:
|
|
||||||
# * second wind
|
|
||||||
# ** conditions
|
|
||||||
|
|
||||||
|
|
||||||
from dice import Dice
|
from dice import Dice
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -307,6 +302,13 @@ class Battle():
|
||||||
return None
|
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):
|
def choose_combatant(self):
|
||||||
print self.format_combatants()
|
print self.format_combatants()
|
||||||
index = input_int('choose combatant')
|
index = input_int('choose combatant')
|
||||||
|
@ -353,11 +355,14 @@ class Battle():
|
||||||
return ret.rstrip()
|
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):
|
def format_current_group(self):
|
||||||
|
if self.validate_started():
|
||||||
|
return self.validate_started()
|
||||||
|
|
||||||
ret = ''
|
ret = ''
|
||||||
|
|
||||||
g = self.groups[current]
|
g = self.groups[self.current]
|
||||||
if g.is_solo_group():
|
if g.is_solo_group():
|
||||||
ret = ret + '{}\n'.format(g.members[0])
|
ret = ret + '{}\n'.format(g.members[0])
|
||||||
else:
|
else:
|
||||||
|
@ -369,7 +374,8 @@ class Battle():
|
||||||
|
|
||||||
|
|
||||||
def next_combatant(self):
|
def next_combatant(self):
|
||||||
if not self.validate_started():
|
if self.validate_started():
|
||||||
|
print self.validate_started()
|
||||||
return
|
return
|
||||||
|
|
||||||
g = self.get_current_group()
|
g = self.get_current_group()
|
||||||
|
@ -395,9 +401,8 @@ class Battle():
|
||||||
|
|
||||||
def validate_started(self):
|
def validate_started(self):
|
||||||
if not self.is_started():
|
if not self.is_started():
|
||||||
print('Error: you can only run this command after starting the battle')
|
return 'Error: you can only run this command after starting the battle'
|
||||||
return False
|
return None
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
battle = Battle()
|
battle = Battle()
|
||||||
|
@ -427,30 +432,31 @@ def main():
|
||||||
|
|
||||||
def do_prompt():
|
def do_prompt():
|
||||||
print('')
|
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 == '?':
|
if comm == '?':
|
||||||
do_help()
|
do_help()
|
||||||
elif comm == 'a':
|
elif comm == 'a':
|
||||||
print('Sorry, this is still a stub function.')
|
print('Sorry, this is still a stub function.')
|
||||||
|
elif comm == 'p':
|
||||||
|
print battle.format_current_group()
|
||||||
elif comm == 'l':
|
elif comm == 'l':
|
||||||
print battle.format_combatants()
|
print battle.format_combatants()
|
||||||
elif comm == 'l':
|
|
||||||
print battle.format_current_group()
|
|
||||||
elif comm == 'b':
|
elif comm == 'b':
|
||||||
battle.begin()
|
battle.begin()
|
||||||
elif comm == 'd':
|
elif comm == 'd':
|
||||||
do_damage()
|
do_damage(data)
|
||||||
elif comm == 'h':
|
elif comm == 'h':
|
||||||
do_heal()
|
do_heal(data)
|
||||||
elif comm == 's':
|
elif comm == 's':
|
||||||
do_surge()
|
do_surge(data)
|
||||||
elif comm == 'so':
|
elif comm == 'so':
|
||||||
do_surge(heal=False)
|
do_surge(data, heal=False)
|
||||||
elif comm == 'sw':
|
elif comm == 'sw':
|
||||||
print('Sorry, this is still a stub function.')
|
print('Sorry, this is still a stub function.')
|
||||||
elif comm == 'c':
|
elif comm == 'c':
|
||||||
do_add_condition()
|
do_add_condition(data)
|
||||||
elif comm == 'r':
|
elif comm == 'r':
|
||||||
print('Sorry, this is still a stub function.')
|
print('Sorry, this is still a stub function.')
|
||||||
elif comm == 'n':
|
elif comm == 'n':
|
||||||
|
@ -461,24 +467,75 @@ def do_prompt():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def do_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()
|
c = battle.choose_combatant()
|
||||||
amount = input_int('damage')
|
amount = input_int('damage')
|
||||||
|
|
||||||
c.damage(amount)
|
c.damage(amount)
|
||||||
|
|
||||||
|
|
||||||
def do_heal():
|
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()
|
c = battle.choose_combatant()
|
||||||
amount = input_int('amount')
|
amount = input_int('amount')
|
||||||
|
|
||||||
c.heal(amount)
|
c.heal(amount)
|
||||||
|
|
||||||
|
|
||||||
def do_surge(heal=True):
|
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 = battle.choose_combatant()
|
||||||
|
|
||||||
c.use_surge(heal)
|
c.use_surge(heal)
|
||||||
|
|
||||||
|
|
||||||
def do_add_condition():
|
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()
|
c = battle.choose_combatant()
|
||||||
name = input_str('condition name')
|
name = input_str('condition name')
|
||||||
ctype = input_str('condition type', default='s', show_default=True)
|
ctype = input_str('condition type', default='s', show_default=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user