import threading import random from engine import english, primitives class NPC(primitives.Container, primitives.Thing): def __init__(self, name, description): primitives.Container.__init__(self, name, description) primitives.Thing.__init__(self, english.HumanName(name), description) self.messages.update({ "say": "the_$me says: $msg" }) def say(self, msg): self.location.announce(self, self.messages["say"](me=self.name, msg=msg)) primitives.add("NPC", NPC) class QuipsNPC(NPC): def __init__(self, name, description): NPC.__init__(self, name, description) self.vars["quips"] = dict() def tell(self, text): if text in self.vars["quips"]: self.say(self.vars["quips"][text]) return True primitives.add("NPC_QUIPS", QuipsNPC)
if cmd: try: print repr(eval(cmd)) except SyntaxError: try: exec cmd except: traceback.print_exc() except: traceback.print_exc() cmd = game.input(">>> ") game.output(self.messages["deactivate"](me=self.name)) primitives.add("PYTHONSHELL", PythonShell) class ConfigPaper(primitives.Thing): def __init__(self, name, description): primitives.Thing.__init__(self, name, description) @self.add_command("read", "read [@me]") def read(): game.output("The paper says:") game.output("=== Config ===") for section in app.config.sections(): game.output("\n[%s]" % section) for key, value in app.config.items(section): game.output("%s.%s: %s" % (section, key, value)) @self.add_command("change", "(?:change|set) [@thing](?: on [@me])?")
"eat=Nice going, now you have blue insides. Kind of like Kool-Aid." "talk=Oh, this is just sad." "kick=You have a blue foot." } """ class Hero(primitives.Player): def __init__(self, name, description): primitives.Player.__init__(self, name, description) @self.add_command("talk", "talk$") def talk(): game.output("You talk to yourself.") primitives.add("HERO", Hero) # More detailed generic class class Thingy(primitives.Thing): def __init__(self, name, description): primitives.Thing.__init__(self, name, description) self.messages.update({ "eat": "Try as you might, you cannot eat that.", "kick": "You kick the_$thing.", "talk": "Why are you talking to a $thing?" }) @self.add_command("eat", "eat [@me]") def eat(): game.output(self.messages["eat"])