Commit 86e8da4b authored by Constantin's avatar Constantin
Browse files

much npc stuff

parent bd114a25
......@@ -147,3 +147,18 @@ class Labyrinth:
field = thing.field
def tell(self,teller,verb,message):
sourceField = teller.field
receivers = []
for neighborField in [sourceField.neighbor(dy,dx) for dy,dx in directions.values()]:
for thing in neighborField.things:
if thing is teller:
for admin in
if hasattr(teller,'uid'):
admin.send("player {0} {1}s: {2}".format(teller.uid, verb, message))
admin.send("{0} {1}s: {2}".format(str(teller), verb, message))
\ No newline at end of file
from thing import Thing
import random
class Npc (Thing):
class DialogLevel:
def __init__(self, notunderstandable=None):
if notunderstandable is None:
notunderstandable = ["I don't quite understand you.","What do you mean?","Excuse me?","Can you re-phrase that?"]
self.notunderstandable = notunderstandable
def analyzeComeWithMe(self, teller, verb, message):
return ("say", "No, I won't join you.", None)
def analyzeLetPass(self, teller, verb, message):
return ("say", "I won't let you pass so easily.", None)
def checkStandardRequests(self, teller, verbbbb, message):
# if you overwrite this, call super first. You should only do something different if it returns None
msg = message.lower()
if ("come" in msg or "join" in msg or "protect" in msg or "help" in msg) and "me" in msg:
return self.analyzeComeWithMe(teller, verb, message)
elif ("let me" in msg and ("pass" in msg or "through" in msg or "go" in msg))
or ("away" in msg):
return self.analyzeLetPass(teller, verb, message)
return None
def analyzeAnswer(self, teller, verb, message):
# return
# 1. what should be said, if None: do not react
# 2. the saying verb (say, shout...) if saying anything
# 3. a new DialogLevel instance for further use if you want change
resp = self.checkStandardRequests(teller,verb,message)
if resp is None: # didn't understand
return ("say",random.choice(self.notunderstandable),None)
def __init__ (self, game, greetings, initialDialogLevel):
self.greetings = greetings
assert isinstance(initialDialogLevel,Npc.DialogLevel)
self.currentDialogLevel = initialDialogLevel
def tell(self, teller, verb, message):
newmsg, newverb, newdialvl = self.currentDialogLevel.analyzeAnswer(teller, verb, message)
if newdialvl is not None:
assert isinstance(newdialvl,Npc.DialogLevel)
self.currentDialogLevel = newdialvl
assert (newmsg is None) == (newverb is None)
if newmsg is not None:, newverb, newmsg)
teller.tell(self, "does not react", "")
......@@ -4,9 +4,14 @@ import treasure
from labyrinth import directions as directionOffsets
from labyrinth import directions_inv as directions_t
import random
from wall import Wall
from npc import Npc
goVerbs = ['go', 'walk', 'run', 'stroll']
sayVerbs = ['say', 'talk', 'scream', 'whisper']
normalSayVerbs = ['say', 'talk', 'whisper']
loadSayVerbs = ['scream', 'shout', ]
askingSayVerbs = ['request','appeal','plead','beg','ask','bid']
sayVerbs = normalSayVerbs+loadSayVerbs+askingSayVerbs
announceVerbs = ['announce']
leaveVerbs = ['leave', 'quit', 'exit', 'suicide']
grabVerbs = ['grab', 'get', 'investigate', 'examine', 'check', 'pick', 'pickup']
......@@ -30,9 +35,8 @@ playerUID = 0
class Player(Thing):
def __init__(self, game, conn):
global playerUID
self.buffer = b"" = game
self.conn = conn
self.uid = playerUID
self.obstinacy = 0
......@@ -142,19 +146,16 @@ class Player(Thing):
elif verb in sayVerbs:
msg = " ".join(words[1:])
someoneClose = False
for dx, dy in directionOffsets.values():
for thing in self.field.neighbor(dx=dx, dy=dy).things:
assert thing != self
if isinstance(thing, Player):
someoneClose = True
thing.send("You hear someone saying: "+msg)
for admin in
admin.send("{0} says: {1}".format(self.uid, msg))
receivers =,verb,msg)
someoneClose = any(isinstance(thing,Player) or isinstance(thing,Npc) for thing in receivers)
if someoneClose:
self.send("You say: "+msg)
self.send("You want to say something, but then you realize nobody's caring anyway. Get over it!")
wallClose = any(isinstance(thing,Wall) for thing in receivers)
if wallClose:
self.send("You are talking to the walls. This is usually not very effective.")
self.send("You want to say something, but then you realize nobody's caring anyway. Get over it!")
elif verb in leaveVerbs:
self.send("Good Bye!")
......@@ -186,11 +187,14 @@ class Player(Thing):
msg = " ".join(words[1:])
for player in
player.send("Though Hearest A Voice Sayin': "+msg)
player.send("Though hearest a godly voice sayin': "+msg)
self.send("Who Do Though Think Though Are?")
self.send("Only gods can do that")
self.send("I don't know what you are talking about")
self.send("I don't know what you are talking about.\nWhat do you want to do?")
def tell(self, teller, verb, message):
self.send("You hear someone %s: \"%s\"" % (verb,message))
def afterMove(self, oldField):
desc =
class Thing():
def __init__(self):
def __init__(self, game):
self.field = None = game
def onMove(self, newField):
return True
......@@ -11,5 +12,8 @@ class Thing():
def blocksMove(self):
return False
def tell(self,teller,verb,message):
def __repr__(self):
return "?"
from thing import Thing
class Wall(Thing):
def __init__(self):
def __init__(self,game):
def onMove(self, newField):
return False
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment