Ejemplo n.º 1
0
def main():
    cf = ClientInterfacer()
    loadoutData = readFile("loadout", getLoadoutFilename(cf),
                           default=FILE_SKELETON)

    args = sys.argv[1:]

    if args[0] == "help":
        cf.draw("Usage: %s <cmd> <arguments>" % sys.argv[0])
        cf.draw("Available commands:")
        cf.draw("- current          show current loadout")
        cf.draw("- list             list available loadouts")
        cf.draw("- show  <name>     show a loadout")
        # cf.draw("- set-stashable    edit stashable items") # TODO
        cf.draw("- save  <name>     save current loadout")
        # cf.draw("- equip <name>     equip specified loadout") # TODO
    elif len(args) == 1 and args[0] == "list":
        cf.draw("Available loadouts:")
        for name in sorted(loadoutData["loadouts"].keys()):
            cf.draw("- %s" % name)
    elif len(args) == 1 and args[0] == "current":
        currentLoadout = getCurrentLoadout(cf, loadoutData["stashable"])
        cf.draw("Your current loadout is:")
        showLoadout(cf, currentLoadout)
    elif len(args) == 2 and args[0] == "show":
        name = args[1]
        if name in loadoutData["loadouts"]:
            loadout = loadoutData["loadouts"][name]
            cf.draw("Loadout %r consists of wearing:" % name)
            showLoadout(cf, loadout)
        else:
            cf.drawError("No such loadout %r" % name)
    elif len(args) == 1 and args[0] == "set-stashable":
        cf.fatal("Not implemented.") # TODO: Interactively edit stashable list
    elif len(args) == 2 and args[0] == "save":
        saveLoadout(cf, args[1], loadoutData)
    elif len(args) == 2 and args[0] == "equip":
        cf.fatal("Not implemented.") # TODO: Equip a loadout
    elif len(args) == 1:
        # Assume "equip".
        cf.fatal("Not implemented.") # TODO: Equip a loadout
    else:
        cf.fatal("Unable to parse command line. Try 'help'.")
Ejemplo n.º 2
0
cf = ClientInterfacer(targetPendingCommands=100)

cf.draw("scripttell me the tag of an item to use for the test.")
cf.waitForScripttell()
s = cf.getNextScripttell()
tag = int(s)

testItem = None
for item in cf.getInventory():
    if item.tag == tag:
        testItem = item
        break

if testItem is None:
    cf.fatal("Couldn't find item with tag %d" % tag)

dropCmd   = cf.getDropCommand(testItem)
pickupCmd = cf.getPickupCommand(testItem)
for i in range(20):
    # We set targetPendingCommands high enough that these will all dispatch
    # immediately.
    cf.queueCommand(dropCmd)
    cf.queueCommand(pickupCmd)
cf.queueCommand("east")
cf._sendToClient("sync 6")

# Fall back to passthru.py.
while 1:
    s = cf._readLineFromClient()
    cf.draw("recv: '%s'" % (s))
Ejemplo n.º 3
0
"""
Repeatedly drop and pick up a selected item, to show that the timing is
reasonable. (Recommend running in DEBUG mode for a better test.)
"""

import sys

from lib.client_interfacer import ClientInterfacer, Command
from lib.recipe import runCommandSequence

cf = ClientInterfacer()

if len(sys.argv) != 2:
    cf.fatal("Usage: %s TAG" % sys.argv[0])

try:
    tag = int(sys.argv[1])
except:
    cf.fatal("%r: invalid tag (must be an integer)." % (sys.argv[1]))

# Search inventory for matching tag.
itemToMove = None
inv = cf.getInventory()
for item in inv:
    if item.tag == tag:
        itemToMove = item
        break
if itemToMove is None:
    cf.fatal("Could not find item in inventory with tag %d." % (tag))

commands = [cf.getDropCommand(itemToMove),
Ejemplo n.º 4
0
# To be safe, first unready any rod that may be readied.
cf.execCommand("apply -u rod")

# This regex is used to check which items are rods of identify. The expected
# name is "Rod of Knowledge of identify (lvl 20)", but this should match
# anything that's a rod of identify.
identRodRE = re.compile(r"(heavy )?rod.* of identify \(.*",
                        flags=re.IGNORECASE)

# Now make a list of all the rods of identify in the player's inventory.
identRods = []
inv = cf.getInventory()
for item in inv:
    if identRodRE.match(item.name):
        if item.applied:
            cf.fatal("Item %r already applied." % item.name)
        identRods.append(item)

commands = []
for identRod in identRods:
    commands.append(cf.getApplyCommand(identRod))
    commands.append("stay fire")

# TODO: Add support to ClientInterfacer for keeping track of inputs matching
# arbitrary prefixes. Watch drawinfo. Write our own loop, which (in addition to
# watching for scripttells) watches for a line like:
#     watch drawinfo ___ You can't reach anything unidentified.
# Once we see that, drop queued commands, flush pending commands, then exit.
loopCommands(commands, cf=cf)