Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hacksaar
Haxotel
Commits
86e8da4b
Commit
86e8da4b
authored
Aug 01, 2014
by
Constantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
much npc stuff
parent
bd114a25
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
19 deletions
+91
-19
labyrinth.py
labyrinth.py
+15
-0
npc.py
npc.py
+49
-0
player.py
player.py
+20
-16
thing.py
thing.py
+5
-1
wall.py
wall.py
+2
-2
No files found.
labyrinth.py
View file @
86e8da4b
...
...
@@ -147,3 +147,18 @@ class Labyrinth:
field
=
thing
.
field
field
.
things
.
remove
(
thing
)
self
.
game
.
showAdmins
()
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
:
continue
receivers
.
append
(
thing
)
thing
.
tell
(
teller
,
verb
,
message
)
for
admin
in
self
.
game
.
admins
:
if
hasattr
(
teller
,
'uid'
):
admin
.
send
(
"player {0} {1}s: {2}"
.
format
(
teller
.
uid
,
verb
,
message
))
else
:
admin
.
send
(
"{0} {1}s: {2}"
.
format
(
str
(
teller
),
verb
,
message
))
\ No newline at end of file
npc.py
0 → 100644
View file @
86e8da4b
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
)
else
:
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
):
super
().
__init__
(
game
)
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
:
self
.
game
.
labyrinth
.
tell
(
self
,
newverb
,
newmsg
)
else
:
teller
.
tell
(
self
,
"does not react"
,
""
)
player.py
View file @
86e8da4b
...
...
@@ -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
super
().
__init__
()
super
().
__init__
(
game
)
self
.
buffer
=
b
""
self
.
game
=
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
self
.
game
.
admins
:
admin
.
send
(
"{0} says: {1}"
.
format
(
self
.
uid
,
msg
))
receivers
=
self
.
game
.
labyrinth
.
tell
(
self
,
verb
,
msg
)
someoneClose
=
any
(
isinstance
(
thing
,
Player
)
or
isinstance
(
thing
,
Npc
)
for
thing
in
receivers
)
if
someoneClose
:
self
.
send
(
"You say: "
+
msg
)
else
:
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."
)
else
:
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!"
)
self
.
game
.
removePlayer
(
self
)
...
...
@@ -186,11 +187,14 @@ class Player(Thing):
if
self
.
game
.
isAdmin
(
self
):
msg
=
" "
.
join
(
words
[
1
:])
for
player
in
self
.
game
.
players
:
player
.
send
(
"Though
H
earest
A V
oice
S
ayin': "
+
msg
)
player
.
send
(
"Though
h
earest
a godly v
oice
s
ayin': "
+
msg
)
else
:
self
.
send
(
"
Who Do Though Think Though Are?
"
)
self
.
send
(
"
Only gods can do that
"
)
else
:
self
.
send
(
"I don't know what you are talking about"
)
self
.
send
(
"I don't know what you are talking about.
\n
What 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
=
self
.
game
.
labyrinth
.
getDescription
(
self
)
...
...
thing.py
View file @
86e8da4b
class
Thing
():
def
__init__
(
self
):
def
__init__
(
self
,
game
):
self
.
field
=
None
self
.
game
=
game
def
onMove
(
self
,
newField
):
return
True
...
...
@@ -11,5 +12,8 @@ class Thing():
def
blocksMove
(
self
):
return
False
def
tell
(
self
,
teller
,
verb
,
message
):
pass
def
__repr__
(
self
):
return
"?"
wall.py
View file @
86e8da4b
from
thing
import
Thing
class
Wall
(
Thing
):
def
__init__
(
self
):
super
().
__init__
()
def
__init__
(
self
,
game
):
super
().
__init__
(
game
)
def
onMove
(
self
,
newField
):
return
False
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment