battleman: Implemented wait/unwait properly, fixed a couple of simple bugs

This commit is contained in:
2012-04-05 17:06:17 -04:00
parent a6d9943856
commit 035d8cba37
2 changed files with 26 additions and 15 deletions

View File

@ -26,7 +26,6 @@ class Battle():
else:
ret = 'Battle not yet started\n\n'
ret = ret + 'Combatants\n==========\n'
ret = ret + self.format_combatants()
return ret
@ -117,7 +116,7 @@ class Battle():
# Returns a formatted string with all of the combatants
def format_combatants(self):
ret = ''
ret = 'Combatants\n==========\n'
for g in self.groups:
if g.is_solo_group():
@ -127,10 +126,16 @@ class Battle():
for c in g.members.values():
ret = ret + ' {}\n'.format(c)
if self.wait_list:
ret = ret + '\nWait List\n=========\n'
for c in self.wait_list.values():
ret = ret + '{}\n'.format(c)
return ret.rstrip()
# Returns a formatted string with just the current group
# fixme: non-solo groups only print indexes...
def format_current_group(self):
if self.validate_started():
return self.validate_started()
@ -145,7 +150,9 @@ class Battle():
return ret.rstrip()
def next_combatant(self):
# Fixme - if someone is waited/unwaited, both them and the person
# after them may have begin_turn() and/or end_turn() called more than once
def next_combatant(self, same_index = False):
if self.validate_started():
print self.validate_started()
return
@ -153,7 +160,8 @@ class Battle():
g = self.get_current_group()
g.end_turn()
self.current += 1
if not same_index:
self.current += 1
if self.current >= len(self.groups):
self.current = 0
@ -182,7 +190,6 @@ class Battle():
return None
# fixme: if removing makes a group empty, nom the group
def wait(self, index):
v = self.validate_started()
if v:
@ -204,6 +211,7 @@ class Battle():
if c:
self.wait_list[index] = c
self.next_combatant(same_index = True)
else:
print 'Error: Failed to find combatant {}'.format(index)
@ -215,7 +223,10 @@ class Battle():
return
if index in self.wait_list:
pass # fixme - fix unwaiting
c = self.wait_list[index]
del self.wait_list[index]
self.groups.insert(self.current, CombatGroup(c.name, {c.index: c}, 0))
self.next_combatant(same_index = True)
else:
if index in self.combatant_hash:
print '{} is not waiting'.format(self.combatant_hash[index])