battleman: Implemented wait/unwait properly, fixed a couple of simple bugs
This commit is contained in:
parent
a6d9943856
commit
035d8cba37
18
battleman.py
18
battleman.py
|
@ -14,7 +14,7 @@ sys.path.append('lib/')
|
||||||
|
|
||||||
import shelve
|
import shelve
|
||||||
import argparse
|
import argparse
|
||||||
import cmd
|
from cmd import Cmd
|
||||||
import os.path
|
import os.path
|
||||||
import battle
|
import battle
|
||||||
from battle import CombatGroup
|
from battle import CombatGroup
|
||||||
|
@ -89,11 +89,11 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CommandParser(cmd.Cmd):
|
class CommandParser(Cmd):
|
||||||
"""Parse the commands from the command-line."""
|
"""Parse the commands from the command-line."""
|
||||||
|
|
||||||
def __init__(self, btl, session):
|
def __init__(self, btl, session):
|
||||||
cmd.Cmd.__init__(self)
|
Cmd.__init__(self)
|
||||||
|
|
||||||
self.btl = btl
|
self.btl = btl
|
||||||
self.session = session
|
self.session = session
|
||||||
|
@ -116,25 +116,25 @@ class CommandParser(cmd.Cmd):
|
||||||
# This allows us to do partial command completion without <tab>,
|
# This allows us to do partial command completion without <tab>,
|
||||||
# as long as
|
# as long as
|
||||||
def default(self, line):
|
def default(self, line):
|
||||||
cmd, data, line = self.parseline(line)
|
comm, data, line = self.parseline(line)
|
||||||
cmds = self.completenames(cmd)
|
cmds = self.completenames(comm)
|
||||||
num_cmds = len(cmds)
|
num_cmds = len(cmds)
|
||||||
if num_cmds == 1:
|
if num_cmds == 1:
|
||||||
getattr(self, 'do_'+cmds[0])(data)
|
getattr(self, 'do_'+cmds[0])(data)
|
||||||
elif num_cmds > 1:
|
elif num_cmds > 1:
|
||||||
sys.stdout.write('Error: Ambiguous command: {}'.format(cmd))
|
sys.stdout.write('Error: Ambiguous command: {}'.format(comm))
|
||||||
else:
|
else:
|
||||||
print 'Error: Unrecognized command {}'.format(cmd)
|
print 'Error: Unrecognized command {}'.format(comm)
|
||||||
|
|
||||||
|
|
||||||
# We are overriding do_help to avoid printing info about
|
# We are overriding do_help to avoid printing info about
|
||||||
# undocumented commands
|
# undocumented commands
|
||||||
def do_help(self, arg):
|
def do_help(self, arg):
|
||||||
if arg:
|
if arg:
|
||||||
Cmd.cmd.do_help(arg)
|
Cmd.do_help(self, arg)
|
||||||
else:
|
else:
|
||||||
# Everything from here to the end is lifted straight
|
# Everything from here to the end is lifted straight
|
||||||
# out of Cmd.cmd.do_help()
|
# out of cmd.Cmd.do_help()
|
||||||
names = self.get_names()
|
names = self.get_names()
|
||||||
cmds_doc = []
|
cmds_doc = []
|
||||||
cmds_undoc = []
|
cmds_undoc = []
|
||||||
|
|
|
@ -26,7 +26,6 @@ class Battle():
|
||||||
else:
|
else:
|
||||||
ret = 'Battle not yet started\n\n'
|
ret = 'Battle not yet started\n\n'
|
||||||
|
|
||||||
ret = ret + 'Combatants\n==========\n'
|
|
||||||
ret = ret + self.format_combatants()
|
ret = ret + self.format_combatants()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
@ -117,7 +116,7 @@ class Battle():
|
||||||
|
|
||||||
# Returns a formatted string with all of the combatants
|
# Returns a formatted string with all of the combatants
|
||||||
def format_combatants(self):
|
def format_combatants(self):
|
||||||
ret = ''
|
ret = 'Combatants\n==========\n'
|
||||||
|
|
||||||
for g in self.groups:
|
for g in self.groups:
|
||||||
if g.is_solo_group():
|
if g.is_solo_group():
|
||||||
|
@ -127,10 +126,16 @@ class Battle():
|
||||||
for c in g.members.values():
|
for c in g.members.values():
|
||||||
ret = ret + ' {}\n'.format(c)
|
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()
|
return ret.rstrip()
|
||||||
|
|
||||||
|
|
||||||
# Returns a formatted string with just the current group
|
# Returns a formatted string with just the current group
|
||||||
|
# fixme: non-solo groups only print indexes...
|
||||||
def format_current_group(self):
|
def format_current_group(self):
|
||||||
if self.validate_started():
|
if self.validate_started():
|
||||||
return self.validate_started()
|
return self.validate_started()
|
||||||
|
@ -145,7 +150,9 @@ class Battle():
|
||||||
return ret.rstrip()
|
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():
|
if self.validate_started():
|
||||||
print self.validate_started()
|
print self.validate_started()
|
||||||
return
|
return
|
||||||
|
@ -153,7 +160,8 @@ class Battle():
|
||||||
g = self.get_current_group()
|
g = self.get_current_group()
|
||||||
g.end_turn()
|
g.end_turn()
|
||||||
|
|
||||||
self.current += 1
|
if not same_index:
|
||||||
|
self.current += 1
|
||||||
|
|
||||||
if self.current >= len(self.groups):
|
if self.current >= len(self.groups):
|
||||||
self.current = 0
|
self.current = 0
|
||||||
|
@ -182,7 +190,6 @@ class Battle():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# fixme: if removing makes a group empty, nom the group
|
|
||||||
def wait(self, index):
|
def wait(self, index):
|
||||||
v = self.validate_started()
|
v = self.validate_started()
|
||||||
if v:
|
if v:
|
||||||
|
@ -204,6 +211,7 @@ class Battle():
|
||||||
|
|
||||||
if c:
|
if c:
|
||||||
self.wait_list[index] = c
|
self.wait_list[index] = c
|
||||||
|
self.next_combatant(same_index = True)
|
||||||
else:
|
else:
|
||||||
print 'Error: Failed to find combatant {}'.format(index)
|
print 'Error: Failed to find combatant {}'.format(index)
|
||||||
|
|
||||||
|
@ -215,7 +223,10 @@ class Battle():
|
||||||
return
|
return
|
||||||
|
|
||||||
if index in self.wait_list:
|
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:
|
else:
|
||||||
if index in self.combatant_hash:
|
if index in self.combatant_hash:
|
||||||
print '{} is not waiting'.format(self.combatant_hash[index])
|
print '{} is not waiting'.format(self.combatant_hash[index])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user