public VehicleAbilityType(XElement xElement) : base(xElement) { try { ButtonIndex = GetAttributeAsNullable <int>("ButtonIndex", true, new ConstrainTo.Domain <int>(1, 12), null) ?? 1; TargetingType = GetAttributeAsNullable <AbilityTargetingType>("TargetingType", false, null, null) ?? AbilityTargetingType.Vehicle; IgnoreLoSToTarget = GetAttributeAsNullable <bool>("IgnoreLoSToTarget", false, null, null) ?? false; // We test compile the "UseWhen" expression to look for problems. // Doing this in the constructor allows us to catch 'blind change'problems when ProfileDebuggingMode is turned on. // If there is a problem, an exception will be thrown (and handled here). var useWhenExpression = GetAttributeAs <string>("UseWhen", false, ConstrainAs.StringNonEmpty, null) ?? "true"; UseWhen = DelayCompiledExpression.Condition(useWhenExpression); HandleAttributeProblem(); } catch (Exception except) { if (Query.IsExceptionReportingNeeded(except)) { QBCLog.Exception(except, "PROFILE PROBLEM with \"{0}\"", xElement.ToString()); } IsAttributeProblem = true; } }
// static field members #region Consructor and Argument Processing public RunCode(Dictionary <string, string> args) : base(args) { try { // Parameters dealing with 'starting' the behavior... var code = GetAttributeAs <string>("Code", false, null, null); if (code == null) { var cData = Element.DescendantNodes().OfType <XCData>().FirstOrDefault(); if (cData != null) { code = cData.Value; } } Type = GetAttributeAsNullable <CodeType>("Type", false, null, null) ?? CodeType.Statement; if (!string.IsNullOrEmpty(code)) { if (Type == CodeType.Definition) { Code = code; } else { code = code.Trim(); if (code.Last() != ';') { code += ";"; } CoroutineProducer = new DelayCompiledExpression <Func <Task> >("async () =>{" + code + "}"); } } QuestId = GetAttributeAsNullable <int>("QuestId", false, ConstrainAs.QuestId(this), null) ?? 0; QuestRequirementComplete = GetAttributeAsNullable <QuestCompleteRequirement>("QuestCompleteRequirement", false, null, null) ?? QuestCompleteRequirement.NotComplete; QuestRequirementInLog = GetAttributeAsNullable <QuestInLogRequirement>("QuestInLogRequirement", false, null, null) ?? QuestInLogRequirement.InLog; } catch (Exception except) { // Maintenance problems occur for a number of reasons. The primary two are... // * Changes were made to the behavior, and boundary conditions weren't properly tested. // * The Honorbuddy core was changed, and the behavior wasn't adjusted for the new changes. // In any case, we pinpoint the source of the problem area here, and hopefully it can be quickly // resolved. LogMessage( "error", "BEHAVIOR MAINTENANCE PROBLEM: " + except.Message + "\nFROM HERE:\n" + except.StackTrace + "\n"); IsAttributeProblem = true; } }
public static PerFrameCachedValue <T> ProduceCachedValueFromCompiledExpression <T>( DelayCompiledExpression <Func <T> > delayCompiledExpression, T defaultValue) { return(delayCompiledExpression != null ? new PerFrameCachedValue <T>(delayCompiledExpression.CallableExpression) : new PerFrameCachedValue <T>(() => defaultValue)); }
public UseWhenPredicate_FuncEval(DelayCompiledExpression <Func <bool> > useWhen, bool allowUseDuringCombat, bool allowUseInVehicle, bool allowUseWhileFlying, bool allowUseWhileMounted) : base(useWhen.ExpressionString, allowUseDuringCombat, allowUseInVehicle, allowUseWhileFlying, allowUseWhileMounted) { _predicate = useWhen; }
public VehicleAbilityType( int abilityIndex, AbilityTargetingType targetingType = AbilityTargetingType.Vehicle, bool ignoreLosToTarget = false, string useWhenExpression = "true") { ButtonIndex = abilityIndex; TargetingType = targetingType; IgnoreLoSToTarget = ignoreLosToTarget; useWhenExpression = string.IsNullOrEmpty(useWhenExpression) ? "true" : useWhenExpression; UseWhen = DelayCompiledExpression.Condition(useWhenExpression); }
public static DelayCompiledExpression <Func <T> > ProduceParameterlessCompiledExpression <T>(string expression) { if (expression == null) { return(null); } if (typeof(T) == typeof(bool)) { return((DelayCompiledExpression <Func <T> >)(object) DelayCompiledExpression.Condition(expression)); } return(new DelayCompiledExpression <Func <T> >("()=>" + expression)); }
public DoWhen(Dictionary <string, string> args) : base(args) { try { // NB: Core attributes are parsed by QuestBehaviorBase parent (e.g., QuestId, NonCompeteDistance, etc) // Behavior-specific attributes... // NB: We must parse the Command first, as this helps determine whether certain attributes are // mandator or optional. Command = GetAttributeAsNullable <CommandType>("Command", false, null, null) ?? CommandType.Update; // Primary attributes... ActivityKey_ItemId = GetAttributeAsNullable <int>("ItemId", false, ConstrainAs.ItemId, null) ?? 0; ActivityKey_SpellId = GetAttributeAsNullable <int>("SpellId", false, ConstrainAs.SpellId, null) ?? 0; ActivityKey_Name = GetAttributeAs <string>("ActivityName", false, ConstrainAs.StringNonEmpty, null) ?? ""; var useAtInterval = GetAttributeAsNullable <int>("UseAtInterval", false, ConstrainAs.Milliseconds, null) ?? 0; UseAtInterval = TimeSpan.FromMilliseconds(useAtInterval); // Go ahead and compile the "UseWhen" expression to look for problems... // Doing this in the constructor allows us to catch 'blind change'problems when ProfileDebuggingMode is turned on. // If there is a problem, an exception will be thrown (and handled here). var useWhenExpression = GetAttributeAs <string>("UseWhen", false, ConstrainAs.StringNonEmpty, null) ?? "false"; UseWhen = DelayCompiledExpression.Condition(useWhenExpression); // Tunables... AllowUseDuringCombat = GetAttributeAsNullable <bool>("AllowUseDuringCombat", false, null, null) ?? false; AllowUseInVehicle = GetAttributeAsNullable <bool>("AllowUseInVehicle", false, null, null) ?? false; AllowUseWhileFlying = GetAttributeAsNullable <bool>("AllowUseWhileFlying", false, null, null) ?? false; AllowUseWhileMounted = GetAttributeAsNullable <bool>("AllowUseWhileMounted", false, null, null) ?? false; AllowExecutionWhileNotAlive = GetAttributeAsNullable <bool>("AllowExecutionWhileNotAlive", false, null, null) ?? false; LogExecution = GetAttributeAsNullable <bool>("LogExecution", false, null, null) ?? true; StopMovingToConductActivity = GetAttributeAsNullable <bool>("StopMovingToConductActivity", false, null, null) ?? false; TreeHookName = GetAttributeAs <string>("TreeHookName", false, ConstrainAs.StringNonEmpty, null) ?? "Questbot_Main"; Nodes = OrderNodeCollection.FromXml(Element); CfbContextForHook = this; } catch (Exception except) { // Maintenance problems occur for a number of reasons. The primary two are... // * Changes were made to the behavior, and boundary conditions weren't properly tested. // * The Honorbuddy core was changed, and the behavior wasn't adjusted for the new changes. // In any case, we pinpoint the source of the problem area here, and hopefully it can be quickly // resolved. QBCLog.Exception(except); IsAttributeProblem = true; } }