/// /// /// Requires that the dialog's NPC must consider its own cvar specified by , /// whose existence and value matches an expression specified by /// and . /// /// /// /// Example: Hide the response unless the NPC has a cvar named "myCVar" with a value less than 5. /// /// <requirement type="NPCHasCVarSDX, SCore" requirementtype="Hide" id="myCVar" operator="lte" value="5" /> /// /// /// /// /// Example: Hide the response unless the NPC has a cvar named "myCVar" with any value (including zero). /// /// <requirement type="NPCHasCVarSDX, SCore" requirementtype="Hide" id="myCVar" /> /// /// /// /// /// Example: Hide the response unless the NPC does not have a cvar named "myCVar". /// /// <requirement type="NPCHasCVarSDX, SCore" requirementtype="Hide" id="myCVar" operator="not" /> /// /// /// public class DialogRequirementNPCHasCVarSDX : BaseDialogRequirement, IDialogOperator { private static readonly string AdvFeatureClass = "AdvancedDialogDebugging"; /// /// /// Operator to use. This is set in /// . /// /// /// /// Valid values: /// /// /// "eq" /// /// The cvar value must exist, and its value must be equal to . /// This is the default. /// /// /// /// "neq" /// The cvar value must not be equal to . /// /// /// "lt" /// The cvar value must be strictly less than . /// /// /// "lte" /// The cvar value must be less than or equal to . /// /// /// "gt" /// The cvar value must be strictly greater than . /// /// /// "gte" /// The cvar value must be greater than or equal to . /// /// /// "not" /// The cvar must not exist, or its value must be equal to zero. is ignored. /// /// /// /// public string Operator { get; set; } = "eq"; public override bool CheckRequirement(EntityPlayer player, EntityNPC talkingTo) { var invert = Operator.ToLower() == "not"; if (talkingTo.Buffs.HasCustomVar(ID)) { var npcValue = talkingTo.Buffs.GetCustomVar(ID); // If value is not specified, accepted it, unless the cvar isn't supposed to exist. if (string.IsNullOrEmpty(Value)) { var passes = invert ? npcValue == 0 : true; AdvLogging.DisplayLog(AdvFeatureClass, $"{GetType()} HasCvar: {ID} Operator: {Operator} Value is empty, returning {passes}"); return passes; } float.TryParse(Value, out var flValue); AdvLogging.DisplayLog(AdvFeatureClass, $"{GetType()} HasCvar: {ID} Value: {flValue} NPC Value: {npcValue} Operator: {Operator}"); return Operator.ToLower() switch { "lt" => npcValue < flValue, "lte" => npcValue <= flValue, "gt" => npcValue > flValue, "gte" => npcValue >= flValue, "neq" => flValue != npcValue, "not" => npcValue == 0, _ => flValue == npcValue, }; ; } return invert; } }