battleman.py: Added a feature to conditions that allows them to end at the start of a turn or the end of a turn

This commit is contained in:
Anna Rose 2012-03-25 01:08:56 -04:00 committed by Anna Wiggins
parent 593c9d2937
commit 1da238be5a

View File

@ -18,7 +18,6 @@ import sys
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
@ -77,13 +76,10 @@ class CombatGroup():
def begin_turn(self):
msg = None
if self.is_solo_group():
msg = '{} has initiative.'.format(self.name)
else:
msg = '{} have initiative.'.format(self.name)
print '{} {} initiative.'.format(self.name, ['has', 'have'][len(self.members) != 1])
print msg
for c in self.members:
c.begin_turn()
def end_turn(self):
@ -117,11 +113,12 @@ class Combatant():
# 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):
def add_condition(self, name, cond_type, duration=None, end_type='e'):
condition = {}
condition['name'] = name
condition['cond_type'] = cond_type
condition['duration'] = duration
condition['end_type'] = end_type
condition['index'] = self.next_condition_index
if cond_type == 'timed' and duration == None:
print('Error: specified a timed condition with no duration.')
@ -159,8 +156,17 @@ class Combatant():
c['duration'] -= 1
def begin_turn(self):
for c in self.conditions.values():
if c['cond_type'] == 't' and c['end_type'] == 's':
if c['duration'] <= 0:
self.remove_condition(c['index'])
else:
print('{} is still affected by {} ({} round{} left).'.format(self, c['name'], c['duration'], 's'[c['duration']==1:]))
def end_turn(self):
for (index, c) in self.conditions.items():
for c in self.conditions.values():
if c['cond_type'] == 's':
r = None
if self.pc:
@ -171,16 +177,16 @@ class Combatant():
r = save_die.roll()['total']
if r >= 10:
self.remove_condition(index)
self.remove_condition(c['index'])
print('{} successfully saved against {}.'.format(self, c['name']))
else:
print('{} failed a save against {}.'.format(self, c['name']))
elif c['cond_type'] == 't':
c['duration'] -= 1
if c['duration'] < 0:
self.remove_condition(index)
elif c['cond_type'] == 't' and c['end_type'] == 'e':
if c['duration'] <= 0:
self.remove_condition(c['index'])
else:
print('{} is still affected by {} ({} round{} left).'.format(self, c['name'], c['duration']+1, 's'[c['duration']==0:]))
print('{} is still affected by {} ({} round{} left).'.format(self, c['name'], c['duration'], 's'[c['duration']==1:]))
# fixme: still need to add recharges
@ -490,9 +496,8 @@ def do_prompt():
(comm, rdata) = input_str('', default='?', show_default=False, prompt_str='>').partition(' ')[::2]
data = rdata.split(' ')
# To simplify our checks later
if data == ['']:
data = None
data = []
if comm == '?':
do_help()
@ -528,7 +533,6 @@ def do_prompt():
do_wait(data)
elif comm == 'W':
do_unwait(data)
print('Sorry, this is still a stub function.')
elif comm == 'q':
sys.exit(0)
@ -642,6 +646,7 @@ def do_second_wind(data):
def do_add_condition(data):
duration = None
end_type = 'e'
if len(data) >= 1:
c = battle.get_combatant(int(data[0]))
@ -664,7 +669,12 @@ def do_add_condition(data):
else:
duration = input_int('duration')
c.add_condition(name, ctype, duration)
if len(data) >= 5:
end_type = data[4]
else:
end_type = input_str('(s)tart|(e)nd', default='e', show_default=True)
c.add_condition(name, ctype, duration, end_type)
def do_remove_condition(data):