battleman.py: Added code to remove conditions (not complete yet), improved timed condition logic
This commit is contained in:
parent
3b064ff717
commit
91d6e23099
61
battleman.py
61
battleman.py
|
@ -127,6 +127,32 @@ class Combatant():
|
|||
self.conditions[self.next_condition_index] = condition
|
||||
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):
|
||||
for (index, c) in self.conditions.items():
|
||||
|
@ -140,16 +166,16 @@ class Combatant():
|
|||
r = save_die.roll()['total']
|
||||
|
||||
if r >= 10:
|
||||
cond = self.conditions.pop(index)
|
||||
print('{} successfully saved against {}.'.format(self, cond['name']))
|
||||
self.remove_condition(index)
|
||||
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']))
|
||||
self.remove_condition(index)
|
||||
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
|
||||
|
||||
|
@ -399,6 +425,11 @@ class Battle():
|
|||
self.round = 1
|
||||
else:
|
||||
self.round += 1
|
||||
|
||||
# Decrement all timed conditions
|
||||
for c in self.combatant_hash.values():
|
||||
c.tick_conditions()
|
||||
|
||||
print('Beginning round {}'.format(self.round))
|
||||
|
||||
|
||||
|
@ -467,7 +498,7 @@ def do_prompt():
|
|||
elif comm == 'c':
|
||||
do_add_condition(data)
|
||||
elif comm == 'r':
|
||||
print('Sorry, this is still a stub function.')
|
||||
do_remove_condition(data)
|
||||
elif comm == 'n':
|
||||
battle.next_combatant()
|
||||
elif comm == 'w':
|
||||
|
@ -589,6 +620,26 @@ def do_add_condition(data):
|
|||
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():
|
||||
print("""Possible commands:
|
||||
? - print this help menu (yay, you already figured that one out)
|
||||
|
|
Loading…
Reference in New Issue
Block a user