Add 'resetdialog' for DMs to reset dialog state

Help DMs test and debug dialogs by adding a hidden 'resetdialog' match
that resets per-character dialog state.
master
Kevin Zheng 2021-07-24 18:08:45 -07:00
parent 992f33dc25
commit 18abd151e1
1 changed files with 13 additions and 6 deletions

View File

@ -210,6 +210,11 @@ class Dialog:
if self.__speaker.Event(self.__speaker, self.__speaker, "query_object_is_animated", 1): if self.__speaker.Event(self.__speaker, self.__speaker, "query_object_is_animated", 1):
return 0 return 0
if self.__character.DungeonMaster and msg == 'resetdialog':
self.__character.WriteKey(self.keyName(), "", 0)
Crossfire.NPCSay(self.__speaker, "Dialog state reset!")
return 0
key = self.uniqueKey() key = self.uniqueKey()
replies = None replies = None
if key in Crossfire.GetPrivateDictionary(): if key in Crossfire.GetPrivateDictionary():
@ -308,6 +313,8 @@ class Dialog:
else: else:
Crossfire.Log(Crossfire.LogError, "CFDialog: Post Block called with unknown action %s." % action) Crossfire.Log(Crossfire.LogError, "CFDialog: Post Block called with unknown action %s." % action)
def keyName(self):
return "dialog_" + self.__location
# Search the player file for a particular flag, and if it exists, return # Search the player file for a particular flag, and if it exists, return
# its value. Flag names are combined with the unique dialog "location" # its value. Flag names are combined with the unique dialog "location"
@ -315,7 +322,7 @@ class Dialog:
# prevents flags from conflicting with other non-dialog-related contents # prevents flags from conflicting with other non-dialog-related contents
# in the player file. # in the player file.
def getStatus(self, key): def getStatus(self, key):
character_status=self.__character.ReadKey("dialog_"+self.__location) character_status=self.__character.ReadKey(self.keyName())
if character_status == "": if character_status == "":
return "0" return "0"
pairs=character_status.split(";") pairs=character_status.split(";")
@ -334,7 +341,7 @@ class Dialog:
return return
ishere = 0 ishere = 0
finished = "" finished = ""
character_status = self.__character.ReadKey("dialog_"+self.__location) character_status = self.__character.ReadKey(self.keyName())
if character_status != "": if character_status != "":
pairs = character_status.split(";") pairs = character_status.split(";")
for i in pairs: for i in pairs:
@ -349,7 +356,7 @@ class Dialog:
if finished != "": if finished != "":
finished = finished + ";" finished = finished + ";"
finished = finished + key + ":" + value finished = finished + key + ":" + value
self.__character.WriteKey("dialog_" + self.__location, finished, 1) self.__character.WriteKey(self.keyName(), finished, 1)
# Search the NPC for a particular flag, and if it exists, return # Search the NPC for a particular flag, and if it exists, return
# its value. Flag names are combined with the unique dialog "location" # its value. Flag names are combined with the unique dialog "location"
@ -357,7 +364,7 @@ class Dialog:
# to be unique. This also prevents flags from conflicting with other # to be unique. This also prevents flags from conflicting with other
# non-dialog-related contents in the NPC. # non-dialog-related contents in the NPC.
def getNPCStatus(self, key): def getNPCStatus(self, key):
npc_status=self.__speaker.ReadKey("dialog_"+self.__location + "_" + self.__character.Name) npc_status=self.__speaker.ReadKey(self.keyName() + "_" + self.__character.Name)
if npc_status == "": if npc_status == "":
return "0" return "0"
pairs=npc_status.split(";") pairs=npc_status.split(";")
@ -377,7 +384,7 @@ class Dialog:
return return
ishere = 0 ishere = 0
finished = "" finished = ""
npc_status = self.__speaker.ReadKey("dialog_"+self.__location + "_" + self.__character.Name) npc_status = self.__speaker.ReadKey(self.keyName() + "_" + self.__character.Name)
if npc_status != "": if npc_status != "":
pairs = npc_status.split(";") pairs = npc_status.split(";")
for i in pairs: for i in pairs:
@ -392,4 +399,4 @@ class Dialog:
if finished != "": if finished != "":
finished = finished + ";" finished = finished + ";"
finished = finished + key + ":" + value finished = finished + key + ":" + value
self.__speaker.WriteKey("dialog_" + self.__location + "_" + self.__character.Name, finished, 1) self.__speaker.WriteKey(self.keyName() + "_" + self.__character.Name, finished, 1)