Refactored the talking_npc a little, made the contributed changes work.
This commit is contained in:
parent
849f4bde71
commit
070e4924e9
1 changed files with 81 additions and 76 deletions
|
|
@ -1,122 +1,127 @@
|
||||||
"""
|
"""
|
||||||
Evennia Talkative NPC
|
Evennia Talkative NPC
|
||||||
Contribution - Griatch 2011
|
|
||||||
This is a simple NPC object capable of holding a simple menu-driven
|
Contribution - Griatch 2011, grungies1138, 2016
|
||||||
conversation. Create it by creating an object of typeclass
|
|
||||||
contrib.talking_npc.TalkingNPC, For example using @create:
|
This is a static NPC object capable of holding a simple menu-driven
|
||||||
@create/drop John : contrib.talking_npc.TalkingNPC
|
conversation. It's just meant as an example. Create it by creating an
|
||||||
|
object of typeclass contrib.talking_npc.TalkingNPC, For example using
|
||||||
|
@create:
|
||||||
|
|
||||||
|
@create/drop John : contrib.talking_npc.TalkingNPC
|
||||||
|
|
||||||
Walk up to it and give the talk command to strike up a conversation.
|
Walk up to it and give the talk command to strike up a conversation.
|
||||||
If there are many talkative npcs in the same room you will get to
|
If there are many talkative npcs in the same room you will get to
|
||||||
choose which one's talk command to call (Evennia handles this
|
choose which one's talk command to call (Evennia handles this
|
||||||
automatically).
|
automatically). This use of EvMenu is very simplistic; See EvMenu for
|
||||||
Note that this is only a prototype class, showcasing the uses of the
|
a lot more complex possibilities.
|
||||||
menusystem module. It is NOT a full mob implementation.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from evennia import DefaultObject, CmdSet, default_cmds
|
from evennia import DefaultObject, CmdSet, default_cmds
|
||||||
from evennia.utils.evmenu import EvMenu
|
from evennia.utils.evmenu import EvMenu
|
||||||
|
|
||||||
|
|
||||||
#
|
# Menu implementing the dialogue tree
|
||||||
# The talk command
|
|
||||||
#
|
|
||||||
|
|
||||||
class CmdTalk(default_cmds.MuxCommand):
|
|
||||||
"""
|
|
||||||
talks to an npc
|
|
||||||
Usage:
|
|
||||||
talk
|
|
||||||
This command is only available if a talkative non-player-character (NPC)
|
|
||||||
is actually present. It will strike up a conversation with that NPC
|
|
||||||
and give you options on what to talk about.
|
|
||||||
"""
|
|
||||||
key = "talk"
|
|
||||||
locks = "cmd:all()"
|
|
||||||
help_category = "General"
|
|
||||||
|
|
||||||
def func(self):
|
|
||||||
"Implements the command."
|
|
||||||
|
|
||||||
# self.obj is the NPC this is defined on
|
|
||||||
obj = self.obj
|
|
||||||
|
|
||||||
self.caller.msg("(You walk up and talk to %s.)" % self.obj.key)
|
|
||||||
|
|
||||||
|
|
||||||
# Initiate the menu
|
|
||||||
EvMenu(self.caller, "typeclasses.talking_npc",
|
|
||||||
startnode="menu_start_node")
|
|
||||||
|
|
||||||
|
|
||||||
def menu_start_node(caller):
|
def menu_start_node(caller):
|
||||||
text = "Hello there, how can I help you?"
|
text = "'Hello there, how can I help you?'"
|
||||||
|
|
||||||
options = ({"desc": "Hey, do you know what this 'Evennia' thing is all about?",
|
options = ({"desc": "Hey, do you know what this 'Evennia' thing is all about?",
|
||||||
"goto": "info1"},
|
"goto": "info1"},
|
||||||
{"desc": "What's your name, little NPC?",
|
{"desc": "What's your name, little NPC?",
|
||||||
"goto": "info2"})
|
"goto": "info2"})
|
||||||
|
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
def info1(caller):
|
def info1(caller):
|
||||||
text = "Oh, Evennia is where you are right now! Don't you feel the power?"
|
text = "'Oh, Evennia is where you are right now! Don't you feel the power?'"
|
||||||
|
|
||||||
options = ({"desc": "Sure, *I* do, not sure how you do though. You are just an NPC.",
|
options = ({"desc": "Sure, *I* do, not sure how you do though. You are just an NPC.",
|
||||||
"goto": "info3"},
|
"goto": "info3"},
|
||||||
{"desc": "Sure I do. What's yer name, NPC?",
|
{"desc": "Sure I do. What's yer name, NPC?",
|
||||||
"goto": "info2"},
|
"goto": "info2"},
|
||||||
{"desc": "Ok, bye for now then."},
|
{"desc": "Ok, bye for now then.",
|
||||||
{"goto": "END"})
|
"goto": "END"})
|
||||||
|
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
def info2(caller):
|
def info2(caller):
|
||||||
text = "My name is not really important ... I'm just an NPC after all."
|
text = "'My name is not really important ... I'm just an NPC after all.'"
|
||||||
|
|
||||||
options = ({"desc": "I didn't really want to know it anyhow.",
|
options = ({"desc": "I didn't really want to know it anyhow.",
|
||||||
"goto": "info3"},
|
"goto": "info3"},
|
||||||
{"desc": "Okay then, so what's this 'Evennia' thing about?",
|
{"desc": "Okay then, so what's this 'Evennia' thing about?",
|
||||||
"goto": "info1"})
|
"goto": "info1"})
|
||||||
|
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
def info3(caller):
|
def info3(caller):
|
||||||
text = "Well ... I'm sort of busy so, have to go. NPC business. Important stuff. You wouldn't understand."
|
text = "'Well ... I'm sort of busy so, have to go. NPC business. Important stuff. You wouldn't understand.'"
|
||||||
|
|
||||||
options = ({"desc": "Oookay ... I won't keep you. Bye.",
|
options = ({"desc": "Oookay ... I won't keep you. Bye.",
|
||||||
"goto": "END"},
|
"goto": "END"},
|
||||||
{"desc": "Wait, why don't you tell me your name first?",
|
{"desc": "Wait, why don't you tell me your name first?",
|
||||||
"goto": "info2"})
|
"goto": "info2"})
|
||||||
|
|
||||||
|
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
def END(caller):
|
def END(caller):
|
||||||
text = "Goodbye, then."
|
text = "'Goodbye, then.'"
|
||||||
|
|
||||||
options = ()
|
options = ()
|
||||||
|
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
#
|
||||||
|
# The talk command (sits on the NPC)
|
||||||
|
#
|
||||||
|
|
||||||
|
class CmdTalk(default_cmds.MuxCommand):
|
||||||
|
"""
|
||||||
|
Talks to an npc
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
talk
|
||||||
|
|
||||||
|
This command is only available if a talkative non-player-character
|
||||||
|
(NPC) is actually present. It will strike up a conversation with
|
||||||
|
that NPC and give you options on what to talk about.
|
||||||
|
"""
|
||||||
|
key = "talk"
|
||||||
|
locks = "cmd:all()"
|
||||||
|
help_category = "General"
|
||||||
|
|
||||||
|
def func(self):
|
||||||
|
"Implements the command."
|
||||||
|
|
||||||
|
# self.obj is the NPC this is defined on
|
||||||
|
self.caller.msg("(You walk up and talk to %s.)" % self.obj.key)
|
||||||
|
|
||||||
|
# Initiate the menu. Change this if you are putting this on
|
||||||
|
# some other custom NPC class.
|
||||||
|
EvMenu(self.caller, "evennia.contrib.talking_npc",
|
||||||
|
startnode="menu_start_node")
|
||||||
|
|
||||||
|
|
||||||
class TalkingCmdSet(CmdSet):
|
class TalkingCmdSet(CmdSet):
|
||||||
"Stores the talk command."
|
"Stores the talk command."
|
||||||
key = "talkingcmdset"
|
key = "talkingcmdset"
|
||||||
|
|
||||||
def at_cmdset_creation(self):
|
def at_cmdset_creation(self):
|
||||||
"populates the cmdset"
|
"populates the cmdset"
|
||||||
self.add(CmdTalk())
|
self.add(CmdTalk())
|
||||||
|
|
||||||
|
|
||||||
class TalkingNPC(DefaultObject):
|
class TalkingNPC(DefaultObject):
|
||||||
"""
|
"""
|
||||||
This implements a simple Object using the talk command and using the
|
This implements a simple Object using the talk command and using
|
||||||
conversation defined above.
|
the conversation defined above.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def at_object_creation(self):
|
def at_object_creation(self):
|
||||||
"This is called when object is first created."
|
"This is called when object is first created."
|
||||||
self.db.desc = "This is a talkative NPC."
|
self.db.desc = "This is a talkative NPC."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue