129 def __init__(self, keywords, presemaphores, messages, postsemaphores, suggested_response = None):
149 r = random.randint(0, l - 1)
181 DialogRule.__init__(self,
None, presemaphores,
None,
None,
None )
198 self.
__rules.insert(index, rule)
213 if self.
__character.DungeonMaster
and msg ==
'resetdialog':
215 Crossfire.NPCSay(self.
__speaker,
"Dialog state reset!")
220 if key
in Crossfire.GetPrivateDictionary():
221 replies = Crossfire.GetPrivateDictionary()[key]
222 Crossfire.GetPrivateDictionary()[key] =
None
225 if self.
isAnswer(msg, rule.getKeyword()) == 1:
227 message = rule.getMessage()
228 message = message.replace(
'$me', self.
__speaker.QueryName())
229 message = message.replace(
'$you', self.
__character.QueryName())
231 Crossfire.NPCSay(self.
__speaker, message)
232 if rule.getSuggests() !=
None:
233 for reply
in rule.getSuggests():
234 Crossfire.AddReply(reply[0], reply[1])
235 Crossfire.GetPrivateDictionary()[key] = rule.getSuggests()
240 for reply
in replies:
242 type = Crossfire.ReplyType.SAY
245 Crossfire.SetPlayerMessage(reply[1], type)
259 for ckey
in keywords:
260 if ckey ==
"*" or msg.lower().find(ckey.lower()) != -1:
273 for condition
in rule.getPreconditions():
274 action = condition[0]
276 script_args = {
'args': args,
'character': character,
'location': location,
'action': action,
'self': self,
'verdict': verdict}
277 path = os.path.join(Crossfire.DataDirectory(), Crossfire.MapDirectory(),
'python/dialog/pre/', action +
'.py')
278 if os.path.isfile(path):
280 exec(
open(path).read(), {}, script_args)
281 verdict = script_args[
'verdict']
282 except Exception
as ex:
283 Crossfire.Log(Crossfire.LogError,
"CFDialog: Failed to evaluate condition %s: %s." % (condition,
str(ex)))
288 Crossfire.Log(Crossfire.LogError,
"CFDialog: Pre Block called with unknown action %s." % action)
291 if rule.getPreFunction() !=
None:
292 if rule.getPreFunction()(self.
__character, rule) !=
True:
303 for condition
in rule.getPostconditions():
304 Crossfire.Log(Crossfire.LogDebug,
"CFDialog: Trying to apply %s." % condition)
305 action = condition[0]
307 path = os.path.join(Crossfire.DataDirectory(), Crossfire.MapDirectory(),
'python/dialog/post/', action +
'.py')
308 if os.path.isfile(path):
310 exec(
open(path).read())
312 Crossfire.Log(Crossfire.LogError,
"CFDialog: Failed to set post-condition %s." %condition)
314 Crossfire.Log(Crossfire.LogError,
"CFDialog: Post Block called with unknown action %s." % action)
326 if character_status ==
"":
328 pairs=character_status.split(
";")
331 if subpair[0] == key:
345 if character_status !=
"":
346 pairs = character_status.split(
";")
348 subpair = i.split(
":")
349 if subpair[0] == key:
353 finished = finished+
";"
354 finished = finished + subpair[0] +
":" + subpair[1]
357 finished = finished +
";"
358 finished = finished + key +
":" + value
370 pairs=npc_status.split(
";")
373 if subpair[0] == key:
389 pairs = npc_status.split(
";")
391 subpair = i.split(
":")
392 if subpair[0] == key:
396 finished = finished+
";"
397 finished = finished + subpair[0] +
":" + subpair[1]
400 finished = finished +
";"
401 finished = finished + key +
":" + value