-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.cs
More file actions
753 lines (617 loc) · 30.1 KB
/
Query.cs
File metadata and controls
753 lines (617 loc) · 30.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
// Originally contributed by Chinajade.
//
// LICENSE:
// This work is licensed under the
// Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
// also known as CC-BY-NC-SA. To view a copy of this license, visit
// http://creativecommons.org/licenses/by-nc-sa/3.0/
// or send a letter to
// Creative Commons // 171 Second Street, Suite 300 // San Francisco, California, 94105, USA.
#region Usings
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Threading;
using Honorbuddy.QuestBehaviorCore.XmlElements;
using JetBrains.Annotations;
using Styx;
using Styx.Common;
using Styx.Common.Helpers;
using Styx.CommonBot;
using Styx.CommonBot.Bars;
using Styx.CommonBot.Frames;
using Styx.CommonBot.POI;
using Styx.CommonBot.Profiles;
using Styx.Helpers;
using Styx.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
#endregion
namespace Honorbuddy.QuestBehaviorCore
{
public static class Query
{
/// <summary>Determines if toon is within a tolerable proximity of <paramref name="location" />.</summary>
/// <param name="location">The location.</param>
/// <param name="tolerance">The tolerance. If <c>null</c>: Falls back to use <see cref="Navigator.AtLocation(Vector3,Vector3)"/>.</param>
public static bool AtLocation(Vector3 location, float? tolerance)
{
return AtLocation((WoWMovement.ActiveMover ?? StyxWoW.Me).Location, location, tolerance);
}
/// <summary>Determines whether <paramref name="myLoc" /> is within a tolerable proximity of <paramref name="location" />.</summary>
/// <param name="myLoc">My loc.</param>
/// <param name="location">The location.</param>
/// <param name="tolerance">The tolerance. If <c>null</c>: Falls back to use <see cref="Navigator.AtLocation(Vector3,Vector3)"/>.</param>
public static bool AtLocation(Vector3 myLoc, Vector3 location, float? tolerance)
{
if (!tolerance.HasValue)
return Navigator.AtLocation(myLoc, location);
float tol = tolerance.Value;
// We are checking if point is in an upright cylinder whose center is positioned at 'location',
// radius set to 'tolerance' and height set to max(4.5, 'tolerance') x 2.
// This is the most suitable method when using mesh navigation because the mesh is often above or below the
// actual ingame terrain so there's a need to clamp the tolerance along the Z axis to an amount that
// is greater then the maximum terrain/mesh Z coord difference
return myLoc.Distance2DSquared(location) <= tol * tol && Math.Abs(myLoc.Z - location.Z) <= Math.Max(4.5f, tol);
}
public static IEnumerable<Blackspot> FindCoveringBlackspots(Vector3 location)
{
return
from blackspot in BlackspotManager.GetAllCurrentBlackspots()
where
(blackspot.Location.Distance2D(location) <= blackspot.Radius)
&& (Math.Abs(blackspot.Location.Z - location.Z) <= blackspot.Height)
select blackspot;
}
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;
}
public static IEnumerable<WoWUnit> FindMobsAttackingMe()
{
return
from o in ObjectManager.ObjectList
let unit = o as WoWUnit
where
IsViable(unit)
&& unit.Aggro
select unit;
}
public static List<WoWUnit> FindMobsTargetingUs(bool ignoreMobsInBlackspots, double nonCompeteDistance)
{
using (StyxWoW.Memory.AcquireFrame())
{
return
(from wowUnit in ObjectManager.GetObjectsOfType<WoWUnit>(true, false)
where
Query.IsViableForPulling(wowUnit, ignoreMobsInBlackspots, nonCompeteDistance)
&& (wowUnit.IsTargetingMeOrPet
|| wowUnit.IsTargetingAnyMinion
|| wowUnit.IsTargetingMyPartyMember)
// exclude opposing faction: both players and their pets show up as "PlayerControlled"
&& !wowUnit.PlayerControlled
// Do not pull mobs on the AvoidMobs list
&& !ProfileManager.CurrentOuterProfile.AvoidMobs.Contains(wowUnit.Entry)
orderby wowUnit.CollectionDistance()
select wowUnit)
.ToList();
}
}
/// <summary>
/// <para>Locates the mount identified by MOUNTNAMEORID in the provided MOUNTLIST.</para>
/// <para>MOUNTLIST is usually provided as Mount.Mounts, Mount.FlyingMounts, etc.</para>
/// <para>The MOUNTNAMEORID can be the mount 'name' or SpellId. If a name, the name
/// is converted to lowercase to make the comparison.</para>
/// </summary>
/// <param name="mountList"></param>
/// <param name="mountNameOrId"></param>
/// <returns>null, if the mount could not be located in the MOUNTLIST.</returns>
/// <remarks>5-Jan-2014 00:30 UTC chinajade</remarks>
public static Mount.MountWrapper FindMount(IEnumerable<Mount.MountWrapper> mountList, string mountNameOrId)
{
if (string.IsNullOrEmpty(mountNameOrId))
{ return null; }
mountNameOrId = mountNameOrId.Trim().ToLower();
int mountId;
IEnumerable<Mount.MountWrapper> query;
if (Int32.TryParse(mountNameOrId, NumberStyles.Integer, CultureInfo.InvariantCulture, out mountId) && (mountId != 0))
{
query =
from mount in mountList
where
mount.CreatureSpellId == mountId
select mount;
}
else if (!string.IsNullOrEmpty(mountNameOrId))
{
query =
from mount in mountList
where
mount.CreatureSpell != null
&& mount.CreatureSpell.Name.ToLower() == mountNameOrId
select mount;
}
else
{
return null;
}
return query.FirstOrDefault();
}
// 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;
}
/// <summary>Finds unocupied vehicles.</summary>
/// <param name="ids">The vehicle ids.</param>
/// <param name="extraQualifiers">The extra qualifiers.</param>
/// <returns></returns>
public static IEnumerable<WoWUnit> FindUnoccupiedVehicles(IEnumerable<int> ids, Func<WoWUnit, bool> extraQualifiers = null)
{
return from wowUnit in ObjectManager.GetObjectsOfType<WoWUnit>(false, false)
where ids.Contains((int)wowUnit.Entry)
&& (extraQualifiers == null || extraQualifiers(wowUnit))
&& wowUnit.CanInteractNow
orderby wowUnit.CollectionDistance()
select wowUnit;
}
// 25Aug2013 chinajade
public static void InCompetitionReset()
{
s_inCompetitionTimers.Clear();
}
// 25Aug2013 chinajade
public static TimeSpan InCompetitionTimeRemaining(WoWObject wowObject)
{
DateTime waitStart;
if (s_inCompetitionTimers.TryGetValue(wowObject.Guid, out waitStart))
{
var now = DateTime.Now;
if (now <= (waitStart + s_inCompetitionMaxWaitTime))
{ return waitStart + s_inCompetitionMaxWaitTime - now; }
}
return TimeSpan.Zero;
}
/// <summary>
/// This method returns whether ACHIEVEMENTID is personal compelete for the toon.
/// This means the achievement is complete (account-wide), and the toon personally has the achievement.
/// </summary>
/// <param name="achievementId"></param>
/// <returns></returns>
public static bool IsAchievementPersonallyCompleted(int achievementId)
{
var luaCmd = string.Format("return GetAchievementInfo({0})", achievementId);
var results = Lua.GetReturnValues(luaCmd);
try
{
var isAchievementComplete = (results.Count < 4) ? false : Lua.ParseLuaValue<bool>(results[3]);
var wasEarnedByMe = (results.Count < 13) ? false : Lua.ParseLuaValue<bool>(results[12]);
return isAchievementComplete && wasEarnedByMe;
}
catch (Exception)
{
return false;
}
}
public static bool IsAnyNpcFrameVisible()
{
return
AuctionFrame.Instance.IsVisible
|| GossipFrame.Instance.IsVisible
|| MailFrame.Instance.IsVisible
|| MerchantFrame.Instance.IsVisible
|| QuestFrame.Instance.IsVisible
|| TaxiFrame.Instance.IsVisible
|| TrainerFrame.Instance.IsVisible;
}
// returns true, if any member of GROUP (or their pets) is in combat
// 24Feb2013-08:11UTC chinajade
public static bool IsAnyInCombat(IEnumerable<WoWUnit> group)
{
return group.Any(u => u.Combat || (u.GotAlivePet && u.Pet.Combat));
}
public static bool IsExceptionReportingNeeded(Exception except)
{
var typeOfException = except.GetType();
return !(typeOfException == typeof(ThreadAbortException));
}
// 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);
}
private static readonly Dictionary<WoWGuid, DateTime> s_inCompetitionTimers = new Dictionary<WoWGuid, DateTime>();
private static readonly TimeSpan s_inCompetitionMaxWaitTime = TimeSpan.FromSeconds(90);
private static readonly TimeSpan s_inCompetitionSweepTime = TimeSpan.FromSeconds(10/*mins*/ * 60 /*secs*/);
private static WaitTimer s_inCompetitionSweepTimer = null;
private static PerFrameCachedValue<bool> s_isInVehicle;
// 23Mar2013-05:38UTC chinajade
public static bool IsInLineOfSight(WoWObject wowObject)
{
WoWUnit wowUnit = wowObject as WoWUnit;
return (wowUnit == null)
? wowObject.InLineOfSight
// NB: For WoWUnit, we do two checks. This keeps us out of trouble when the
// mobs are up a stairway and we're looking at them through a guardrail and
// other boundary conditions.
: (wowUnit.InLineOfSight && wowUnit.InLineOfSpellSight);
}
// 25Nov2013-09:30UTC chinajade
public static bool IsInVehicle()
{
return s_isInVehicle ?? (s_isInVehicle =
new PerFrameCachedValue<bool>(() => StyxWoW.Me.InVehicle
|| Lua.GetReturnVal<bool>("return IsPossessBarVisible()", 0)));
}
// 25Nov2013 HighVoltz
public static bool IsMeleeSpec(WoWSpec spec)
{
return !IsRangeSpec(spec);
}
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 static bool IsMountAquatic(string mountNameOrId)
{
return FindMount(Mount.UnderwaterMounts, mountNameOrId) != null;
}
public static bool IsMountFlying(string mountNameOrId)
{
return FindMount(Mount.FlyingMounts, mountNameOrId) != null;
}
public static bool IsMountGround(string mountNameOrId)
{
return FindMount(Mount.GroundMounts, mountNameOrId) != null;
}
public static bool IsMountKnown(string mountNameOrId)
{
return FindMount(Mount.Mounts, mountNameOrId) != null;
}
/// <summary>
/// Returns 'true' for items that start quests, or are quest objectives.
/// </summary>
/// <param name="wowItem"></param>
/// <returns></returns>
// 3Nov2013 chinajade
public static bool IsQuestItem(WoWItem wowItem)
{
// If not valid, then not a quest item...
if ((wowItem == null) || !wowItem.IsValid)
{ return false; }
ItemInfo itemInfo = wowItem.ItemInfo;
if (itemInfo == null)
return false;
return
(itemInfo.BeginQuestId != 0) // Begins a quest?
|| (itemInfo.Bond == WoWItemBondType.Quest); // Objective of quest?
}
// 25Nov2013 HighVoltz
public static bool IsRangeSpec(WoWSpec spec)
{
switch (spec)
{
case WoWSpec.HunterBeastMastery:
case WoWSpec.HunterMarksmanship:
case WoWSpec.HunterSurvival:
case WoWSpec.MageArcane:
case WoWSpec.MageFire:
case WoWSpec.MageFrost:
case WoWSpec.PriestDiscipline:
case WoWSpec.PriestHoly:
case WoWSpec.PriestShadow:
case WoWSpec.WarlockAffliction:
case WoWSpec.WarlockDemonology:
case WoWSpec.WarlockDestruction:
case WoWSpec.ShamanElemental:
case WoWSpec.ShamanRestoration:
case WoWSpec.PaladinHoly:
case WoWSpec.DruidBalance:
case WoWSpec.DruidRestoration:
case WoWSpec.MonkMistweaver:
return true;
default:
return false;
}
}
public static bool IsMobTargetingUs(WoWUnit wowUnit)
{
return
Query.IsViable(wowUnit)
&& (wowUnit.IsTargetingMeOrPet
|| wowUnit.IsTargetingAnyMinion
|| wowUnit.IsTargetingMyPartyMember)
// exclude opposing faction: both players and their pets show up as "PlayerControlled"
&& !wowUnit.PlayerControlled;
}
// 2Sep2013 chinajade
public static bool IsPoiIdle(BotPoi poi)
{
if (poi == null)
{ return false; }
return s_idlePoiTypes.Contains(poi.Type);
}
private static readonly PoiType[] s_idlePoiTypes =
{
PoiType.None,
PoiType.Quest,
PoiType.QuestPickUp,
PoiType.QuestTurnIn
};
public static bool IsPoiMatch(WoWObject wowObject, PoiType poiType, NavType? navType = null)
{
if (!IsViable(wowObject))
{ return false; }
return (BotPoi.Current != null)
&& (BotPoi.Current.Guid == wowObject.Guid)
&& (BotPoi.Current.Type == poiType)
&& ((navType == null) || (BotPoi.Current.NavType == navType));
}
// 16Apr2013-10:11UTC chinajade
public static bool IsSharedWorldResource(WoWObject wowObject)
{
bool isSharedResource = false;
var wowGameObject = wowObject.ToGameObject();
var wowUnit = wowObject as WoWUnit;
isSharedResource |= (wowGameObject != null) && s_sharedGameObjectTypes.Contains(wowGameObject.SubType);
isSharedResource |= (wowUnit != null) && !wowUnit.TaggedByOther;
isSharedResource |= (wowUnit != null) && !wowUnit.IsHostile
&& (wowUnit.IsAnyTrainer
|| wowUnit.IsAnyVendor
|| wowUnit.IsAuctioneer
|| wowUnit.IsBanker
|| wowUnit.IsFlightMaster
|| wowUnit.IsGuildBanker
|| wowUnit.IsInnkeeper
|| wowUnit.IsQuestGiver
|| wowUnit.IsStableMaster
|| wowUnit.CanGossip
);
return isSharedResource;
}
private static readonly WoWGameObjectType[] s_sharedGameObjectTypes =
{
WoWGameObjectType.Binder, // sets hearthstone
// NOT: WoWGameObjectType.Door,
// Although it would be nice to include doors, NPCs locked in cages that require a key to open
// are "door" subtypes. If we walked up and took one of these resources while it was in competition
// that would not be good. Thus, we exclude it from our list of 'shared resources'.
WoWGameObjectType.GuildBank,
WoWGameObjectType.Mailbox,
WoWGameObjectType.MeetingStone,
WoWGameObjectType.QuestGiver,
WoWGameObjectType.SpellCaster, // portals
WoWGameObjectType.Transport
};
// 30May2013-08:11UTC chinajade
public static bool IsStateMatch_AurasWanted(WoWObject wowObject, IEnumerable<int> auraIdsWanted)
{
Contract.Requires(wowObject != null, context => "wowObject != null");
Contract.Requires(auraIdsWanted != null, context => "auraIdsWanted != null");
var wowUnit = wowObject as WoWUnit;
return
(wowUnit == null) // Unit has no auras to check
|| !auraIdsWanted.Any() // No aura qualifiers provided
|| wowUnit.GetAllAuras().Any(a => auraIdsWanted.Contains(a.SpellId));
}
// 30May2013-08:11UTC chinajade
public static bool IsStateMatch_AurasMissing(WoWObject wowObject, IEnumerable<int> auraIdsMissing)
{
Contract.Requires(wowObject != null, context => "wowObject != null");
Contract.Requires(auraIdsMissing != null, context => "auraIdsMissing != null");
var wowUnit = wowObject as WoWUnit;
return
(wowUnit == null) // Unit has no auras to check
|| !auraIdsMissing.Any() // No aura qualifiers provided
|| !wowUnit.GetAllAuras().Any(a => auraIdsMissing.Contains(a.SpellId));
}
// 30May2013-08:11UTC chinajade
public static bool IsStateMatch_IgnoreMobsInBlackspots(WoWObject wowObject, bool ignoreMobsInBlackspots)
{
return !ignoreMobsInBlackspots || !IsTargetInBlackspot(wowObject);
}
// 30May2013-08:11UTC chinajade
public static bool IsStateMatch_MeshNavigable(WoWObject wowObject, MovementByType movementBy)
{
Contract.Requires(wowObject != null, context => "wowObject != null");
return
(movementBy != MovementByType.NavigatorOnly)
// TODO: Rewrite usages to examine paths after generation instead
|| /*Navigator.CanNavigateFully(StyxWoW.Me.Location, wowObject.Location)*/true;
}
// 28Apr2013-03:38UTC chinajade
public static bool IsStateMatch_MobState(WoWObject wowObject, MobStateType requestedMobState, double mobHpPercentLeft = 100.0)
{
var wowUnit = wowObject as WoWUnit;
if (wowUnit != null)
{
bool isMobAlive = wowUnit.IsAlive;
return
(wowUnit.HealthPercent <= mobHpPercentLeft)
&& (requestedMobState == MobStateType.DontCare)
|| ((requestedMobState == MobStateType.Alive) && isMobAlive)
|| ((requestedMobState == MobStateType.AliveNotInCombat) && isMobAlive && !wowUnit.Combat)
|| ((requestedMobState == MobStateType.BelowHp) && isMobAlive)
|| ((requestedMobState == MobStateType.Dead) && wowUnit.IsDead && wowUnit.IsUntagged());
}
return false;
}
// 27Jun2013-08:11UTC chinajade
public static bool IsStateMatch_NotMoving(WoWUnit wowUnit, bool nonMovingTargetWanted)
{
return
!nonMovingTargetWanted || !wowUnit.IsMoving;
}
/// <summary>
/// <p>Returns 'true' if WOWOBJECT is located in a blackspot; otherwise, 'false'.</p>
///
/// <p>Not all blackspots are created equal. For targeting purposes, we only want to consider
/// blackspots defined by the profile (static), or the QBcore-based behaviors (a subset of dynamic
/// blackspots). Other blackspots, such as those dropped by the StuckHandler (also dynamic), should not
/// be considered for targeting purposes. If we did, then it would be possible for say InteractWith
/// to cause Honorbuddy to hang forever, because the StuckHandler dropped a blackspot on a unique
/// target.</p>
/// <p>Blackspots dropped by the StuckHandler and other sources should not be considered for
/// targeting decisions.</p>
/// </summary>
/// <param name="wowObject"></param>
/// <returns></returns>
public static bool IsTargetInBlackspot(WoWObject wowObject)
{
Func<Vector3, Blackspot, bool> isInBlackspot =
(location, blackspot) =>
{
return
(blackspot.Location.DistanceSquared(location) <= (blackspot.Radius * blackspot.Radius))
&& (location.Z >= (blackspot.Location.Z - blackspot.Height))
&& (location.Z <= (blackspot.Location.Z + blackspot.Height));
};
var wowObjectLocation = wowObject.Location;
return
// Consider profile-defined (static) blackspots...
BlackspotManager.GetAllCurrentBlackspots(BlackspotQueryFlags.Static)
.Any(b => isInBlackspot(wowObjectLocation, b))
||
// Consider QBcore-defined (dynamic) blackspots...
BlackspotManager.GetAllCurrentBlackspots(BlackspotQueryFlags.Dynamic)
.Any(b => BlackspotType.IsQbcoreDefined(b) && isInBlackspot(wowObjectLocation, b));
}
// 30Sep2013 chinajade
public static bool IsVehicleActionBarShowing()
{
return ActionBar.Active.Type == ActionBarType.Vehicle;
}
// 24Feb2013-08:11UTC chinajade
[ContractAnnotation("null=>false")]
public static bool IsViable(WoWObject wowObject)
{
return
(wowObject != null)
&& wowObject.IsValid;
}
// 24Feb2013-08:11UTC chinajade
[ContractAnnotation("null=>false")]
public static bool IsViableForFighting(WoWUnit wowUnit)
{
return
IsViable(wowUnit)
&& wowUnit.IsAlive
&& !wowUnit.IsFriendly
&& wowUnit.Attackable
&& wowUnit.CanSelect
&& !wowUnit.IsBlacklistedForCombat();
}
// 24Feb2013-08:11UTC chinajade
[ContractAnnotation("wowObject:null=>false")]
public static bool IsViableForInteracting(WoWObject wowObject,
bool ignoreMobsInBlackspots,
double nonCompeteDistance)
{
if (wowObject == null)
{ return false; }
bool isViableForInteracting =
IsViable(wowObject)
&& !wowObject.IsBlacklistedForInteraction()
&& IsStateMatch_IgnoreMobsInBlackspots(wowObject, ignoreMobsInBlackspots)
&& !IsInCompetition(wowObject, nonCompeteDistance);
return isViableForInteracting;
}
// 24Feb2013-08:11UTC chinajade
public static bool IsViableForPulling(WoWUnit wowUnit,
bool ignoreMobsInBlackspots,
double nonCompeteDistance)
{
return IsViableForFighting(wowUnit)
&& !wowUnit.IsBlacklistedForPulling()
&& IsStateMatch_IgnoreMobsInBlackspots(wowUnit, ignoreMobsInBlackspots)
&& !IsInCompetition(wowUnit, nonCompeteDistance);
}
}
}