From 0d07667c5075f4aecd40906f83b3bf3a78a33a03 Mon Sep 17 00:00:00 2001 From: ryo_saeba Date: Mon, 10 May 2010 17:50:57 +0000 Subject: [PATCH] Add a 'prefunction' to rules to have special processing. git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@13163 282e977c-c81d-0410-88c4-b93c2d0d6712 --- python/CFDialog.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/CFDialog.py b/python/CFDialog.py index 3d9640f80..c5ac859a9 100644 --- a/python/CFDialog.py +++ b/python/CFDialog.py @@ -132,6 +132,7 @@ class DialogRule: self.__messages = messages self.__postsems = postsemaphores self.__suggestions = suggested_response + self.__prefunction = None # The keyword is a string. Multiple keywords may be defined in the string # by delimiting them with vertical bar (|) characters. "*" is a special @@ -165,6 +166,14 @@ class DialogRule: def getSuggests(self): return self.__suggestions + # Return a possible pre function, that will be called to ensure the rule matches. + def getPreFunction(self): + return self.__prefunction + + # Define a prefunction that will be called to match the rule. + def setPreFunction(self, function): + self.__prefunction = function + # This is a subclass of the generic dialog rule that we use for determining whether to # 'include' additional rules. class IncludeRule(DialogRule): @@ -270,6 +279,10 @@ class Dialog: else: Crossfire.Log(Crossfire.LogError, "CFDialog: Pre Block called with unknown action %s." % action) return 0 + + if rule.getPreFunction() != None: + if rule.getPreFunction()(self.__character, rule) != True: + return 0 return 1