battleman.py: Started adding some logic for battle groups, that contain a group of entities who share a single initiative. Also implemented the first couple main menu functions.
This commit is contained in:
parent
ac09d41675
commit
c48218da92
158
battleman.py
158
battleman.py
|
@ -8,11 +8,23 @@
|
|||
|
||||
import dice
|
||||
|
||||
class Combatant():
|
||||
|
||||
class CombatGroup():
|
||||
|
||||
# What we're mostly getting here is a definition of the *members*
|
||||
# of the group... then we build them all and stick them in
|
||||
# the group
|
||||
@classmethod
|
||||
def from_input(cls):
|
||||
name = raw_input("Name: ")
|
||||
hp = int(raw_input("hp: "))
|
||||
init_mod = int(raw_input("init mod: "))
|
||||
|
||||
ap = raw_input("action points [0] ")
|
||||
if ap:
|
||||
ap = int(ap)
|
||||
else:
|
||||
ap = 0
|
||||
|
||||
surges = raw_input("surges [0]: ")
|
||||
if surges:
|
||||
|
@ -20,29 +32,37 @@ class Combatant():
|
|||
else:
|
||||
surges = 0
|
||||
|
||||
recharges = []
|
||||
recharge = '-1'
|
||||
while True:
|
||||
recharge = raw_input("recharge: ").split(',')
|
||||
if recharge == ['']:
|
||||
break
|
||||
recharges = []
|
||||
recharge = '-1'
|
||||
while True:
|
||||
recharge = raw_input("recharge: ").split(',')
|
||||
if recharge == ['']:
|
||||
break
|
||||
else:
|
||||
recharges.append(recharge)
|
||||
|
||||
return Combatant(name, hp, pc=0, surges=surges, recharges=recharges)
|
||||
count = raw_input("count [1]: ")
|
||||
if count:
|
||||
count = int(count)
|
||||
else:
|
||||
count = 0
|
||||
|
||||
# Now make the combatants...
|
||||
members = []
|
||||
for i in range(count):
|
||||
members.append(Combatant(name, hp, pc=False, surges=surges, ap=ap, sw=0, recharges=recharges))
|
||||
|
||||
if count > 1:
|
||||
name = name + 's'
|
||||
|
||||
return CombatGroup(name, members, init_mod)
|
||||
|
||||
|
||||
def __init__(self, name, hp, init_mod, pc=False, surges=0, ap=0, sw=0, recharges=[]):
|
||||
def __init__(self, name, members, init_mod=0):
|
||||
self.name = name
|
||||
self.hp = hp
|
||||
self.pc = pc
|
||||
self.surges = surges
|
||||
self.ap = ap
|
||||
self.sw = sw
|
||||
self.recharges = []
|
||||
self.members = members
|
||||
self.init_mod = init_mod
|
||||
self.init = 0
|
||||
self.conditions = []
|
||||
|
||||
|
||||
def roll_init(self):
|
||||
|
@ -54,6 +74,28 @@ class Combatant():
|
|||
self.init = init
|
||||
|
||||
|
||||
def add_member(self, c):
|
||||
self.members.append(c)
|
||||
|
||||
|
||||
|
||||
class Combatant():
|
||||
next_index = 0
|
||||
|
||||
def __init__(self, name, hp, pc=False, init_mod=0, surges=0, ap=0, sw=0, recharges=[]):
|
||||
self.name = name
|
||||
self.max_hp = hp
|
||||
self.hp = self.max_hp
|
||||
self.pc = pc
|
||||
self.surges = surges
|
||||
self.ap = ap
|
||||
self.sw = sw
|
||||
self.recharges = []
|
||||
self.conditions = []
|
||||
self.index = Combatant.next_index
|
||||
Combatant.next_index += 1
|
||||
|
||||
|
||||
def add_condition(self, name, cond_type, duration):
|
||||
condition = {}
|
||||
condition['name'] = name
|
||||
|
@ -70,27 +112,36 @@ class Combatant():
|
|||
return "{} ({hp} hp)".format(self.name, hp=self.hp)
|
||||
|
||||
|
||||
def input_int(prompt, default=-1):
|
||||
if default != -1:
|
||||
prompt = prompt + '[{}]'.format(default)
|
||||
prompt = prompt + ': '
|
||||
|
||||
data = raw_input(prompt)
|
||||
if default != -1 and not data:
|
||||
return default
|
||||
else:
|
||||
return int(data)
|
||||
|
||||
|
||||
|
||||
# data about the battle - includes combatant list, etc
|
||||
battle = {}
|
||||
|
||||
def main():
|
||||
battle['combatants'] = []
|
||||
battle['groups'] = []
|
||||
battle['current'] = None
|
||||
battle['round'] = -1
|
||||
|
||||
# hard-coding test cases for now.
|
||||
# Eventually, use a state-saving text file that's easy to edit
|
||||
battle['combatants'].append(Combatant("Adele", hp=26, init_mod=2, pc=True, surges=8, sw=1))
|
||||
battle['combatants'].append(Combatant("Aristaire", hp=20, init_mod=0, pc=True, surges=6, sw=1))
|
||||
battle['groups'].append(CombatGroup("Adele", [Combatant("Adele", hp=26, pc=True, surges=8, sw=1)], 2))
|
||||
battle['groups'].append(CombatGroup("Aristaire", [Combatant("Aristaire", hp=20, pc=True, surges=6, sw=1)], 0))
|
||||
|
||||
ngroups = int(raw_input("Num enemy groups: "))
|
||||
ngroups = int(raw_input("Number of enemy groups: "))
|
||||
for i in range(1, ngroups+1):
|
||||
print("Adding enemy group {}".format(i))
|
||||
battle['combatants'].append(Combatant.from_input())
|
||||
|
||||
# debug
|
||||
for c in battle['combatants']:
|
||||
print(c)
|
||||
battle['groups'].append(CombatGroup.from_input())
|
||||
|
||||
while True:
|
||||
do_prompt()
|
||||
|
@ -99,39 +150,31 @@ def main():
|
|||
def do_prompt():
|
||||
comm = raw_input('> ')
|
||||
|
||||
# help
|
||||
# debug
|
||||
print ('|' + comm + '|')
|
||||
|
||||
if 'comm' == '?':
|
||||
do_help()
|
||||
# add more combatants
|
||||
elif 'comm' == 'a':
|
||||
pass
|
||||
# list combatants with indices
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif 'comm' == 'l':
|
||||
do_list_combatants()
|
||||
# begin the battle
|
||||
elif 'comm' == 'b':
|
||||
do_begin_battle()
|
||||
# deal damage to a combatant
|
||||
elif 'comm' == 'd':
|
||||
pass
|
||||
# heal damage from a combatant
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif 'comm' == 'h':
|
||||
pass
|
||||
# use a healing surge
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif 'comm' == 's':
|
||||
pass
|
||||
# apply a condition
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif 'comm' == 'c':
|
||||
pass
|
||||
# remove a condition early
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif 'comm' == 'r':
|
||||
pass
|
||||
# end the current combatant's turn
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif 'comm' == 'n':
|
||||
pass
|
||||
# remove the combatant from the initiative order (delay/prepare)
|
||||
print('Sorry, this is still a stub function.')
|
||||
elif 'comm' == 'w':
|
||||
pass
|
||||
print('Sorry, this is still a stub function.')
|
||||
|
||||
|
||||
def do_help():
|
||||
|
@ -146,16 +189,15 @@ h - heal someone
|
|||
s - let someone use a healing surge
|
||||
c - apply a condition
|
||||
r - remove a condition (this can also happen automatically)
|
||||
n - next (end the current combatant's turn)
|
||||
w - wait (remove the combatant from the initiative order and into a separate pool)
|
||||
n - next (end the current combat group's turn)
|
||||
w - wait (remove a combatant from the initiative order and into a separate pool)
|
||||
""")
|
||||
|
||||
|
||||
def do_list_combatants():
|
||||
index = 0
|
||||
for c in battle['combatants']:
|
||||
print('{}: {}'.format(index, c.name))
|
||||
index += 1
|
||||
for g in battle['groups']:
|
||||
for c in g.members:
|
||||
print('{}: {}'.format(c.index, c.name))
|
||||
|
||||
|
||||
def do_begin_battle():
|
||||
|
@ -163,14 +205,18 @@ def do_begin_battle():
|
|||
print("Error: battle is already running")
|
||||
return
|
||||
|
||||
for c in battle['combatants']:
|
||||
if c.pc:
|
||||
raw_input('Initiative for {}: '.format(c.name))
|
||||
for g in battle['groups']:
|
||||
if g.single() and g.members[0].pc:
|
||||
raw_input('Initiative for {}: '.format(g.name))
|
||||
else:
|
||||
c.roll_init()
|
||||
g.roll_init()
|
||||
|
||||
battle['combatants'].sort(reverse=True)
|
||||
current = 0
|
||||
battle['groups'].sort(reverse=True, key=lambda group: group.init)
|
||||
battle['current'] = 0
|
||||
battle['round'] = 1
|
||||
|
||||
for g in battle['groups']:
|
||||
print '{} ({})'.format(g.name, g.init)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user