battleman.py: Added code to remove conditions (not complete yet), improved timed condition logic

This commit is contained in:
Anna Rose 2012-03-23 17:44:06 -04:00
parent 3b064ff717
commit 91d6e23099

View File

@ -128,6 +128,32 @@ class Combatant():
self.next_condition_index += 1 self.next_condition_index += 1
# Removes a condition, prints a message about it, and returns a copy of the condition
def remove_condition(self, index):
if not index in self.conditions:
print "Error: invalid condition index."
return None
c = self.conditions.pop(index)
print('{} is no longer affected by {}.'.format(self, c['name']))
return c
def choose_condition(self):
pass
def format_conditions(self):
pass
def tick_conditions(self):
for c in self.conditions.values():
if c['cond_type'] == 't':
c['duration'] -= 1
def end_turn(self): def end_turn(self):
for (index, c) in self.conditions.items(): for (index, c) in self.conditions.items():
if c['cond_type'] == 's': if c['cond_type'] == 's':
@ -140,16 +166,16 @@ class Combatant():
r = save_die.roll()['total'] r = save_die.roll()['total']
if r >= 10: if r >= 10:
cond = self.conditions.pop(index) self.remove_condition(index)
print('{} successfully saved against {}.'.format(self, cond['name']))
else: else:
print('{} failed a save against {}.'.format(self, c['name'])) print('{} failed a save against {}.'.format(self, c['name']))
elif c['cond_type'] == 't': elif c['cond_type'] == 't':
c['duration'] -= 1 c['duration'] -= 1
if c['duration'] < 0: if c['duration'] < 0:
cond = self.conditions.pop(index) self.remove_condition(index)
print('{} no longer affected by {}.'.format(self, cond['name'])) else:
print('{} is still affected by {} ({} round{} left).'.format(self, c['name'], c['duration']+1, 's'[c['duration']==0:]))
# fixme: still need to add recharges # fixme: still need to add recharges
@ -399,6 +425,11 @@ class Battle():
self.round = 1 self.round = 1
else: else:
self.round += 1 self.round += 1
# Decrement all timed conditions
for c in self.combatant_hash.values():
c.tick_conditions()
print('Beginning round {}'.format(self.round)) print('Beginning round {}'.format(self.round))
@ -467,7 +498,7 @@ def do_prompt():
elif comm == 'c': elif comm == 'c':
do_add_condition(data) do_add_condition(data)
elif comm == 'r': elif comm == 'r':
print('Sorry, this is still a stub function.') do_remove_condition(data)
elif comm == 'n': elif comm == 'n':
battle.next_combatant() battle.next_combatant()
elif comm == 'w': elif comm == 'w':
@ -589,6 +620,26 @@ def do_add_condition(data):
c.add_condition(name, ctype, duration) c.add_condition(name, ctype, duration)
def do_remove_condition(data):
if data:
if len(data) != 2:
print ('Error: wrong number of arguments.')
return
c = battle.get_combatant(int(data[0]))
if not c:
print ('Error: Invalid combatant index.')
return
index = int(data[1])
else:
c = battle.choose_combatant()
index = c.choose_condition()
c.remove_condition(index)
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)