From cfa5773ef86f58285c4edf865f79df7e343ffe77 Mon Sep 17 00:00:00 2001 From: tchize Date: Sun, 16 Dec 2007 15:15:41 +0000 Subject: [PATCH] Add a simple to use script that make use of NPC dialog git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@7930 282e977c-c81d-0410-88c4-b93c2d0d6712 --- python/CFDialog.py | 1 + python/misc/npc_dialog.py | 70 ++ test/dialog | 1599 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1670 insertions(+) create mode 100644 python/misc/npc_dialog.py create mode 100644 test/dialog diff --git a/python/CFDialog.py b/python/CFDialog.py index 5215fbbde..4ca14b398 100644 --- a/python/CFDialog.py +++ b/python/CFDialog.py @@ -160,6 +160,7 @@ class Dialog: self.__speaker.Say(rule.getMessage()) self.setConditions(rule) return 0 + return 1 def isAnswer(self,msg, keyword): if keyword=="*": return 1 diff --git a/python/misc/npc_dialog.py b/python/misc/npc_dialog.py new file mode 100644 index 000000000..772f57429 --- /dev/null +++ b/python/misc/npc_dialog.py @@ -0,0 +1,70 @@ +# npc_dialog.py - Dialog helper class +# +# Copyright (C) 2007 David Delbecq +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# +# This is a simple script that make use of CFDialog.py and receive it's +# parameters from a JSON inside the event message +# exemple +#{ +# "location" : "test_grandpa_01", +# "rules": [ +# { +# "match" : "hello|hi", +# "pre" : [["hello","0"]], +# "post" : [["hello","1"]], +# "msg" : ["Hello, lad!","Hi, young fellow!","Howdy!"] +# }, +# { +# "match": "hello|hi", +# "pre" :[["hello","1"]], +# "post" :[["hello", "*"]], +# "msg" : ["I've heard, you know, I'm not deaf *grmbl*"] +# }, +# { +# "match" : "*", +# "pre" : [["hello","*"]], +# "post" : [["hello", "*"]], +# "msg" : ["What ?", "Huh ?", "What do you want ?"] +# } +#]} +# The pre and post in rule are variable to test and set depending on that dialog rule. +# For example, first rule applie if "hello" is set to "0" (default) and immediatly +# sets it to "1" when rule is used. +# the Double [ around pre and post are needed. The pre and post are +# arrays of arrays. Each item in pre and post is an array of [variable,value] +# The match is the rule to apply to what user says + +import Crossfire + +from CFDialog import DialogRule, Dialog + +import cjson +event = Crossfire.WhatIsEvent() +player = Crossfire.WhoIsActivator() +npc = Crossfire.WhoAmI() +parameters = cjson.decode(event.Message) +location = parameters["location"]; +speech = Dialog(player, npc, location) +index=0; + +for jsonRule in parameters["rules"]: + speech.addRule(DialogRule(jsonRule["match"], jsonRule["pre"], jsonRule["msg"], jsonRule["post"]),index) + index=index+1 + +if speech.speak(Crossfire.WhatIsMessage()) == 0: + Crossfire.SetReturnValue(1) diff --git a/test/dialog b/test/dialog new file mode 100644 index 000000000..10c637d05 --- /dev/null +++ b/test/dialog @@ -0,0 +1,1599 @@ +arch map +name dialog +width 20 +height 20 +msg +Created: 2007-12-16 tchize +Modified: 2007-12-16 tchize +endmsg +end +arch grass_only +end +arch grass_only +y 1 +end +arch grass_only +y 2 +end +arch grass_only +y 3 +end +arch grass_only +y 4 +end +arch grass_only +y 5 +end +arch grass_only +y 6 +end +arch grass_only +y 7 +end +arch grass_only +y 8 +end +arch grass_only +y 9 +end +arch grass_only +y 10 +end +arch grass_only +y 11 +end +arch grass_only +y 12 +end +arch grass_only +y 13 +end +arch grass_only +y 14 +end +arch grass_only +y 15 +end +arch grass_only +y 16 +end +arch grass_only +y 17 +end +arch grass_only +y 18 +end +arch grass_only +y 19 +end +arch grass_only +x 1 +end +arch grass_only +x 1 +y 1 +end +arch grass_only +x 1 +y 2 +end +arch grass_only +x 1 +y 3 +end +arch grass_only +x 1 +y 4 +end +arch grass_only +x 1 +y 5 +end +arch grass_only +x 1 +y 6 +end +arch grass_only +x 1 +y 7 +end +arch grass_only +x 1 +y 8 +end +arch grass_only +x 1 +y 9 +end +arch grass_only +x 1 +y 10 +end +arch grass_only +x 1 +y 11 +end +arch grass_only +x 1 +y 12 +end +arch grass_only +x 1 +y 13 +end +arch grass_only +x 1 +y 14 +end +arch grass_only +x 1 +y 15 +end +arch grass_only +x 1 +y 16 +end +arch grass_only +x 1 +y 17 +end +arch grass_only +x 1 +y 18 +end +arch grass_only +x 1 +y 19 +end +arch grass_only +x 2 +end +arch grass_only +x 2 +y 1 +end +arch grass_only +x 2 +y 2 +end +arch grass_only +x 2 +y 3 +end +arch grass_only +x 2 +y 4 +end +arch grass_only +x 2 +y 5 +end +arch grass_only +x 2 +y 6 +end +arch grass_only +x 2 +y 7 +end +arch grass_only +x 2 +y 8 +end +arch grass_only +x 2 +y 9 +end +arch grass_only +x 2 +y 10 +end +arch grass_only +x 2 +y 11 +end +arch grass_only +x 2 +y 12 +end +arch grass_only +x 2 +y 13 +end +arch grass_only +x 2 +y 14 +end +arch grass_only +x 2 +y 15 +end +arch grass_only +x 2 +y 16 +end +arch grass_only +x 2 +y 17 +end +arch grass_only +x 2 +y 18 +end +arch grass_only +x 2 +y 19 +end +arch grass_only +x 3 +end +arch grass_only +x 3 +y 1 +end +arch grass_only +x 3 +y 2 +end +arch grass_only +x 3 +y 3 +end +arch grass_only +x 3 +y 4 +end +arch grass_only +x 3 +y 5 +end +arch grass_only +x 3 +y 6 +end +arch grass_only +x 3 +y 7 +end +arch grass_only +x 3 +y 8 +end +arch grass_only +x 3 +y 9 +end +arch grass_only +x 3 +y 10 +end +arch grass_only +x 3 +y 11 +end +arch grass_only +x 3 +y 12 +end +arch grass_only +x 3 +y 13 +end +arch grass_only +x 3 +y 14 +end +arch grass_only +x 3 +y 15 +end +arch grass_only +x 3 +y 16 +end +arch grass_only +x 3 +y 17 +end +arch grass_only +x 3 +y 18 +end +arch grass_only +x 3 +y 19 +end +arch grass_only +x 4 +end +arch grass_only +x 4 +y 1 +end +arch grass_only +x 4 +y 2 +end +arch grass_only +x 4 +y 3 +end +arch grass_only +x 4 +y 4 +end +arch grass_only +x 4 +y 5 +end +arch grass_only +x 4 +y 6 +end +arch grass_only +x 4 +y 7 +end +arch grass_only +x 4 +y 8 +end +arch grass_only +x 4 +y 9 +end +arch grass_only +x 4 +y 10 +end +arch grass_only +x 4 +y 11 +end +arch grass_only +x 4 +y 12 +end +arch grass_only +x 4 +y 13 +end +arch grass_only +x 4 +y 14 +end +arch grass_only +x 4 +y 15 +end +arch grass_only +x 4 +y 16 +end +arch grass_only +x 4 +y 17 +end +arch grass_only +x 4 +y 18 +end +arch grass_only +x 4 +y 19 +end +arch grass_only +x 5 +end +arch grass_only +x 5 +y 1 +end +arch grass_only +x 5 +y 2 +end +arch grass_only +x 5 +y 3 +end +arch grass_only +x 5 +y 4 +end +arch grass_only +x 5 +y 5 +end +arch grass_only +x 5 +y 6 +end +arch grass_only +x 5 +y 7 +end +arch grass_only +x 5 +y 8 +end +arch grass_only +x 5 +y 9 +end +arch grass_only +x 5 +y 10 +end +arch grass_only +x 5 +y 11 +end +arch grass_only +x 5 +y 12 +end +arch grass_only +x 5 +y 13 +end +arch grass_only +x 5 +y 14 +end +arch grass_only +x 5 +y 15 +end +arch grass_only +x 5 +y 16 +end +arch grass_only +x 5 +y 17 +end +arch grass_only +x 5 +y 18 +end +arch grass_only +x 5 +y 19 +end +arch grass_only +x 6 +end +arch grass_only +x 6 +y 1 +end +arch grass_only +x 6 +y 2 +end +arch grass_only +x 6 +y 3 +end +arch grass_only +x 6 +y 4 +end +arch grass_only +x 6 +y 5 +end +arch grass_only +x 6 +y 6 +end +arch grass_only +x 6 +y 7 +end +arch grass_only +x 6 +y 8 +end +arch grass_only +x 6 +y 9 +end +arch grass_only +x 6 +y 10 +end +arch grass_only +x 6 +y 11 +end +arch grass_only +x 6 +y 12 +end +arch sage +x 6 +y 12 +arch event_say +title Python +slaying /python/misc/npc_dialog.py +msg +{ + "location" : "test_grandpa_01", + "rules": [ + { + "match" : "hello|hi", + "pre" : [["hello","0"]], + "post" : [["hello","1"]], + "msg" : ["Hello, lad!","Hi, young fellow!","Howdy!"] + }, { + "match": "hello|hi", + "pre" :[["hello","1"]], + "post" :[["hello", "*"]], + "msg" : ["I've heard, you know, I'm not deaf *grmbl*"] + } , { + "match" : "*", + "pre" : [["hello","*"]], + "post" : [["hello", "*"]], + "msg" : ["What ?", "Huh ?", "What do you want ?"] + } +]} +endmsg +end +end +arch grass_only +x 6 +y 13 +end +arch grass_only +x 6 +y 14 +end +arch grass_only +x 6 +y 15 +end +arch grass_only +x 6 +y 16 +end +arch grass_only +x 6 +y 17 +end +arch grass_only +x 6 +y 18 +end +arch grass_only +x 6 +y 19 +end +arch grass_only +x 7 +end +arch grass_only +x 7 +y 1 +end +arch grass_only +x 7 +y 2 +end +arch grass_only +x 7 +y 3 +end +arch grass_only +x 7 +y 4 +end +arch grass_only +x 7 +y 5 +end +arch grass_only +x 7 +y 6 +end +arch grass_only +x 7 +y 7 +end +arch grass_only +x 7 +y 8 +end +arch grass_only +x 7 +y 9 +end +arch grass_only +x 7 +y 10 +end +arch grass_only +x 7 +y 11 +end +arch grass_only +x 7 +y 12 +end +arch grass_only +x 7 +y 13 +end +arch grass_only +x 7 +y 14 +end +arch grass_only +x 7 +y 15 +end +arch grass_only +x 7 +y 16 +end +arch grass_only +x 7 +y 17 +end +arch grass_only +x 7 +y 18 +end +arch grass_only +x 7 +y 19 +end +arch grass_only +x 8 +end +arch grass_only +x 8 +y 1 +end +arch grass_only +x 8 +y 2 +end +arch grass_only +x 8 +y 3 +end +arch grass_only +x 8 +y 4 +end +arch grass_only +x 8 +y 5 +end +arch grass_only +x 8 +y 6 +end +arch grass_only +x 8 +y 7 +end +arch grass_only +x 8 +y 8 +end +arch grass_only +x 8 +y 9 +end +arch grass_only +x 8 +y 10 +end +arch grass_only +x 8 +y 11 +end +arch grass_only +x 8 +y 12 +end +arch grass_only +x 8 +y 13 +end +arch grass_only +x 8 +y 14 +end +arch grass_only +x 8 +y 15 +end +arch grass_only +x 8 +y 16 +end +arch grass_only +x 8 +y 17 +end +arch grass_only +x 8 +y 18 +end +arch grass_only +x 8 +y 19 +end +arch grass_only +x 9 +end +arch grass_only +x 9 +y 1 +end +arch grass_only +x 9 +y 2 +end +arch grass_only +x 9 +y 3 +end +arch grass_only +x 9 +y 4 +end +arch grass_only +x 9 +y 5 +end +arch grass_only +x 9 +y 6 +end +arch grass_only +x 9 +y 7 +end +arch grass_only +x 9 +y 8 +end +arch grass_only +x 9 +y 9 +end +arch grass_only +x 9 +y 10 +end +arch grass_only +x 9 +y 11 +end +arch grass_only +x 9 +y 12 +end +arch grass_only +x 9 +y 13 +end +arch grass_only +x 9 +y 14 +end +arch grass_only +x 9 +y 15 +end +arch grass_only +x 9 +y 16 +end +arch grass_only +x 9 +y 17 +end +arch grass_only +x 9 +y 18 +end +arch grass_only +x 9 +y 19 +end +arch grass_only +x 10 +end +arch grass_only +x 10 +y 1 +end +arch grass_only +x 10 +y 2 +end +arch grass_only +x 10 +y 3 +end +arch grass_only +x 10 +y 4 +end +arch grass_only +x 10 +y 5 +end +arch grass_only +x 10 +y 6 +end +arch grass_only +x 10 +y 7 +end +arch grass_only +x 10 +y 8 +end +arch grass_only +x 10 +y 9 +end +arch grass_only +x 10 +y 10 +end +arch grass_only +x 10 +y 11 +end +arch grass_only +x 10 +y 12 +end +arch grass_only +x 10 +y 13 +end +arch grass_only +x 10 +y 14 +end +arch grass_only +x 10 +y 15 +end +arch grass_only +x 10 +y 16 +end +arch grass_only +x 10 +y 17 +end +arch grass_only +x 10 +y 18 +end +arch grass_only +x 10 +y 19 +end +arch grass_only +x 11 +end +arch grass_only +x 11 +y 1 +end +arch grass_only +x 11 +y 2 +end +arch grass_only +x 11 +y 3 +end +arch grass_only +x 11 +y 4 +end +arch grass_only +x 11 +y 5 +end +arch grass_only +x 11 +y 6 +end +arch grass_only +x 11 +y 7 +end +arch grass_only +x 11 +y 8 +end +arch grass_only +x 11 +y 9 +end +arch grass_only +x 11 +y 10 +end +arch grass_only +x 11 +y 11 +end +arch grass_only +x 11 +y 12 +end +arch grass_only +x 11 +y 13 +end +arch grass_only +x 11 +y 14 +end +arch grass_only +x 11 +y 15 +end +arch grass_only +x 11 +y 16 +end +arch grass_only +x 11 +y 17 +end +arch grass_only +x 11 +y 18 +end +arch grass_only +x 11 +y 19 +end +arch grass_only +x 12 +end +arch grass_only +x 12 +y 1 +end +arch grass_only +x 12 +y 2 +end +arch grass_only +x 12 +y 3 +end +arch grass_only +x 12 +y 4 +end +arch grass_only +x 12 +y 5 +end +arch grass_only +x 12 +y 6 +end +arch grass_only +x 12 +y 7 +end +arch grass_only +x 12 +y 8 +end +arch grass_only +x 12 +y 9 +end +arch grass_only +x 12 +y 10 +end +arch grass_only +x 12 +y 11 +end +arch grass_only +x 12 +y 12 +end +arch grass_only +x 12 +y 13 +end +arch grass_only +x 12 +y 14 +end +arch grass_only +x 12 +y 15 +end +arch grass_only +x 12 +y 16 +end +arch grass_only +x 12 +y 17 +end +arch grass_only +x 12 +y 18 +end +arch grass_only +x 12 +y 19 +end +arch grass_only +x 13 +end +arch grass_only +x 13 +y 1 +end +arch grass_only +x 13 +y 2 +end +arch grass_only +x 13 +y 3 +end +arch grass_only +x 13 +y 4 +end +arch grass_only +x 13 +y 5 +end +arch grass_only +x 13 +y 6 +end +arch grass_only +x 13 +y 7 +end +arch grass_only +x 13 +y 8 +end +arch grass_only +x 13 +y 9 +end +arch grass_only +x 13 +y 10 +end +arch grass_only +x 13 +y 11 +end +arch grass_only +x 13 +y 12 +end +arch grass_only +x 13 +y 13 +end +arch grass_only +x 13 +y 14 +end +arch grass_only +x 13 +y 15 +end +arch grass_only +x 13 +y 16 +end +arch grass_only +x 13 +y 17 +end +arch grass_only +x 13 +y 18 +end +arch grass_only +x 13 +y 19 +end +arch grass_only +x 14 +end +arch grass_only +x 14 +y 1 +end +arch grass_only +x 14 +y 2 +end +arch grass_only +x 14 +y 3 +end +arch grass_only +x 14 +y 4 +end +arch grass_only +x 14 +y 5 +end +arch grass_only +x 14 +y 6 +end +arch grass_only +x 14 +y 7 +end +arch grass_only +x 14 +y 8 +end +arch grass_only +x 14 +y 9 +end +arch grass_only +x 14 +y 10 +end +arch grass_only +x 14 +y 11 +end +arch grass_only +x 14 +y 12 +end +arch grass_only +x 14 +y 13 +end +arch grass_only +x 14 +y 14 +end +arch grass_only +x 14 +y 15 +end +arch grass_only +x 14 +y 16 +end +arch grass_only +x 14 +y 17 +end +arch grass_only +x 14 +y 18 +end +arch grass_only +x 14 +y 19 +end +arch grass_only +x 15 +end +arch grass_only +x 15 +y 1 +end +arch grass_only +x 15 +y 2 +end +arch grass_only +x 15 +y 3 +end +arch grass_only +x 15 +y 4 +end +arch grass_only +x 15 +y 5 +end +arch grass_only +x 15 +y 6 +end +arch grass_only +x 15 +y 7 +end +arch grass_only +x 15 +y 8 +end +arch grass_only +x 15 +y 9 +end +arch grass_only +x 15 +y 10 +end +arch grass_only +x 15 +y 11 +end +arch grass_only +x 15 +y 12 +end +arch grass_only +x 15 +y 13 +end +arch grass_only +x 15 +y 14 +end +arch grass_only +x 15 +y 15 +end +arch grass_only +x 15 +y 16 +end +arch grass_only +x 15 +y 17 +end +arch grass_only +x 15 +y 18 +end +arch grass_only +x 15 +y 19 +end +arch grass_only +x 16 +end +arch grass_only +x 16 +y 1 +end +arch grass_only +x 16 +y 2 +end +arch grass_only +x 16 +y 3 +end +arch grass_only +x 16 +y 4 +end +arch grass_only +x 16 +y 5 +end +arch grass_only +x 16 +y 6 +end +arch grass_only +x 16 +y 7 +end +arch grass_only +x 16 +y 8 +end +arch grass_only +x 16 +y 9 +end +arch grass_only +x 16 +y 10 +end +arch grass_only +x 16 +y 11 +end +arch grass_only +x 16 +y 12 +end +arch grass_only +x 16 +y 13 +end +arch grass_only +x 16 +y 14 +end +arch grass_only +x 16 +y 15 +end +arch grass_only +x 16 +y 16 +end +arch grass_only +x 16 +y 17 +end +arch grass_only +x 16 +y 18 +end +arch grass_only +x 16 +y 19 +end +arch grass_only +x 17 +end +arch grass_only +x 17 +y 1 +end +arch grass_only +x 17 +y 2 +end +arch grass_only +x 17 +y 3 +end +arch grass_only +x 17 +y 4 +end +arch grass_only +x 17 +y 5 +end +arch grass_only +x 17 +y 6 +end +arch grass_only +x 17 +y 7 +end +arch grass_only +x 17 +y 8 +end +arch grass_only +x 17 +y 9 +end +arch grass_only +x 17 +y 10 +end +arch grass_only +x 17 +y 11 +end +arch grass_only +x 17 +y 12 +end +arch grass_only +x 17 +y 13 +end +arch grass_only +x 17 +y 14 +end +arch grass_only +x 17 +y 15 +end +arch grass_only +x 17 +y 16 +end +arch grass_only +x 17 +y 17 +end +arch grass_only +x 17 +y 18 +end +arch grass_only +x 17 +y 19 +end +arch grass_only +x 18 +end +arch grass_only +x 18 +y 1 +end +arch grass_only +x 18 +y 2 +end +arch grass_only +x 18 +y 3 +end +arch grass_only +x 18 +y 4 +end +arch grass_only +x 18 +y 5 +end +arch grass_only +x 18 +y 6 +end +arch grass_only +x 18 +y 7 +end +arch grass_only +x 18 +y 8 +end +arch grass_only +x 18 +y 9 +end +arch grass_only +x 18 +y 10 +end +arch grass_only +x 18 +y 11 +end +arch grass_only +x 18 +y 12 +end +arch grass_only +x 18 +y 13 +end +arch grass_only +x 18 +y 14 +end +arch grass_only +x 18 +y 15 +end +arch grass_only +x 18 +y 16 +end +arch grass_only +x 18 +y 17 +end +arch grass_only +x 18 +y 18 +end +arch grass_only +x 18 +y 19 +end +arch grass_only +x 19 +end +arch grass_only +x 19 +y 1 +end +arch grass_only +x 19 +y 2 +end +arch grass_only +x 19 +y 3 +end +arch grass_only +x 19 +y 4 +end +arch grass_only +x 19 +y 5 +end +arch grass_only +x 19 +y 6 +end +arch grass_only +x 19 +y 7 +end +arch grass_only +x 19 +y 8 +end +arch grass_only +x 19 +y 9 +end +arch grass_only +x 19 +y 10 +end +arch grass_only +x 19 +y 11 +end +arch grass_only +x 19 +y 12 +end +arch grass_only +x 19 +y 13 +end +arch grass_only +x 19 +y 14 +end +arch grass_only +x 19 +y 15 +end +arch grass_only +x 19 +y 16 +end +arch grass_only +x 19 +y 17 +end +arch grass_only +x 19 +y 18 +end +arch grass_only +x 19 +y 19 +end