battleman.py: Implemented conditions
This commit is contained in:
parent
ac7396e6a3
commit
0fc770f261
68
battleman.py
68
battleman.py
|
@ -108,20 +108,54 @@ class Combatant():
|
||||||
self.ap = ap
|
self.ap = ap
|
||||||
self.sw = sw
|
self.sw = sw
|
||||||
self.recharges = []
|
self.recharges = []
|
||||||
self.conditions = []
|
self.conditions = {}
|
||||||
self.index = Combatant.next_index
|
self.index = Combatant.next_index
|
||||||
|
self.next_condition_index = 0
|
||||||
Combatant.next_index += 1
|
Combatant.next_index += 1
|
||||||
|
|
||||||
|
|
||||||
def add_condition(self, name, cond_type, duration):
|
def __str__(self):
|
||||||
|
return "{}: {} ({})".format(self.index, self.name, self.format_health_summary())
|
||||||
|
|
||||||
|
|
||||||
|
# cond_type can be 's' or 't', for 'save' or 'timed'. If it is 't', condition expires at the end of the players turn
|
||||||
|
# 'duration' rounds from now
|
||||||
|
def add_condition(self, name, cond_type, duration=None):
|
||||||
condition = {}
|
condition = {}
|
||||||
condition['name'] = name
|
condition['name'] = name
|
||||||
|
condition['cond_type'] = cond_type
|
||||||
condition['duration'] = duration
|
condition['duration'] = duration
|
||||||
self.conditions.append(condition)
|
if cond_type == 'timed' and duration == None:
|
||||||
|
print('Error: specified a timed condition with no duration.')
|
||||||
|
return
|
||||||
|
self.conditions[self.next_condition_index] = condition
|
||||||
|
self.next_condition_index += 1
|
||||||
|
|
||||||
|
|
||||||
def end_turn(self):
|
def end_turn(self):
|
||||||
pass # fixme - need to do a lot of stuff with conditions here
|
for (index, c) in self.conditions.items():
|
||||||
|
if c['cond_type'] == 's':
|
||||||
|
r = None
|
||||||
|
if self.pc:
|
||||||
|
print('{}: save against {}.'.format(self, c['name']))
|
||||||
|
r = input_int('saving throw')
|
||||||
|
else:
|
||||||
|
save_die = Dice.from_str('1d20')
|
||||||
|
r = save_die.roll()['total']
|
||||||
|
|
||||||
|
if r >= 10:
|
||||||
|
cond = self.conditions.pop(index)
|
||||||
|
print('{} successfully saved against {}.'.format(self, cond['name']))
|
||||||
|
else:
|
||||||
|
print('{} failed a save against {}.'.format(self, c['name']))
|
||||||
|
|
||||||
|
elif c['cond_type'] == 't':
|
||||||
|
c['duration'] -= 1
|
||||||
|
if c['duration'] < 0:
|
||||||
|
cond = self.conditions.pop(index)
|
||||||
|
print('{} no longer affected by {}.'.format(self, cond['name']))
|
||||||
|
|
||||||
|
# fixme: still need to add recharges
|
||||||
|
|
||||||
|
|
||||||
def damage(self, amount):
|
def damage(self, amount):
|
||||||
|
@ -199,11 +233,18 @@ class Combatant():
|
||||||
if self.temp_hp > 0:
|
if self.temp_hp > 0:
|
||||||
temp_info = ', {} temp hp'.format(self.temp_hp)
|
temp_info = ', {} temp hp'.format(self.temp_hp)
|
||||||
|
|
||||||
return '{} hp{}{}{}'.format(self.hp, temp_info, bloodied, ', '.join([x.name for x in self.conditions]))
|
return '{} hp{}{}{}'.format(self.hp, temp_info, bloodied, ', '.join([x['name'] for x in self.conditions.values()]))
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def format_condition_summary(self):
|
||||||
return "{}: {} ({})".format(self.index, self.name, self.format_health_summary())
|
summary = self.name + ':\n'
|
||||||
|
for (index, c) in conditions.items():
|
||||||
|
type_string = ''
|
||||||
|
if c.cond_type == 's':
|
||||||
|
type_string = 'Save Ends'
|
||||||
|
elif c.cond_type == 't':
|
||||||
|
type_string = '{} Round{}'.format(c.duration, 's'[c.duration==1:])
|
||||||
|
summary = summary + '{}: {} ({})\n'.format(index, c['name'], c['duration'])
|
||||||
|
|
||||||
|
|
||||||
def input_str(prompt, default=None, show_default=False, prompt_str=':'):
|
def input_str(prompt, default=None, show_default=False, prompt_str=':'):
|
||||||
|
@ -409,7 +450,7 @@ def do_prompt():
|
||||||
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':
|
||||||
print('Sorry, this is still a stub function.')
|
do_add_condition()
|
||||||
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':
|
||||||
|
@ -437,6 +478,17 @@ def do_surge(heal=True):
|
||||||
c.use_surge(heal)
|
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')
|
||||||
|
|
||||||
|
c.add_condition(name, ctype, duration)
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user