battleman.py: Added ability to add groups on the fly
This commit is contained in:
parent
c3cc6d85e0
commit
7a0505fdf1
41
battleman.py
41
battleman.py
|
@ -25,16 +25,16 @@ class CombatGroup():
|
||||||
# the group
|
# the group
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_input(cls):
|
def from_input(cls):
|
||||||
name = input_str("Name: ")
|
name = input_str("name")
|
||||||
hp = input_int('hp')
|
hp = input_int('hp')
|
||||||
init_mod = input_int('init mod', 0)
|
init_mod = input_int('init mod', 0)
|
||||||
ap = input_int('action points', 0)
|
ap = input_int('action points', 0)
|
||||||
surges = input_int('healing surges', 0)
|
surges = input_int('healing surges', 0)
|
||||||
|
|
||||||
recharges = []
|
recharges = []
|
||||||
recharge = '-1'
|
recharge = ['']
|
||||||
while True:
|
while True:
|
||||||
recharge = input_str("recharge: ").split(',')
|
recharge = input_str("recharge", default='').split(',')
|
||||||
if recharge == ['']:
|
if recharge == ['']:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -327,7 +327,26 @@ class Battle():
|
||||||
|
|
||||||
|
|
||||||
def add_group(self, group):
|
def add_group(self, group):
|
||||||
|
# If battle is already going, need to know
|
||||||
|
# where in the init order the new mooks go
|
||||||
|
if battle.is_started():
|
||||||
|
if group.is_solo_group() and group.members[0].pc:
|
||||||
|
group.set_init(input_int('Initiative for {}'.format(group.name)))
|
||||||
|
else:
|
||||||
|
group.roll_init()
|
||||||
|
|
||||||
|
added = False
|
||||||
|
for i in range(len(self.groups)):
|
||||||
|
if group.init > self.groups[i].init:
|
||||||
|
self.groups.insert(i, group)
|
||||||
|
added = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not added:
|
||||||
self.groups.append(group)
|
self.groups.append(group)
|
||||||
|
else:
|
||||||
|
self.groups.append(group)
|
||||||
|
|
||||||
for c in group.members:
|
for c in group.members:
|
||||||
self.combatant_hash[c.index] = c
|
self.combatant_hash[c.index] = c
|
||||||
|
|
||||||
|
@ -460,11 +479,6 @@ def main():
|
||||||
battle.add_group(CombatGroup("Barglins", [Combatant("Barglin", hp=1), Combatant("Barglin", hp=1)], 3))
|
battle.add_group(CombatGroup("Barglins", [Combatant("Barglin", hp=1), Combatant("Barglin", hp=1)], 3))
|
||||||
battle.add_group(CombatGroup("Orcs of Baz", [Combatant("Orc", hp=32), Combatant("Orc", hp=32)], 1))
|
battle.add_group(CombatGroup("Orcs of Baz", [Combatant("Orc", hp=32), Combatant("Orc", hp=32)], 1))
|
||||||
|
|
||||||
# ngroups = input_int('Number of enemy groups:')
|
|
||||||
# for i in range(1, ngroups+1):
|
|
||||||
# print("Adding enemy group {}".format(i))
|
|
||||||
# battle.add_group(CombatGroup.from_input())
|
|
||||||
|
|
||||||
print "Welcome to 4e Battle Manager.\n"
|
print "Welcome to 4e Battle Manager.\n"
|
||||||
print battle
|
print battle
|
||||||
|
|
||||||
|
@ -484,7 +498,7 @@ def do_prompt():
|
||||||
if comm == '?':
|
if comm == '?':
|
||||||
do_help()
|
do_help()
|
||||||
elif comm == 'a':
|
elif comm == 'a':
|
||||||
print('Sorry, this is still a stub function.')
|
do_add_combatants(data)
|
||||||
elif comm == 'p':
|
elif comm == 'p':
|
||||||
print battle.format_current_group()
|
print battle.format_current_group()
|
||||||
elif comm == 'l':
|
elif comm == 'l':
|
||||||
|
@ -518,7 +532,7 @@ def do_prompt():
|
||||||
def do_help():
|
def do_help():
|
||||||
print("""Possible commands:
|
print("""Possible commands:
|
||||||
? - print this help menu (yay, you already figured that one out)
|
? - print this help menu (yay, you already figured that one out)
|
||||||
a - add more combatants (works during battle) [stub]
|
a - add more combatants (works during battle)
|
||||||
b - begin the battle
|
b - begin the battle
|
||||||
l - list combatants
|
l - list combatants
|
||||||
p - print info for combatant/group with initiative
|
p - print info for combatant/group with initiative
|
||||||
|
@ -535,6 +549,13 @@ w - wait (remove a combatant from the initiative order and into a separate pool
|
||||||
q - quit""")
|
q - quit""")
|
||||||
|
|
||||||
|
|
||||||
|
def do_add_combatants(data):
|
||||||
|
ngroups = input_int('number of groups')
|
||||||
|
for i in range(1, ngroups+1):
|
||||||
|
print("Adding group {}".format(i))
|
||||||
|
battle.add_group(CombatGroup.from_input())
|
||||||
|
|
||||||
|
|
||||||
def do_damage(data):
|
def do_damage(data):
|
||||||
if len(data) >= 1:
|
if len(data) >= 1:
|
||||||
c = battle.get_combatant(int(data[0]))
|
c = battle.get_combatant(int(data[0]))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user