Like the @match system, CFDialog now converts both match strings and things

the player says to lowercase before checking for a match.


git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@10421 282e977c-c81d-0410-88c4-b93c2d0d6712
master
kbulgrien 2008-11-14 01:28:30 +00:00
parent b311c17606
commit 5ca76c340c
1 changed files with 10 additions and 1 deletions

View File

@ -78,6 +78,9 @@
# You can then add the rules you created to the dialog. Rules are parsed in # You can then add the rules you created to the dialog. Rules are parsed in
# a given order, so you must add the most generic answer last. # a given order, so you must add the most generic answer last.
# #
# Like the @match system, CFDialog converts both match strings and the things
# the player says to lowercase before checking for a match.
#
# A simple example # A simple example
#================= #=================
# I want to create a dialog for an old man. If I say "hello" or "hi" for the # I want to create a dialog for an old man. If I say "hello" or "hi" for the
@ -115,6 +118,11 @@
# rmsg = ["What ?", "Huh ?", "What do you want ?"] # rmsg = ["What ?", "Huh ?", "What do you want ?"]
# speech.addRule(DialogRule("*", prer, rmsg, postr),2) # speech.addRule(DialogRule("*", prer, rmsg, postr),2)
# #
# A complete example that shows how to modify an actual in-game map may be
# found on the wiki:
#
# http://wiki.metalforge.net/doku.php/cfdialog?s=cfdialog#a_simple_example
#
import Crossfire import Crossfire
import string import string
import random import random
@ -161,12 +169,13 @@ class Dialog:
self.setConditions(rule) self.setConditions(rule)
return 0 return 0
return 1 return 1
def isAnswer(self,msg, keyword): def isAnswer(self,msg, keyword):
if keyword=="*": if keyword=="*":
return 1 return 1
keys=string.split(keyword,"|") keys=string.split(keyword,"|")
for ckey in keys: for ckey in keys:
if string.find(msg,ckey)!=-1: if string.find(msg.lower(),ckey.lower())!=-1:
return 1 return 1
return 0 return 0