45 from CFDialog
import DialogRule, Dialog, IncludeRule
49 location =
"defaultdialognamespace"
54 for filenm
in filename:
56 filepath = os.path.join(Crossfire.DataDirectory(),
57 Crossfire.MapDirectory(), filenm[1:])
59 filepath = os.path.join(relpath, filenm)
61 filepath = os.path.join(Crossfire.DataDirectory(),
62 Crossfire.MapDirectory(), relpath, filenm)
64 f =
open(filepath,
'rb')
66 Crossfire.Log(Crossfire.LogDebug,
"Error loading NPC dialog %s" % filepath)
69 Crossfire.Log(Crossfire.LogDebug,
"Loading NPC dialog %s" % filepath)
70 params = cjson.decode(f.read())
72 if "location" in params:
73 location = params[
"location"]
74 for jsonRule
in params[
"rules"]:
75 if "include" in jsonRule:
78 incldialog =
Dialog(player, npc, location)
81 shouldinclude = incldialog.matchConditions(inclrule)
84 newfiles = jsonRule[
"include"]
85 if shouldinclude == 1:
88 parameters.extend(
parseJSON(newfiles, os.path.dirname(filepath)))
90 Crossfire.Log(Crossfire.LogDebug,
"Ignoring NPC dialog from %s, conditions not met" % newfiles)
92 parameters.append(jsonRule)
95 npc = Crossfire.WhoAmI()
97 player = Crossfire.WhoIsActivator()
98 if (Crossfire.ScriptParameters() !=
None):
99 filename = Crossfire.ScriptParameters()
104 for jsonRule
in dialogs:
106 if 'replies' in jsonRule:
107 replies = jsonRule[
'replies']
113 speech.addRule(rule, index)
116 if speech.speak(Crossfire.WhatIsMessage()) == 0:
118 Crossfire.WhoAmI().WriteKey(
'talked_to',
str(random.randint(3, 8)), 1)
119 Crossfire.SetReturnValue(1)