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;
            }
        }
 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);
 }
Example #3
0
        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));
        }
Example #4
0
        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;
            }
        }