- Document how to successfully create rules that do not need any pre or post
conditions (by supplying and empty list). - Add exception handling to matchConditions() and setConditions() and output a debug log message to facilitate debugging broken dialogs when the rules contain malformed condition lists. git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@10635 282e977c-c81d-0410-88c4-b93c2d0d6712master
parent
9fbc7d83ea
commit
5308835604
|
@ -68,27 +68,30 @@
|
||||||
# another NPC. The flags can also be used to help an individual NPC
|
# another NPC. The flags can also be used to help an individual NPC
|
||||||
# remember what he has said to the player in the past. Flag settings are
|
# remember what he has said to the player in the past. Flag settings are
|
||||||
# stored in the player file, so they persist as long as the character exists
|
# stored in the player file, so they persist as long as the character exists
|
||||||
# in the game. Each rule contains a list of one or more preconditions, and
|
# in the game. Each rule contains a list of one or more preconditions, if
|
||||||
# each of the individual preconditions is itself a list of a flag name and
|
# any. Supply an empty list [] if no preconditions exist, but otherwise,
|
||||||
# one or more values in the following format: [["flag1", "value1", "value2"
|
# each of the preconditions is required to be a list that contains at least
|
||||||
# ...], ["flag2", "value3"] ...] where "..." indicates that the pattern may
|
# a flag name and one or more values in the following format: [["flag1",
|
||||||
# be repeated. The flag name is always the first item in a precondition
|
# "value1", "value2" ...], ["flag2", "value3"] ...] where "..." indicates
|
||||||
# list. ":" and ";" characters are forbidden in the flag names and values.
|
# that the pattern may be repeated. The flag name is always the first item
|
||||||
# For a rule to be triggered, all its preconditions must be satisfied by
|
# in a precondition list. ":" and ";" characters are forbidden in the flag
|
||||||
# settings in the player file. To satisfy a precondition, one of the
|
# names and values. For a rule to be triggered, all its preconditions must
|
||||||
# precondition values must match the identified flag setting in the player
|
# be satisfied by settings in the player file. To satisfy a precondition,
|
||||||
# file. The default value of any precondition that has not been specifically
|
# one of the precondition values must match the identified flag setting in
|
||||||
# set in the player file is "0". If one of the precondition values is set
|
# the player file. The default value of any precondition that has not been
|
||||||
# to "*", a match is not required.
|
# specifically set in the player file is "0". If one of the precondition
|
||||||
|
# values is set to "*", a match is not required.
|
||||||
#
|
#
|
||||||
# - Postconditions are state changes to apply to the player file flags after
|
# - Postconditions are state changes to apply to the player file flags after
|
||||||
# the rule triggers. The postcondition is a nested list that has the same
|
# the rule triggers. If a rule is not intended to set a flag, supply an
|
||||||
# format as the precondition list except that each postcondition list only
|
# empty list [] when specifying postconditions, otherwise, postconditions
|
||||||
# contains one value. This is because the other main difference is that
|
# are supplied in a nested list that has the same format as the precondition
|
||||||
# whereas a precondition checks a player file to see if a flag has a certain
|
# list except that each postcondition list only contains one value. This is
|
||||||
# value, the postcondition causes a value to be stored into the player file,
|
# because the other main difference is that whereas a precondition checks a
|
||||||
# and it does not make sense to store more than one value into a single
|
# player file to see if a flag has a certain value, the postcondition causes
|
||||||
# flag. A value of "*" means that the player file flag will not be changed.
|
# a value to be stored into the player file, and it does not make sense to
|
||||||
|
# store more than one value into a single flag. A value of "*" means that
|
||||||
|
# the player file flag will not be changed.
|
||||||
#
|
#
|
||||||
# - A prefunction is an optional callback function that will be called when a
|
# - A prefunction is an optional callback function that will be called when a
|
||||||
# rule's preconditions are all matched, but before the rule is validated.
|
# rule's preconditions are all matched, but before the rule is validated.
|
||||||
|
@ -284,12 +287,16 @@ class Dialog:
|
||||||
# complex conditions that determine if the rule is allowed to trigger.
|
# complex conditions that determine if the rule is allowed to trigger.
|
||||||
def matchConditions(self, rule):
|
def matchConditions(self, rule):
|
||||||
for condition in rule.getPreconditions():
|
for condition in rule.getPreconditions():
|
||||||
status = self.getStatus(condition[0])
|
try:
|
||||||
values = condition[1:]
|
status = self.getStatus(condition[0])
|
||||||
for value in values:
|
values = condition[1:]
|
||||||
if (status == value) or (value == "*"):
|
for value in values:
|
||||||
break
|
if (status == value) or (value == "*"):
|
||||||
else:
|
break
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
except:
|
||||||
|
Crossfire.Log(Crossfire.LogDebug, "CFDialog: Bad Precondition")
|
||||||
return 0
|
return 0
|
||||||
if rule.getPrefunction() <> None:
|
if rule.getPrefunction() <> None:
|
||||||
return rule.getPrefunction()(self.__character, rule)
|
return rule.getPrefunction()(self.__character, rule)
|
||||||
|
@ -300,10 +307,14 @@ class Dialog:
|
||||||
# dramatic effects than the setting of a flag in the player file.
|
# dramatic effects than the setting of a flag in the player file.
|
||||||
def setConditions(self, rule):
|
def setConditions(self, rule):
|
||||||
for condition in rule.getPostconditions():
|
for condition in rule.getPostconditions():
|
||||||
key = condition[0]
|
try:
|
||||||
val = condition[1]
|
key = condition[0]
|
||||||
if val != "*":
|
val = condition[1]
|
||||||
self.setStatus(key,val)
|
if val != "*":
|
||||||
|
self.setStatus(key,val)
|
||||||
|
except:
|
||||||
|
Crossfire.Log(Crossfire.LogDebug, "CFDialog: Bad Postcondition")
|
||||||
|
return 0
|
||||||
if rule.getPostfunction() <> None:
|
if rule.getPostfunction() <> None:
|
||||||
rule.getPostfunction()(self.__character, rule)
|
rule.getPostfunction()(self.__character, rule)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue