battleman.py: Fixed removing conditions and the condition summary list
This commit is contained in:
parent
91d6e23099
commit
55feb9b55c
32
battleman.py
32
battleman.py
|
@ -11,6 +11,8 @@
|
||||||
# for resuming a battle later
|
# for resuming a battle later
|
||||||
# * an option for passing in multiple files that contain combatant definitions
|
# * an option for passing in multiple files that contain combatant definitions
|
||||||
# * down combatants go into a separate list
|
# * down combatants go into a separate list
|
||||||
|
# * Ability for commands to accept partial data, and continue with selection from there
|
||||||
|
|
||||||
|
|
||||||
from dice import Dice
|
from dice import Dice
|
||||||
import sys
|
import sys
|
||||||
|
@ -121,6 +123,7 @@ class Combatant():
|
||||||
condition['name'] = name
|
condition['name'] = name
|
||||||
condition['cond_type'] = cond_type
|
condition['cond_type'] = cond_type
|
||||||
condition['duration'] = duration
|
condition['duration'] = duration
|
||||||
|
condition['index'] = self.next_condition_index
|
||||||
if cond_type == 'timed' and duration == None:
|
if cond_type == 'timed' and duration == None:
|
||||||
print('Error: specified a timed condition with no duration.')
|
print('Error: specified a timed condition with no duration.')
|
||||||
return
|
return
|
||||||
|
@ -130,7 +133,7 @@ class Combatant():
|
||||||
|
|
||||||
# Removes a condition, prints a message about it, and returns a copy of the condition
|
# Removes a condition, prints a message about it, and returns a copy of the condition
|
||||||
def remove_condition(self, index):
|
def remove_condition(self, index):
|
||||||
if not index in self.conditions:
|
if index not in self.conditions:
|
||||||
print "Error: invalid condition index."
|
print "Error: invalid condition index."
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -141,11 +144,14 @@ class Combatant():
|
||||||
|
|
||||||
|
|
||||||
def choose_condition(self):
|
def choose_condition(self):
|
||||||
pass
|
print self.format_condition_summary()
|
||||||
|
index = input_int('choice')
|
||||||
|
|
||||||
|
if index not in self.conditions:
|
||||||
|
print 'Error: {} is not a valid index'.format(index)
|
||||||
|
return self.choose_condition()
|
||||||
|
|
||||||
def format_conditions(self):
|
return self.conditions[index]
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def tick_conditions(self):
|
def tick_conditions(self):
|
||||||
|
@ -281,14 +287,16 @@ class Combatant():
|
||||||
|
|
||||||
|
|
||||||
def format_condition_summary(self):
|
def format_condition_summary(self):
|
||||||
summary = self.name + ':\n'
|
summary = ''
|
||||||
for (index, c) in conditions.items():
|
for (index, c) in self.conditions.items():
|
||||||
type_string = ''
|
type_string = ''
|
||||||
if c.cond_type == 's':
|
if c['cond_type'] == 's':
|
||||||
type_string = 'Save Ends'
|
type_string = 'Save Ends'
|
||||||
elif c.cond_type == 't':
|
elif c['cond_type'] == 't':
|
||||||
type_string = '{} Round{}'.format(c.duration, 's'[c.duration==1:])
|
type_string = '{} Round{}'.format(c['duration'], 's'[ c['duration']==1: ] )
|
||||||
summary = summary + '{}: {} ({})\n'.format(index, c['name'], c['duration'])
|
summary = summary + '{}: {} ({})\n'.format(index, c['name'], type_string)
|
||||||
|
|
||||||
|
return summary.rstrip()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -341,7 +349,7 @@ class Battle():
|
||||||
def choose_combatant(self):
|
def choose_combatant(self):
|
||||||
print self.format_combatants()
|
print self.format_combatants()
|
||||||
index = input_int('choose combatant')
|
index = input_int('choose combatant')
|
||||||
if index not in self.combatant_hash.keys():
|
if index not in self.combatant_hash:
|
||||||
print 'Error: {} is not a valid index'.format(index)
|
print 'Error: {} is not a valid index'.format(index)
|
||||||
return self.choose_combatant()
|
return self.choose_combatant()
|
||||||
return self.combatant_hash[index]
|
return self.combatant_hash[index]
|
||||||
|
@ -635,7 +643,7 @@ def do_remove_condition(data):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
c = battle.choose_combatant()
|
c = battle.choose_combatant()
|
||||||
index = c.choose_condition()
|
index = c.choose_condition()['index']
|
||||||
|
|
||||||
c.remove_condition(index)
|
c.remove_condition(index)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user