forked from namreeb/PPather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPPather.cs
More file actions
1869 lines (1626 loc) · 44.4 KB
/
Copy pathPPather.cs
File metadata and controls
1869 lines (1626 loc) · 44.4 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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of PPather.
PPather is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PPather is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PPather. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Threading;
using System.Reflection;
using System.Text;
using System.IO;
using Glider.Common.Objects;
using System.Windows.Forms;
using System.Drawing;
using Pather;
using Pather.Tasks;
using Pather.Graph;
using Pather.Activities;
using Pather.Parser;
using Pather.Helpers.UI;
using WowTriangles;
namespace Pather
{
public abstract class PPather : GGameClass
{
public const double PI = Math.PI;
public const string VERSION = "1.0.4c";
public static Random random = new Random();
public static Mover mover;
public static UnitRadar radar;
public static CultureInfo numberFormat = CultureInfo.InvariantCulture;
// presumably PPather acts as a singleton so we shouldn't have
// any issues making fields static if necessary
bool BGMode = false;
bool Stopped = true;
public PullTask CurrentPullTask = null;
public string CurrentContinent = null;
public static PathGraph world = null;
Spot WasAt = null;
public enum RunState_e
{
Stopped,
Paused,
Running
};
public RunState_e RunState = RunState_e.Stopped;
public RunState_e WantedState = RunState_e.Stopped;
public NPCDatabase NPCs = new NPCDatabase();
public static ToonState ToonData = new ToonState();
Thread glideThread = null;
GSpellTimer SaveTimer = new GSpellTimer(60 * 1000);
int XPInitial;
int XPCurrent;
GSpellTimer GliderStart;
GSpellTimer LogoutTimer;
int Kills = 0;
int Deaths = 0;
int Loots = 0;
int Harvests = 0;
int TTL = 0; // time to level in minutes
int XPh = 0; // XP/h since last level/start
int KPh = 0;
// GUI
public static PatherForm form;
public static Settings PatherSettings;
// subclass constructors must call this constructor via base()
public PPather()
: base()
{
RegisterTasks();
RootNode.Init();
PatherSettings = Settings.Load();
}
/// <summary>
/// This will use reflection to read the ParserKeyword field
/// for all subclasses of ParserTask (both built-in and user defined)
/// and register that keyword. You can register multiple keywords by
/// delimiting that field with commas, i.e.
/// public const string ParserKeyword = "Par,Parallel";
///
/// If the field does not exist, the name of the class will
/// be used instead without "Task" at the end of the name, which
/// is the desired behavior for most of the parser tasks.
/// </summary>
private void RegisterTasks()
{
ParserTask.registeredTasks.Clear();
Type taskType = typeof(ParserTask);
Assembly cur = Assembly.GetExecutingAssembly();
Assembly[] allAsms = System.AppDomain.CurrentDomain.GetAssemblies();
// this is only sorted for debugging
SortedList<string, Type> internalTypes = new SortedList<string, Type>();
SortedList<string, Type> userTypes = new SortedList<string, Type>();
foreach (Type t in cur.GetTypes())
{
if (t.IsSubclassOf(taskType) && !t.IsAbstract)
{
internalTypes[t.FullName] = t;
}
}
foreach (Assembly a in allAsms)
{
if (a == cur)
continue; // already did them
foreach (Type t in a.GetTypes())
{
if (t.IsSubclassOf(taskType) && !t.IsAbstract)
{
userTypes[t.FullName] = t;
}
}
}
List<Type> allTypes = new List<Type>();
allTypes.AddRange(internalTypes.Values);
allTypes.AddRange(userTypes.Values);
foreach (Type t in allTypes)
{
try
{
FieldInfo f = t.GetField("ParserKeyword");
string s = "";
if (null != f)
{
s = f.GetValue(null).ToString();
}
else
{
// if the field doesn't exist, use the class name
int index = t.Name.LastIndexOf("Task");
s = index >= 0 ? t.Name.Substring(0, index) : t.Name;
}
foreach (string ss in s.Split(','))
{
String sss = ss.Trim(); /// :rolleyes: @ C#
if (sss != "")
ParserTask.RegisterTask(sss, t);
}
}
catch (Exception)
{
}
}
//string str = "Built-in Tasks: ";
//foreach (string s in internalTypes.Keys) {
// str += s + ", ";
//}
//str += "\n\nUser Tasks: ";
//foreach (string s in userTypes.Keys) {
// str += s + ", ";
//}
//MessageBox.Show("Asm: " + cur.GetName().ToString() + "\n\n" + str);
//str = "";
//foreach (string key in ParserTask.registeredTasks.Keys) {
// str += key + " -> " + ParserTask.registeredTasks[key].FullName + "\n";
//}
//MessageBox.Show("Registered Types:\n\n" + str);
}
public override string DisplayName
{
get
{
return VERSION;
}
}
#region Blacklist Stuff
private Dictionary<string, GSpellTimer> blacklisted = new Dictionary<string, GSpellTimer>();
public void Blacklist(string name, int howlong_seconds)
{
GSpellTimer t = null;
if (blacklisted.TryGetValue(name, out t))
{
blacklisted.Remove(name);
}
t = new GSpellTimer(howlong_seconds * 1000);
blacklisted.Add(name, t);
PPather.WriteLine("Blacklisted " + name + " for " + howlong_seconds + "s");
}
public void Blacklist(long GUID, int howlong_seconds)
{
Blacklist("GUID" + GUID, howlong_seconds);
}
public void Blacklist(GUnit unit)
{
Blacklist(unit.GUID, 15 * 60); // 15 minutes
}
public void Blacklist(GUnit unit, int howlong_seconds)
{
Blacklist(unit.GUID, howlong_seconds);
}
public void Blacklist(String name)
{
Blacklist(name, 15 * 60); // 15 minutes
}
public void UnBlacklist(string name)
{
blacklisted.Remove(name);
PPather.WriteLine("Un-Blacklisted " + name);
}
public void UnBlacklist(long GUID)
{
UnBlacklist("GUID" + GUID);
}
public void UnBlacklist(GUnit u)
{
UnBlacklist(u.GUID);
}
public bool IsBlacklisted(string name)
{
GSpellTimer t = null;
if (!blacklisted.TryGetValue(name, out t))
return false;
return !t.IsReady;
}
public bool IsBlacklisted(long GUID)
{
return IsBlacklisted("GUID" + GUID);
}
public bool IsBlacklisted(GUnit unit)
{
return IsBlacklisted(unit.GUID);
}
#endregion
public void Killed(GUnit unit)
{
//PPather.WriteLine("Killed unit " + unit.Name);
Kills++;
}
public void TargetIs(GUnit unit)
{
form.SetTarget(unit);
}
public void Looted(GUnit unit)
{
//PPather.WriteLine("Looted unit " + unit.Name);
Loots++;
}
public void PickedUp(GNode node)
{
//PPather.WriteLine("Picked up node " + node.Name);
Harvests++;
}
public override void LoadConfig()
{
}
public override void CreateDefaultConfig()
{
}
void Pather_ChatLog(string RawText, string ParsedText)
{
if (ParsedText.Contains("The Horde wins!") ||
ParsedText.Contains("The battle has ended") ||
ParsedText.Contains("The Alliance wins!"))
{
PPather.WriteLine("BG ended: " + ParsedText);
// Context.KillAction("BG ended", false);
}
}
public string CombatLogCleaner(string raw)
{
StringBuilder sb = new StringBuilder();
/*
* Syntax:
* |Hunit:0xXXXXXXXXXXXXXXXX:Name|hName|h
* |cXXXXXXXXstring|r
* */
int len = raw.Length;
for (int i = 0; i < len; i++)
{
char c = raw[i];
if (c == '|')
{
c = raw[++i];
if (c == 'H')
{
while (raw[i++] != '|')
;
i++; // skip the 'h'
while (raw[i] != '|')
sb.Append(raw[i++]);
i++; // skip the 'r'
}
else if (c == 'c')
{
i += 9;
while (raw[i] != '|')
sb.Append(raw[i++]);
i++; // skip the 'r'
}
}
else
sb.Append(c);
}
return sb.ToString();
}
/*
You perform Herb Gathering on Peacebloom.
Toon begins casting Lightning Bolt.
Toon has slain Venomtail Scorpid!
Toon's Lightning Bolt hits Venomtail Scorpid for 1141 Nature.
Venomtail Scorpid died.
* */
void Pather_CombatLog(string rawText)
{
if (rawText == null)
return;
string text = CombatLogCleaner(rawText);
string myname = GContext.Main.Me.Name;
if (text.StartsWith(myname) && text.Contains(" has slain "))
{
int start = text.IndexOf(" has slain ") + 11;
int end = text.IndexOf("!");
String mob = text.Substring(start, end - start);
PPather.WriteLine("Killed mob: " + mob);
if (CurrentPullTask != null)
{
CurrentPullTask.KilledMob(mob);
PPather.WriteLine(CurrentPullTask.ToString());
}
else
{
PPather.WriteLine("No Pull Task");
}
}
}
public string GetCurrentLocation()
{
try
{
GLocation loc = GContext.Main.Me.Location;
if (loc == null)
return null;
return (string.Format(PPather.numberFormat, "[{0,2:#0.0}, {1,2:#0.0}, {2,2:#0.0}]", loc.X, loc.Y, loc.Z));
}
catch (Exception)
{
return null;
}
}
public override void OnStartGlide()
{
Stopped = false;
Helpers.Inventory.ReadyItemCacheTimer();
//Helpers.Equip.ItemCache.Load();
glideThread = Thread.CurrentThread;
glideThread.CurrentCulture = CultureInfo.InvariantCulture;
RunState = RunState_e.Paused;
WantedState = RunState_e.Running;
CurrentPullTask = null;
base.OnStartGlide();
PPather.WriteLine("Memory Usage: " + System.GC.GetTotalMemory(true) / (1024 * 1024) + " MB");
WasAt = null;
CurrentPullTask = null;
string zone = MacrolessZoneInfo.GetZoneText();
string subzone = MacrolessZoneInfo.GetSubZoneText();
MPQTriangleSupplier mpq = new MPQTriangleSupplier();
//CurrentContinent = mpq.SetZone(subzone + ":" + zone);
CurrentContinent = GContext.Main.WorldMap;
mpq.SetContinent(CurrentContinent);
BGMode = false;
PPather.WriteLine("Continent is : " + ((CurrentContinent != "") ? CurrentContinent : "*** unknown"));
PPather.WriteLine("Zone is : " + ((zone != "") ? zone : "*** unknown"));
PPather.WriteLine("Subzone is : " + ((subzone != "") ? subzone : "*** unknown"));
if (Helpers.StopAtLevel.StopAtLevelEnabled)
PPather.WriteLine("!Info:Will auto stop at level " +
PPather.PatherSettings.StopAtLevel.ToString());
if (CurrentContinent.StartsWith("PVPZone") ||
CurrentContinent == "NetherstormBG")
{
BGMode = true;
}
if (!System.IO.File.Exists("PPather\\ccode.dll"))
throw new Exception("ccode.dll wasn't found! Make sure it's in the PPather folder!");
if (!System.IO.File.Exists("PPather\\StormLib.dll"))
throw new Exception("StormLib.dll wasn't found! Make sure it's in the PPather folder!");
string myFaction = "Unknown";
if (IsHordePlayerFaction(Me))
myFaction = "Horde";
if (IsAlliancePlayerFaction(Me))
myFaction = "Alliance";
NPCs.SetContinent(CurrentContinent, myFaction);
ToonData.SetToonName(Me.Name);
ChunkedTriangleCollection triangleWorld = new ChunkedTriangleCollection(512);
triangleWorld.SetMaxCached(9);
triangleWorld.AddSupplier(mpq);
world = new PathGraph(CurrentContinent, triangleWorld, null);
}
private void SaveAllState()
{
NPCs.Save();
ToonData.Save();
if (world != null)
{
world.Save();
}
}
public override void OnStopGlide()
{
if (Stopped)
return;
Stopped = true;
WantedState = RunState_e.Stopped;
RunState = RunState_e.Stopped;
SaveAllState();
if (ToonData != null)
ToonData.SetToonName(null);
if (NPCs != null)
NPCs.SetContinent(null, null); // stop tracking
if (world != null)
world.Close();
world = null;
CurrentPullTask = null;
// forget what we know about battlefield state
BGQueueTaskManager.ResetQueueState();
PPather.WriteLine("Memory Usage Before: " + GC.GetTotalMemory(false) / (1024 * 1024) + " MB");
world = null; // release RAM
GC.Collect();
// passing true to GetTotalMemory isn't the same as calling Collect()
PPather.WriteLine("Memory Usage After: " + GC.GetTotalMemory(true) / (1024 * 1024) + " MB");
GContext.Main.DisableCursorHook();
base.OnStopGlide();
}
public override void Startup()
{
mover = new Mover(Context);
radar = new UnitRadar();
form = new PatherForm(this);
PPather.WriteLine("!Good:PPather Startup - Version " + VERSION);
form.ShowInTaskbar = false;
form.Show();
base.Startup();
GContext.Main.ChatLog += new GContext.GChatLogHandler(Pather_ChatLog);
GContext.Main.CombatLog += new GContext.GCombatLogHandler(Pather_CombatLog);
}
public override void Shutdown()
{
GContext.Main.CombatLog -= new GContext.GCombatLogHandler(Pather_CombatLog);
GContext.Main.ChatLog -= new GContext.GChatLogHandler(Pather_ChatLog);
form.Dispose();
base.Shutdown();
}
public override void Patrol()
{
OnStartGlide();
Kills = 0;
Loots = 0;
Harvests = 0;
XPInitial = Me.Experience;
GliderStart = new GSpellTimer(0);
LogoutTimer = new GSpellTimer(0);
if (!Me.IsInCombat && !Me.IsDead)
Rest();
while (true)
{
MyPather();
Thread.Sleep(1000);
}
}
private void UpdateXP()
{
XPCurrent = Me.Experience;
if (XPCurrent < XPInitial)
{
PPather.WriteLine("!Good:Ding! Congratulations.");
XPInitial = Me.Experience;
XPCurrent = XPInitial;
GliderStart = new GSpellTimer(0);
}
else
{
double XPGained = (double)(XPCurrent - XPInitial);
double time = (double)(-GliderStart.TicksLeft) / 3600000.0; // hours
if (time != 0.0)
{
int XpNeeded = Me.NextLevelExperience - Me.Experience;
int XPPerHour = (int)(XPGained / time);
KPh = (int)((double)Kills / time);
int minsToLvl = XPPerHour == 0 ? 0 : (60 * XpNeeded) / XPPerHour;
//PPather.WriteLine("Kills: " + Kills + " Kills/h: " + KillsPerHour + " XP/h: " + XPPerHour + " TTL: " + minsToLvl + " min");
TTL = minsToLvl;
XPh = XPPerHour;
}
}
}
private GSpellTimer ChunkLoadT = new GSpellTimer(5000, true);
public void ResetMyPos()
{
WasAt = null;
}
public void UpdateMyPos()
{
radar.Update();
if (world != null)
{
GLocation loc = GContext.Main.Me.Location;
Location isAt = new Location(loc.X, loc.Y, loc.Z);
//if(WasAt != null) PPather.WriteLine("was " + WasAt.location);
//PPather.WriteLine("isAt " + isAt);
if (WasAt != null)
{
if (WasAt.GetLocation().GetDistanceTo(isAt) > 20)
WasAt = null;
}
WasAt = world.TryAddSpot(WasAt, isAt);
}
}
public static string GetQuestStatus(string quest)
{
string val = ToonData.Get("Quest:" + quest);
return val;
}
// Quest have 4 states:
// accepted - picked up
// failed - failed for some reason
// goaldone - goal done, need handin
// completed - completed and handed in
// completedr - completed but repeatable
public void QuestAccepted(string name)
{
PPather.WriteLine("!Info:Quest accepted: '" + name + "'");
ToonData.Set("Quest:" + name, "accepted");
}
public void QuestFailed(string name)
{
PPather.WriteLine("!Info:Quest failed: '" + name + "'");
ToonData.Set("Quest:" + name, "failed");
}
public void QuestGoalDone(string name)
{
PPather.WriteLine("!Info:Quest goal done: '" + name + "'");
ToonData.Set("Quest:" + name, "goaldone");
}
public void QuestCompleted(string name, bool repeat)
{
PPather.WriteLine("!Info:Quest completed: '" + name + "'");
ToonData.Set("Quest:" + name, "completed" + ((repeat) ? "r" : ""));
}
public void SetToonState(string key, string value)
{
PPather.WriteLine("!Info:Saved toon state variable: \"" + key + "\" with state: " + value);
ToonData.Set(key, value);
}
public static string GetToonState(string key)
{
string val = ToonData.Get(key);
return val;
}
// completed or failed
public bool IsQuestDone(string name)
{
string val = ToonData.Get("Quest:" + name);
if (val == null)
return false;
if (val == "completedr")
return false;
if (val == "failed" || val == "completed")
return true;
return false;
}
public bool IsQuestFailed(string name)
{
string val = ToonData.Get("Quest:" + name);
if (val == null)
return false;
if (val == "failed")
return true;
return false;
}
public bool IsQuestAccepted(string name)
{
string val = ToonData.Get("Quest:" + name);
if (val == null)
return false;
if (val == "accepted")
return true;
return false;
}
public bool IsQuestGoalDone(string name)
{
string val = ToonData.Get("Quest:" + name);
if (val == null)
return false;
if (val == "goaldone")
return true;
return false;
}
// Called by gui thread
public void UpdateNPCs()
{
if (NPCs == null)
return;
NPCs.Update();
}
public List<GMonster> CheckForMobsAtLoc(GLocation l, float radius)
{
List<GMonster> returns = new List<GMonster>();
GMonster[] mobs = GObjectList.GetMonsters();
if (mobs.Length > 0)
{
foreach (GMonster mob in mobs)
{
float mdt = mob.GetDistanceTo(l);
if (mdt <= radius && !mob.IsDead && !mob.IsTagged)
returns.Add(mob);
}
}
return returns;
}
public Location FindNPCLocation(string name)
{
if (NPCs == null)
return null;
NPCDatabase.NPC npc = NPCs.Find(name);
//PPather.WriteLine("found '" + name + "' or? " + npc);
if (npc == null)
return null;
return new Location(npc.location);
}
public GLocation PredictedLocation(GUnit mob)
{
GLocation currentLocation = mob.Location;
double x = currentLocation.X;
double y = currentLocation.Y;
double z = currentLocation.Z;
double heading = mob.Heading;
double dist = 4;
x += Math.Cos(heading) * dist;
y += Math.Sin(heading) * dist;
GLocation predictedLocation = new GLocation((float)x, (float)y, (float)z);
GLocation closestLocatition = currentLocation;
if (predictedLocation.DistanceToSelf < closestLocatition.DistanceToSelf)
closestLocatition = predictedLocation;
return closestLocatition;
}
public static bool IsStupidItem(GUnit unit)
{
if (unit.CreatureType == GCreatureType.Totem)
return true;
// Filter out all stupid sting found in outland
string name = unit.Name.ToLower();
if (name.Contains("target") || name.Contains("trigger") ||
name.Contains("flak cannon") || name.Contains("trip wire") ||
name.Contains("infernal rain") || name.Contains("anilia") ||
name.Contains("teleporter credit") || name.Contains("door fel cannon") ||
name.Contains("ethereum glaive") || name.Contains("orb flight"))
return true;
return false;
}
public bool IsItSafeAt(GUnit ignore, GUnit u)
{
return IsItSafeAt(ignore, u.Location);
}
public bool IsItSafeAt(GUnit ignore, Location l)
{
return IsItSafeAt(ignore, new GLocation(l.X, l.Y, l.Z));
}
public bool IsItSafeAt(GUnit ignore, GLocation l)
{
/*List<GMonster> mobs = CheckForMobsAtLoc(l, 30.0f); // Setting for radius?
foreach (GMonster mob in mobs) {
if (mob != (GMonster)ignore &&
!IsStupidItem(mob)) {
if (!mob.IsDead && mob.Reaction == GReaction.Hostile &&
!mob.IsTagged)
return false;
}
}*/
return true;
}
public double DistanceToClosestHostileFrom(GUnit target)
{
GMonster m = GObjectList.GetNearestHostile(target.Location, target.GUID, false);
if (m != null)
return m.GetDistanceTo(target);
else
return 1E100;
}
public GPlayer GetClosestPvPPlayer()
{
GPlayer[] plys = GObjectList.GetPlayers();
GPlayer ClosestPlayer = null;
foreach (GPlayer p in plys)
{
if (!p.IsSameFaction && !p.IsDead && p.Location.Z > Me.Location.Z - 5 && p.Location.Z < Me.Location.Z + 5)
{
double d = p.GetDistanceTo(Me);
if ((ClosestPlayer == null || d < ClosestPlayer.GetDistanceTo(Me)))
ClosestPlayer = p;
}
}
return ClosestPlayer;
}
public GPlayer GetClosestPvPPlayerAttackingMe()
{
GPlayer[] plys = GObjectList.GetPlayers();
GPlayer ClosestPlayer = null;
foreach (GPlayer p in plys)
{
if (!p.IsSameFaction && p.Target == Me)
{
if (ClosestPlayer == null || p.GetDistanceTo(Me) < ClosestPlayer.GetDistanceTo(Me))
ClosestPlayer = p;
}
}
return ClosestPlayer;
}
public GPlayer GetClosestFriendlyPlayer()
{
GPlayer[] plys = GObjectList.GetPlayers();
GPlayer ClosestPlayer = null;
foreach (GPlayer p in plys)
{
if (p.IsSameFaction && p != Me)
{
if (ClosestPlayer == null || p.GetDistanceTo(Me) < ClosestPlayer.GetDistanceTo(Me))
ClosestPlayer = p;
}
}
return ClosestPlayer;
}
public GUnit FindAttacker()
{
// Find attackers
GUnit attacker = GObjectList.GetNearestAttacker(0);
if (attacker != null)
{
if (attacker.IsPlayer)
{
// hmmm
if (attacker.IsInCombat &&
attacker.Target != null &&
attacker.Target == GContext.Main.Me)
{
// looks like this sucker is attacking me!
return attacker;
}
}
else
{
return attacker; // a monster
}
}
return null;
}
public bool Face(GUnit monster)
{
return Face(monster, PI / 8);
}
public bool Face(GNode node)
{
return Face(node, PI / 8);
}
public bool Face(GUnit monster, double tolerance)
{
int timeout = 3000;
if (monster == null)
return false;
GSpellTimer approachTimeout = new GSpellTimer(timeout, false);
if (Math.Abs(monster.Bearing) < tolerance)
return true;
bool wasDead = monster.IsDead;
do
{
if (Me.IsDead || wasDead != monster.IsDead)
{
mover.Stop();
return false;
}
double b = monster.Bearing;
if (b < -tolerance)
{
// to the left
mover.RotateLeft(true);
}
else if (b > tolerance)
{
// to the rigth
mover.RotateRight(true);
}
else
{
// ahead
mover.Stop();
return true;
}
UpdateMyPos();
} while (!approachTimeout.IsReadySlow);
mover.Stop();
PPather.WriteLine("!Error:Couldn't face unit");
return false;
}
public bool Face(GNode monster, double tolerance)
{
if (monster == null)
return false;
int timeout = 3000;
if (mover == null)
return false;
GSpellTimer approachTimeout = new GSpellTimer(timeout, false);
if (Math.Abs(monster.Location.Bearing) < tolerance)
return true;
do
{
if (Me.IsDead)
{
mover.Stop();
return false;
}
double b = monster.Location.Bearing;
if (b < -tolerance)
{
// to the left
mover.RotateLeft(true);
}
else if (b > tolerance)
{
// to the rigth
mover.RotateRight(true);
}
else
{
// ahead
mover.Stop();
return true;
}
UpdateMyPos();
} while (!approachTimeout.IsReadySlow);
mover.Stop();
PPather.WriteLine("!Error:Couldn't face unit");
return false;
}
public bool Face(PathObject obj)
{
return Face(obj, PI / 8);