/// <summary> /// Targets and kills any mob targeting Self or Pet. /// </summary> /// <returns></returns> public Composite UtilityBehaviorPS_SpankMobTargetingUs() { return(new Decorator(context => !Me.Combat, new PrioritySelector( // If a mob is targeting us, deal with it immediately, so subsequent activities won't be interrupted... // NB: This can happen if we 'drag mobs' behind us on the way to our destination. new Decorator(context => !IsViableForFighting(_ubpsSpankMobTargetingUs_Mob), new Action(context => { ProvideBoolDelegate extraQualifiers = (obj) => { var wowUnit = obj as WoWUnit; return (wowUnit != null) // exclude opposing faction: both players and their pets show up as "PlayerControlled" && !wowUnit.PlayerControlled; }; _ubpsSpankMobTargetingUs_Mob = FindNonFriendlyNpcTargetingMeOrPet(extraQualifiers) .OrderBy(u => u.DistanceSqr) .FirstOrDefault(); return RunStatus.Failure; // fall through })), // Spank any mobs we find being naughty... new Decorator(context => _ubpsSpankMobTargetingUs_Mob != null, UtilityBehaviorPS_SpankMob(context => _ubpsSpankMobTargetingUs_Mob)) ))); }
private Composite TryCast(int spellId, ProvideBoolDelegate requirements = null) { requirements = requirements ?? (context => true); return(new Decorator(context => SpellManager.CanCast(spellId) && requirements(context), new Action(context => { QBCLog.DeveloperInfo("MiniCombatRoutine used {0}", Utility.GetSpellNameFromId(spellId)); SpellManager.Cast(spellId); }))); }
public static IEnumerable <WoWObject> FindMobsAndFactions( IEnumerable <int> mobIds, bool includeSelf = false, IEnumerable <int> factionIds = null, ProvideBoolDelegate extraQualifiers = null) { return (from wowObject in ObjectManager.GetObjectsOfType <WoWObject>(true, true) where IsMobOrFaction(wowObject, mobIds, includeSelf, factionIds, extraQualifiers) select wowObject); }
// 25Feb2013-12:50UTC chinajade public IEnumerable <WoWUnit> FindNonFriendlyNpcTargetingMeOrPet(ProvideBoolDelegate extraQualifiers = null) { extraQualifiers = extraQualifiers ?? (context => true); return (from wowUnit in ObjectManager.GetObjectsOfType <WoWUnit>(true, false) where IsViableForFighting(wowUnit) && wowUnit.IsTargetingMeOrPet && extraQualifiers(wowUnit) select wowUnit); }
// 11Apr2013-04:41UTC chinajade public bool IsInCompetition(WoWObject wowObject) { ProvideBoolDelegate excludeGroupMembers = (potentialGroupMember => { var asWoWPlayer = potentialGroupMember as WoWPlayer; return((asWoWPlayer != null) && !asWoWPlayer.IsInMyParty); }); return(!IsSharedWorldResource(wowObject) && FindPlayersNearby(wowObject.Location, NonCompeteDistance, excludeGroupMembers).Any()); }
// 25Feb2013-12:50UTC chinajade public IEnumerable<WoWUnit> FindNonFriendlyNpcTargetingMeOrPet(ProvideBoolDelegate extraQualifiers = null) { extraQualifiers = extraQualifiers ?? (context => true); return from wowUnit in ObjectManager.GetObjectsOfType<WoWUnit>(true, false) where IsViableForFighting(wowUnit) && wowUnit.IsTargetingMeOrPet && extraQualifiers(wowUnit) select wowUnit; }
// 24Feb2013-08:11UTC chinajade public IEnumerable <WoWUnit> FindUnitsFromIds(IEnumerable <int> unitIds, ProvideBoolDelegate extraQualifiers = null) { ContractRequires(unitIds != null, context => "unitIds argument may not be null"); extraQualifiers = extraQualifiers ?? (wowUnitContext => true); return (from wowUnit in ObjectManager.GetObjectsOfType <WoWUnit>(true, false) where IsViable(wowUnit) && unitIds.Contains((int)wowUnit.Entry) && extraQualifiers(wowUnit) select wowUnit); }
// 24Feb2013-08:11UTC chinajade public IEnumerable<WoWObject> FindObjectsFromIds(IEnumerable<int> objectIds, ProvideBoolDelegate extraQualifiers = null) { ContractRequires(objectIds != null, context => "objectIds argument may not be null"); extraQualifiers = extraQualifiers ?? (wowObjectContext => true); return from wowObject in ObjectManager.GetObjectsOfType<WoWObject>(true, false) where IsViable(wowObject) && objectIds.Contains((int)wowObject.Entry) && extraQualifiers(wowObject) select wowObject; }
// 25Feb2013-12:50UTC chinajade public IEnumerable <WoWUnit> FindHostileUnitsWithinAggroRangeOFDestination( WoWPoint destination, double extraRangePadding = 0.0, ProvideBoolDelegate extraQualifiers = null) { extraQualifiers = extraQualifiers ?? (context => true); return (from wowUnit in ObjectManager.GetObjectsOfType <WoWUnit>(true, false) where IsViableForFighting(wowUnit) && wowUnit.IsHostile && extraQualifiers(wowUnit) && (wowUnit.Location.SurfacePathDistance(destination) <= (wowUnit.MyAggroRange + extraRangePadding)) select wowUnit); }
// 25Feb2013-12:50UTC chinajade public IEnumerable<WoWUnit> FindHostileUnitsWithinAggroRangeOFDestination( WoWPoint destination, double extraRangePadding = 0.0, ProvideBoolDelegate extraQualifiers = null) { extraQualifiers = extraQualifiers ?? (context => true); return from wowUnit in ObjectManager.GetObjectsOfType<WoWUnit>(true, false) where IsViableForFighting(wowUnit) && wowUnit.IsHostile && extraQualifiers(wowUnit) && (wowUnit.Location.SurfacePathDistance(destination) <= (wowUnit.MyAggroRange + extraRangePadding)) select wowUnit; }
public static bool IsMobOrFaction( WoWObject wowObject, IEnumerable <int> mobIds, bool includeSelf = false, IEnumerable <int> factionIds = null, ProvideBoolDelegate extraQualifiers = null) { if (!IsViable(wowObject)) { return(false); } var wowUnit = wowObject as WoWUnit; var isMob = mobIds != null && mobIds.Contains((int)wowObject.Entry); var isMe = includeSelf && wowObject.IsMe; var isFaction = wowUnit != null && factionIds != null && factionIds.Contains((int)wowUnit.FactionId); return((isMob || isMe || isFaction) && (extraQualifiers == null || extraQualifiers(wowObject))); }
public Composite UtilityBehaviorPS_SpankMobWithinAggroRange(ProvideWoWPointDelegate destinationDelegate, ProvideDoubleDelegate extraRangePaddingDelegate = null, Func <IEnumerable <int> > excludedUnitIdsDelegate = null) { extraRangePaddingDelegate = extraRangePaddingDelegate ?? (context => 0.0); excludedUnitIdsDelegate = excludedUnitIdsDelegate ?? (() => new List <int>()); return(new Decorator(context => !Me.Combat, new PrioritySelector( // If a mob is targeting us, deal with it immediately, so subsequent activities won't be interrupted... // NB: This can happen if we 'drag mobs' behind us on the way to our destination. new Decorator(context => !IsViableForFighting(_ubpsSpankMobWithinAggroRange_Mob), new Action(context => { ProvideBoolDelegate extraQualifiers = (obj) => { var wowUnit = obj as WoWUnit; return (wowUnit != null) // exclude opposing faction: both players and their pets show up as "PlayerControlled" && !wowUnit.PlayerControlled && !excludedUnitIdsDelegate().Contains((int)wowUnit.Entry); }; _ubpsSpankMobWithinAggroRange_Mob = FindHostileUnitsWithinAggroRangeOFDestination( destinationDelegate(context), extraRangePaddingDelegate(context), extraQualifiers) .OrderBy(u => u.DistanceSqr).FirstOrDefault(); return RunStatus.Failure; // fall through })), // Spank any mobs we find being naughty... new Decorator(context => _ubpsSpankMobWithinAggroRange_Mob != null, UtilityBehaviorPS_SpankMob(context => _ubpsSpankMobWithinAggroRange_Mob)) ))); }
// 11Apr2013-04:41UTC chinajade public static bool IsInCompetition(WoWObject wowObject, double nonCompeteDistance) { if (!IsViable(wowObject)) { return(false); } // Shared world resources are never in competition... if (IsSharedWorldResource(wowObject)) { return(false); } // If unit is tagged by someone else and in combat, it is in competition... // N.B. There are some cases where NPCs are shown as tagged by - // someone else yet nobody is actively engaged with said unit. // If unit is not in combat with anyone and it is tagged and nobody else is around it can not be in competition. // On the other hand if we choose to ignore the tagged unit and it's the only NPC that exists in the world then bot will be stuck var wowUnit = wowObject as WoWUnit; var isTaggedByOther = ((wowUnit != null) && !wowUnit.IsUntagged() && wowUnit.Combat); if (isTaggedByOther) { return(true); } ProvideBoolDelegate excludeGroupMembers = (potentialGroupMember => { var asWoWPlayer = potentialGroupMember as WoWPlayer; return((asWoWPlayer != null) && !asWoWPlayer.IsInMyParty); }); var isPlayersNearby = FindPlayersNearby(wowObject.Location, nonCompeteDistance, excludeGroupMembers).Any(); var isCompetitionTimerRunning = s_inCompetitionTimers.ContainsKey(wowObject.Guid); // If players are clear, and competition timer is running... // We no longer need the competition timer. if (!isPlayersNearby && isCompetitionTimerRunning) { s_inCompetitionTimers.Remove(wowObject.Guid); } // If players are nearby, and we haven't established competition timer... // We need to record time at which we start the wait. if (isPlayersNearby && !isCompetitionTimerRunning) { // Add new entry... s_inCompetitionTimers.Add(wowObject.Guid, DateTime.Now); // Time to sweep away old 'in competition' entries? if ((s_inCompetitionSweepTimer == null) || s_inCompetitionSweepTimer.IsFinished) { // Remove expired 'in competition' entries... var now = DateTime.Now; var keysToRemove = (from kvp in s_inCompetitionTimers where now > (kvp.Value + s_inCompetitionSweepTime) select kvp.Key) .ToArray(); foreach (var key in keysToRemove) { s_inCompetitionTimers.Remove(key); } // Reset sweep timer (creating it, if necessary)... if (s_inCompetitionSweepTimer == null) { s_inCompetitionSweepTimer = new WaitTimer(s_inCompetitionSweepTime); } s_inCompetitionSweepTimer.Reset(); } } // If we've been waiting on object too long, it is no longer 'in competition'... // NB: Since group membership affects 'nearby players', we must make this test // after the competition timers have been updated due to nearby players. DateTime waitStart; if (s_inCompetitionTimers.TryGetValue(wowObject.Guid, out waitStart)) { if (DateTime.Now > (waitStart + s_inCompetitionMaxWaitTime)) { return(false); } // Fall through, if we haven't been waiting too long... } return(isPlayersNearby); }
// 25Feb2013-12:50UTC chinajade public static IEnumerable <WoWPlayer> FindPlayersNearby(Vector3 location, double radius, ProvideBoolDelegate extraQualifiers = null) { extraQualifiers = extraQualifiers ?? (wowPlayerContext => true); return (from wowPlayer in ObjectManager.GetObjectsOfType <WoWPlayer>(true, false) where IsViable(wowPlayer) && wowPlayer.IsAlive && (wowPlayer.Location.Distance(location) < radius) && extraQualifiers(wowPlayer) select wowPlayer); }
// 25Feb2013-12:50UTC chinajade public IEnumerable<WoWPlayer> FindPlayersNearby(WoWPoint location, double radius, ProvideBoolDelegate extraQualifiers = null) { extraQualifiers = extraQualifiers ?? (wowPlayerContext => true); return from wowPlayer in ObjectManager.GetObjectsOfType<WoWPlayer>(true, false) where IsViable(wowPlayer) && wowPlayer.IsAlive && (wowPlayer.Location.Distance(location) < radius) && extraQualifiers(wowPlayer) select wowPlayer; }