// 26May2013-09:04UTC chinajade public static Composite MarkerSeq(ProvideStringDelegate messageDelegate) { return(new Action(context => { Logging.Write(Colors.Fuchsia, BuildLogMessage("marker", messageDelegate(context))); })); }
public static bool Provides(bool isContractOkay, ProvideStringDelegate provideStringProviderDelegate) { if (!isContractOkay) { // TODO: (Future enhancement) Build a string representation of isContractOkay if stringProviderDelegate is null string message = provideStringProviderDelegate(null) ?? "NO MESSAGE PROVIDED"; var trace = new StackTrace(1); QBCLog.Error("[CONTRACT VIOLATION] {0}\nLocation:\n{1}", message, trace.ToString()); throw new ContractException(message); } return(isContractOkay); }
public static bool ContractProvides(bool isContractOkay, ProvideStringDelegate provideStringProviderDelegate) { if (!isContractOkay) { // TODO: (Future enhancement) Build a string representation of isContractOkay if stringProviderDelegate is null string message = provideStringProviderDelegate(null) ?? "NO MESSAGE PROVIDED"; var trace = new StackTrace(1); LogError("[CONTRACT VIOLATION] {0}\nLocation:\n{1}", message, trace.ToString()); throw new ContractException(message); } return isContractOkay; }
// 19Apr2013-05:58UTC chinajade public void UsageCheck_DeprecatedAttribute(XElement xElement, bool deprecatedAttributeEncounteredPredicate, string attributeName, ProvideStringDelegate messageDelegate) { if (QuestBehaviorCoreSettings.Instance.LogNotifyOn_OnDeprecatedAttributeUse) { if (deprecatedAttributeEncounteredPredicate) { QBCLog.Warning(QBCLog.BuildMessageWithContext(xElement, "DEPRECATED ATTRIBUTE ({1}):{0}{2}", Environment.NewLine, attributeName, UtilFormatMessage(messageDelegate(null)))); AudibleNotifyOn(QuestBehaviorCoreSettings.Instance.AudibleNotify_OnDeprecatedAttributeUse); } } }
// 19Apr2013-05:58UTC chinajade public void UsageCheck_DeprecatedAttribute(XElement xElement, bool deprecatedAttributeEncounteredPredicate, string attributeName, ProvideStringDelegate messageDelegate) { if (QuestBehaviorCoreSettings.Instance.LogNotifyOn_OnDeprecatedAttributeUse) { if (deprecatedAttributeEncounteredPredicate) { LogWarning("DEPRECATED ATTRIBUTE ({1}):{0}{2}{0}{3}{0}", Environment.NewLine, attributeName, messageDelegate(null), GetProfileReference(xElement)); if (QuestBehaviorCoreSettings.Instance.AudibleNotify_OnDeprecatedAttributeUse) { const int audioDelayInMilliseconds = 150; SystemSounds.Asterisk.Play(); Thread.Sleep(audioDelayInMilliseconds); SystemSounds.Asterisk.Play(); } } } }
/// <summary> /// <para>Instructs the user's pet to assume one of the following stances: "Assist", "Defensive", "Passive"</para> /// <para>Notes:<list type="bullet"> /// <item><description><para>* This behavior performs all appropriate checks: pet exists and is alive, etc.</para></description></item> /// <item><description><para>* The pet's "Assist", "Defensive", and "Passive" commands must be hot-barred! Existence in the spellbook /// is insufficient. This is a limitation of the WoWclient and HB APIs.</para></description></item> /// <item><description><para>* The returned Composite is suitable for use in a behavior tree (Priority)Selector container /// (i.e., placing it in a Sequence container will not yield the desired results).</para></description></item> /// </list></para> /// </summary> /// <param name="petStanceNameDelegate"></param> /// <returns>a behavior tree Composite suitable for use in a (Priority)Selector container</returns> public Composite UtilityBehaviorPS_PetSetStance(ProvideStringDelegate petStanceNameDelegate) { string[] knownStanceNames = { "Assist", "Defensive", "Passive" }; // We can't change pet stance while mounted, so don't try... return(new Decorator(context => !Me.Mounted, new PrioritySelector(petStanceNameContext => petStanceNameDelegate(petStanceNameContext), new Decorator(petStanceNameContext => !knownStanceNames.Contains((string)petStanceNameContext), new Action(petStanceNameContext => { LogMaintenanceError("Unknown pet stance '{0}'. Must be one of: {1}", (string)petStanceNameContext, string.Join(", ", knownStanceNames)); })), new Decorator(petStanceNameContext => Me.GotAlivePet && CanCastPetAction((string)petStanceNameContext) && !IsPetActionActive((string)petStanceNameContext), new Action(petStanceNameContext => { CastPetAction((string)petStanceNameContext); })) ))); }
// 19Apr2013-05:58UTC chinajade public void UsageCheck_SemanticCoherency(XElement xElement, bool incoherencyPredicate, ProvideStringDelegate messageDelegate) { if (incoherencyPredicate) { QBCLog.Error(QBCLog.BuildMessageWithContext(xElement, "PROFILE ERROR: {0}", UtilFormatMessage(messageDelegate(null)))); IsAttributeProblem = true; AudibleNotifyOn(QuestBehaviorCoreSettings.Instance.AudibleNotify_OnSemanticIncoherency); } }
public Composite UtilityBehaviorPS_MoveTo(ProvideWoWPointDelegate destinationDelegate, ProvideStringDelegate destinationNameDelegate, ProvideDoubleDelegate precisionDelegate = null, CanRunDecoratorDelegate suppressMountUse = null, ProvideWoWPointDelegate locationObserver = null) { ContractRequires(destinationDelegate != null, context => "locationRetriever may not be null"); ContractRequires(destinationNameDelegate != null, context => "destinationNameDelegate may not be null"); precisionDelegate = precisionDelegate ?? (context => Me.Mounted ? 8.0 : 5.0); suppressMountUse = suppressMountUse ?? (context => false); locationObserver = locationObserver ?? (context => Me.Location); return(new Decorator(context => MovementBy != MovementByType.None, new PrioritySelector( new Action(context => { _ubpsMoveTo_Location = destinationDelegate(context); return RunStatus.Failure; // fall through }), new Decorator(context => !suppressMountUse(context) && !Me.InVehicle && !Me.Mounted && Mount.CanMount() && Mount.ShouldMount(_ubpsMoveTo_Location), new Action(context => { Mount.MountUp(() => _ubpsMoveTo_Location); })), new Decorator(context => (locationObserver(context).Distance((_ubpsMoveTo_Location)) > precisionDelegate(context)), new Sequence( new CompositeThrottle(TimeSpan.FromMilliseconds(1000), new Action(context => { TreeRoot.StatusText = "Moving to " + (destinationNameDelegate(context) ?? _ubpsMoveTo_Location.ToString()); })), new Action(context => { var moveResult = MoveResult.Failed; // Use Flightor, if allowed... if ((MovementBy == MovementByType.FlightorPreferred) && Me.IsOutdoors && Me.MovementInfo.CanFly) { Flightor.MoveTo(_ubpsMoveTo_Location); // <sigh> Its simply a crime that Flightor doesn't implement the INavigationProvider interface... moveResult = MoveResult.Moved; } // Use Navigator to get there, if allowed... else if ((MovementBy == MovementByType.NavigatorPreferred) || (MovementBy == MovementByType.NavigatorOnly) || (MovementBy == MovementByType.FlightorPreferred)) { if (!Me.IsSwimming) { moveResult = Navigator.MoveTo(_ubpsMoveTo_Location); } } // If Navigator couldn't move us, resort to click-to-move if allowed... if (!((moveResult == MoveResult.Moved) || (moveResult == MoveResult.ReachedDestination) || (moveResult == MoveResult.PathGenerated))) { if (MovementBy == MovementByType.NavigatorOnly) { LogWarning("Failed to mesh move--is area unmeshed? Or, are we flying or swimming?"); return RunStatus.Failure; } WoWMovement.ClickToMove(_ubpsMoveTo_Location); } return RunStatus.Success; }), new WaitContinue(Delay_WoWClientMovementThrottle, context => false, new ActionAlwaysSucceed()) )) ))); }
// 19Apr2013-05:58UTC chinajade public void UsageCheck_SemanticCoherency(XElement xElement, bool incoherencyPredicate, ProvideStringDelegate messageDelegate) { if (incoherencyPredicate) { LogError("PROFILE ERROR: {1}{0}{2}{0}", Environment.NewLine, messageDelegate(null), GetProfileReference(xElement)); IsAttributeProblem = true; if (QuestBehaviorCoreSettings.Instance.AudibleNotify_OnSemanticIncoherency) { const int audioDelayInMilliseconds = 150; SystemSounds.Asterisk.Play(); Thread.Sleep(audioDelayInMilliseconds); SystemSounds.Asterisk.Play(); } } }
/// <summary> /// <para>Instructs the user's pet to assume one of the following stances: "Assist", "Defensive", "Passive"</para> /// <para>Notes:<list type="bullet"> /// <item><description><para>* This behavior performs all appropriate checks: pet exists and is alive, etc.</para></description></item> /// <item><description><para>* The pet's "Assist", "Defensive", and "Passive" commands must be hot-barred! Existence in the spellbook /// is insufficient. This is a limitation of the WoWclient and HB APIs.</para></description></item> /// <item><description><para>* The returned Composite is suitable for use in a behavior tree (Priority)Selector container /// (i.e., placing it in a Sequence container will not yield the desired results).</para></description></item> /// </list></para> /// </summary> /// <param name="petStanceNameDelegate"></param> /// <returns>a behavior tree Composite suitable for use in a (Priority)Selector container</returns> public Composite UtilityBehaviorPS_PetSetStance(ProvideStringDelegate petStanceNameDelegate) { string[] knownStanceNames = { "Assist", "Defensive", "Passive" }; // We can't change pet stance while mounted, so don't try... return new Decorator(context => !Me.Mounted, new PrioritySelector(petStanceNameContext => petStanceNameDelegate(petStanceNameContext), new Decorator(petStanceNameContext => !knownStanceNames.Contains((string)petStanceNameContext), new Action(petStanceNameContext => { LogMaintenanceError("Unknown pet stance '{0}'. Must be one of: {1}", (string)petStanceNameContext, string.Join(", ", knownStanceNames)); })), new Decorator(petStanceNameContext => Me.GotAlivePet && CanCastPetAction((string)petStanceNameContext) && !IsPetActionActive((string)petStanceNameContext), new Action(petStanceNameContext => { CastPetAction((string)petStanceNameContext); })) )); }
// Use this in Sequence containers... public static Composite LogMarkerSeq(ProvideStringDelegate messageDelegate) { return new Action(context => { Logging.Write(Colors.Fuchsia, messageDelegate(context)); }); }
public Composite UtilityBehaviorPS_MoveTo(ProvideWoWPointDelegate destinationDelegate, ProvideStringDelegate destinationNameDelegate, ProvideDoubleDelegate precisionDelegate = null, CanRunDecoratorDelegate suppressMountUse = null, ProvideWoWPointDelegate locationObserver = null) { ContractRequires(destinationDelegate != null, context => "locationRetriever may not be null"); ContractRequires(destinationNameDelegate != null, context => "destinationNameDelegate may not be null"); precisionDelegate = precisionDelegate ?? (context => Me.Mounted ? 8.0 : 5.0); suppressMountUse = suppressMountUse ?? (context => false); locationObserver = locationObserver ?? (context => Me.Location); return new Decorator(context => MovementBy != MovementByType.None, new PrioritySelector( new Action(context => { _ubpsMoveTo_Location = destinationDelegate(context); return RunStatus.Failure; // fall through }), new Decorator(context => !suppressMountUse(context) && !Me.InVehicle && !Me.Mounted && Mount.CanMount() && Mount.ShouldMount(_ubpsMoveTo_Location), new Action(context => { Mount.MountUp(() => _ubpsMoveTo_Location); })), new Decorator(context => (locationObserver(context).Distance((_ubpsMoveTo_Location)) > precisionDelegate(context)), new Sequence( new CompositeThrottle(TimeSpan.FromMilliseconds(1000), new Action(context => {TreeRoot.StatusText = "Moving to " + (destinationNameDelegate(context) ?? _ubpsMoveTo_Location.ToString()); })), new Action(context => { var moveResult = MoveResult.Failed; // Use Flightor, if allowed... if ((MovementBy == MovementByType.FlightorPreferred) && Me.IsOutdoors && Me.MovementInfo.CanFly) { Flightor.MoveTo(_ubpsMoveTo_Location); // <sigh> Its simply a crime that Flightor doesn't implement the INavigationProvider interface... moveResult = MoveResult.Moved; } // Use Navigator to get there, if allowed... else if ((MovementBy == MovementByType.NavigatorPreferred) || (MovementBy == MovementByType.NavigatorOnly) || (MovementBy == MovementByType.FlightorPreferred)) { if (!Me.IsSwimming) { moveResult = Navigator.MoveTo(_ubpsMoveTo_Location); } } // If Navigator couldn't move us, resort to click-to-move if allowed... if (!((moveResult == MoveResult.Moved) || (moveResult == MoveResult.ReachedDestination) || (moveResult == MoveResult.PathGenerated))) { if (MovementBy == MovementByType.NavigatorOnly) { LogWarning("Failed to mesh move--is area unmeshed? Or, are we flying or swimming?"); return RunStatus.Failure; } WoWMovement.ClickToMove(_ubpsMoveTo_Location); } return RunStatus.Success; }), new WaitContinue(Delay_WoWClientMovementThrottle, context => false, new ActionAlwaysSucceed()) )) )); }