forked from andmer/simpl
/
SimcraftTop.cs
1265 lines (985 loc) · 40 KB
/
SimcraftTop.cs
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 BotBase was created by Apoc, I take no credit for anything within this fullExpression
//I just changed "!StyxWoW.Me.CurrentTarget.IsFriendly" to "!StyxWoW.Me.CurrentTarget.IsHostile"
//For the purpose of allowing RaidBot to work within Arenas
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Profiles;
using Styx.CommonBot.Routines;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Action = Styx.TreeSharp.Action;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Threading;
using Simcraft.APL;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Honorbuddy;
using JetBrains.Annotations;
using Styx.CommonBot.Profiles.Quest.Order;
namespace Simcraft
{
public partial class SimcraftImpl : BotBase
{
public double floor(double a)
{
return Math.Floor(a);
}
public double ceil(double a)
{
return Math.Ceiling(a);
}
public static SimcraftImpl inst;
public delegate bool UnitCriteriaDelegate(WoWUnit u);
private const string SimcraftHookName = "Simcraft.Root";
private static Boolean _aoeEnabled;
private static Boolean _damageEnabled;
private static Boolean _cdsEnabled;
public static int iterationCounter;
public static int iterationCache = 1;
public static DateTime ooc;
public WoWClass _class = StyxWoW.Me.Class;
public Stopwatch _clickTimer = new Stopwatch();
public CombatRoutine _oldRoutine;
public Composite _root;
public dynamic actions;
public dynamic buff; // = new BuffProxy();
public ChiProxy chi; // = new ChiProxy(() => StyxWoW.Me.ToUnit(),this);
public dynamic seal;
public static ActionPrioriyList current_action_list = null;
public Dictionary<string, bool> hotkeyVariables = new Dictionary<string, bool>();
public static bool Superlog = false;
public dynamic totem
{
get { return pet; }
}
public uint[] CobraReset = new uint[] { 131894, 13813, 3044, 2643, 19434, 37506, 80012, 53351, 109259, 117050, 120360, 3674 };
/*"[A Murder of Crows]" + "[Explosive Trap]" + "[Multi-Shot]" + "[Arcane Shot]" +
"[Aimed Shot]" + "[Scatter Shot]" + "[Chimera Shot]" + "[Kill Shot]" + "[Powershot]" +
"[Glaive Toss]" + "[Barrage]" + "[Black Arrow]";*/
public ComboPointProxy combo_points;
public WoWContext Context = WoWContext.PvE;
public dynamic cooldown; // = new CooldownProxy();
public dynamic debuff; // = new DebuffProxy();
public EnergyProxy energy; // = new EnergyProxy(() => StyxWoW.Me.ToUnit(), this);
public FocusProxy focus; // = new FocusProxy(() => StyxWoW.Me.ToUnit(), this);
public HealthProxy health; // = new HealthProxy(() => StyxWoW.Me.ToUnit(), this);
public Stopwatch IterationTimer = new Stopwatch();
public double iterationTotal;
public spell_data_t LastSpellCast;
//public SpellOverride OverrideSpell = new SpellOverride();
public RageProxy rage; // = new RageProxy(() => StyxWoW.Me.ToUnit(), this);
public dynamic spell; // = new SpellProxy();
public dynamic talent; // = new TalentProxy();
public TargetProxy target;
public RunicPowerProxy runic_power;
public DiseaseProxy disease;
public RuneProxy blood;// = new RuneProxy(null,null,RuneType.Blood);
public RuneProxy unholy;
public RuneProxy death;
public RuneProxy frost;
public dynamic glyph;
public RaidEventProxy.FakeEvent movement = new RaidEventProxy.FakeEvent();
public RaidEventProxy.FakeEvent adds = new RaidEventProxy.FakeEvent();
public RaidEventProxy raid_event = new RaidEventProxy();
public dynamic prev_gcd;
public dynamic prev;
public ItemProxy trinket1 = new ItemProxy(WoWEquipSlot.Trinket1);
public ItemProxy trinket2 = new ItemProxy(WoWEquipSlot.Trinket2);
public dynamic set_bonus;
public dynamic pet;
public EclipseProxy eclipse_energy;
public ObliterateProxy obliterate;
public ManaProxy mana;
public HolyPowerProxy holy_power;
public WoWUnit last_judgment_target = null;
public dynamic active_dot;
public dynamic stat;
public ProxyCacheEntry MainCache;
public AuraProxy PlayerAuras = new AuraProxy("player");
public AuraProxy PetAuras = new AuraProxy("pet");
public GetUnitDelegate Target1
{
get { return () => Me.CurrentTarget; }
}
public String FindDatabase()
{
Write("Looking for db.dbc in " + Directory.GetCurrentDirectory()+ " and all its Subdirectories");
string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(),
"db.dbc",
SearchOption.AllDirectories);
if (files.Length == 0) throw new FileNotFoundException("Couldnt find Database", "db.dbc");
return files.First();
}
public static String SimcraftProfilePath = @"Simcraft Profiles/";
public static Database dbc;
public SimcraftImpl()
{
//Write("go!");
try
{
dbc = Serializer.DeSerializeObject(FindDatabase());
}
catch (Exception e)
{
Write(e.ToString());
}
spell_data_t[] a = new spell_data_t[dbc.Spells.Values.Count];
dbc.Spells.Values.CopyTo(a, 0);
foreach (var v in a)
{
dbc.Spells[v.id, v.token] = v;
}
Write("Count "+dbc.Spells.Count);
Directory.CreateDirectory(SimcraftProfilePath);
try
{
RoutineManager.Current = null;
SimcNames.Populate();
MainCache = new ProxyCacheEntry();
inst = this;
active_dot = new ActiveDot();
//trinket = new TrinketProxy(() => StyxWoW.Me.ToUnit(), this);
health = new HealthProxy(() => StyxWoW.Me.ToUnit());
energy = new EnergyProxy(() => StyxWoW.Me.ToUnit());
focus = new FocusProxy(() => StyxWoW.Me.ToUnit());
chi = new ChiProxy(() => StyxWoW.Me.ToUnit());
rage = new RageProxy(() => StyxWoW.Me.ToUnit());
buff = new BuffProxy(() => StyxWoW.Me.ToUnit(), PlayerAuras);
debuff = new DebuffProxy(() => conditionUnit);
talent = new TalentProxy(() => StyxWoW.Me.ToUnit());
cooldown = new CooldownProxy(() => StyxWoW.Me.ToUnit());
spell = new SpellProxy(() => StyxWoW.Me.ToUnit());
combo_points = new ComboPointProxy(() => StyxWoW.Me.ToUnit());
target = new TargetProxy(() => conditionUnit);
runic_power = new RunicPowerProxy(() => StyxWoW.Me.ToUnit());
disease = new DiseaseProxy(this);
blood = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Blood);
unholy = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Unholy);
frost = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Frost);
death = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Death);
glyph = new GlyphProxy(() => StyxWoW.Me.ToUnit());
set_bonus = new SetBonusProxy();
prev_gcd = new PrevGcdProxy();
prev = new PrevGcdProxy();
pet = new PetProxy("def");
eclipse_energy = new EclipseProxy(() => StyxWoW.Me.ToUnit());
mana = new ManaProxy(() => StyxWoW.Me.ToUnit());
holy_power = new HolyPowerProxy(() => StyxWoW.Me.ToUnit());
seal = new SealProxy();
actions = new ActionProxy();
stat = new StatProxy();
obliterate = new ObliterateProxy();
MainCache["gcd"].SetRetrievalDelegate(() =>
{
var rem = (Decimal)SpellManager.GlobalCooldownLeft.TotalSeconds;
var g = BaseGcd();
g = g / ((100+spell_haste)/ 100);
return new Gcd((Decimal)_conditionSpell.gcd, Math.Max(g, 1), rem);
});
MainCache["GlobalCooldown"].SetRetrievalDelegate(() =>
{
return SpellManager.GlobalCooldownLeft.TotalMilliseconds > 1000/15;
});
MainCache["WoWTime"].SetRetrievalDelegate(() =>
{
return Lua.GetReturnVal<double>("return GetTime()",0);
});
var s = new spell_data_t();
s.name = "Storm, Earth, and Fire";
s.token = "storm_earth_and_fire";
s.id = 138130;
dbc.Spells.Add(138130, s);
}
catch (Exception e)
{
Write(e.ToString());
}
}
public Decimal BaseGcd()
{
switch (_class)
{
//hunters, rogues, [Cat Form] druids, monks and death knights,
case WoWClass.Hunter:
case WoWClass.Rogue:
case WoWClass.Druid:
case WoWClass.Monk:
case WoWClass.DeathKnight:
if (_spec != WoWSpec.DruidBalance && _spec != WoWSpec.DruidGuardian && _spec != WoWSpec.DruidRestoration)
return 1;
break;
}
return (Decimal)1.5;
}
public override Form ConfigurationForm
{
get { return new ConfigWindow(); }
}
public override string Name
{
get { return "Simcraft Impl"; }
}
public override Composite Root
{
get
{
if (_root == null)
_root = new HookExecutor(SimcraftHookName);
return _root;
}
}
public override PulseFlags PulseFlags
{
get { return PulseFlags.Objects | PulseFlags.Lua; }
}
public static bool IsPaused { get; set; }
public WoWClass Class
{
get { return StyxWoW.Me.Class; }
}
public static LocalPlayer Me
{
get { return StyxWoW.Me; }
}
public dynamic action
{
get { return spell; }
}
public dynamic dot
{
get { return debuff; }
}
public WoWUnit conditionUnit { get; set; }
public double time
{
get { return (DateTime.Now - ooc).TotalSeconds; }
}
private static Random Randomizer = new Random((int)DateTime.Now.Ticks);
private static string RandomString(int size)
{
StringBuilder builder = new StringBuilder();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * Randomizer.NextDouble() + 65)));
builder.Append(ch);
}
return builder.ToString();
}
public static Dictionary<String, ActionPrioriyList> apls = new Dictionary<String, ActionPrioriyList>();
public static void GenerateApls(String folder)
{
apls.Clear();
inst.actions.Reset();
if (current_action_list != null ) current_action_list.Unload();
SimcraftImpl.Write("Compiling Action Lists");
foreach (var filename in Directory.GetFiles(folder))
{
if (!filename.EndsWith(".simc")) continue;
String contents = File.ReadAllText(filename);
var currentApl = ActionPrioriyList.FromString(contents);
if (currentApl.Class != Me.Class) continue;
var code = currentApl.ToCode();
var classname = RandomString(10);
code = code.Replace("public class SimcraftRota", "public class "+classname);
//SimcraftImpl.Write(code);
Assembly asm = RuntimeCodeCompiler.CompileCode(code);
Behavior attributes =
(Behavior)asm.GetTypes()[0].GetMembers()[0].GetCustomAttributes(typeof(Behavior), true).First();
currentApl.Assembly = asm;
SimcraftImpl.Write("New Apl: " + currentApl.Name);
apls[currentApl.ToString()] = currentApl;
}
}
public static void Main()
{
dbc = Serializer.DeSerializeObject("db.dbc");
spell_data_t[] a = new spell_data_t[dbc.Spells.Values.Count];
dbc.Spells.Values.CopyTo(a, 0);
foreach (var v in a)
{
dbc.Spells[v.id, v.token] = v;
}
int c = 0;
String akk = "";
SimcNames.Populate();
//var u = new SimcNames.SpecList { new SimcNames.SpecPair(WoWSpec.None, 1), };
/*foreach (var s in SimcNames.spells.Keys)
{
if (SimcNames.spells[s].Count == 0) Console.WriteLine("spell::"+s);
}
foreach (var s in SimcNames.debuffs.Keys)
{
if (SimcNames.debuffs[s].Count == 0) Console.WriteLine("debuff::" + s);
}
foreach (var s in SimcNames.buffs.Keys)
{
if (SimcNames.buffs[s].Count == 0) Console.WriteLine("buff::" + s);
}*/
//var attr = dbc.Spells[SimcNames.spells["sinister_strike"].First().V2].attr1;
foreach (var s in dbc.Spells.Values)
{
if (s.IsChanneled() && SimcNames.spells.ContainsKey(s.token)) Console.WriteLine(s.name);
}
Console.ReadKey();
/*String content = "";
foreach (var s in SimcNames.spells.Keys)
{
if (!dbc.Spells.RelationContainsKey(s))
{
content += "spells[\"" + s + "\"]=new SpecList();" + Environment.NewLine;
continue;
}
string arr = "";
foreach (var e in GetAllSpells(s))
{
arr += "new SpecPair(WoWSpec.None, "+e.id+"),";
}
content += "spells[\"" + s + "\"]=new SpecList{" +arr+ "};" + Environment.NewLine;
}
foreach (var s in SimcNames.buffs.Keys)
{
if (!dbc.Spells.RelationContainsKey(s))
{
content += "buffs[\"" + s + "\"]=new SpecList();" + Environment.NewLine;
continue;
}
string arr = "";
foreach (var e in GetAllSpells(s))
{
arr += "new SpecPair(WoWSpec.None, " + e.id + "),";
}
content += "buffs[\"" + s + "\"]=new SpecList{" + arr + "};" + Environment.NewLine;
}
foreach (var s in SimcNames.debuffs.Keys)
{
if (!dbc.Spells.RelationContainsKey(s))
{
content += "debuffs[\"" + s + "\"]=new SpecList();" + Environment.NewLine;
continue;
}
string arr = "";
foreach (var e in GetAllSpells(s))
{
arr += "new SpecPair(WoWSpec.None, " + e.id + "),";
}
content += "debuffs[\"" + s + "\"]=new SpecList{" + arr + "};" + Environment.NewLine;
}
File.WriteAllText("a.txt",content);
Console.WriteLine(c);
//Console.WriteLine(FindBuff("steady_focus").tooltip);
//Console.WriteLine(e.Spells[lid].name + " " + e.Spells[lid].desc);*/
}
public static List<spell_data_t> GetAllSpells(String token)
{
var ret = new List<spell_data_t>();
foreach (var s in dbc.Spells[token])
{
ret.Add(dbc.Spells[s]);
}
return ret;
}
public static List<Effect> GetAllSpellEffects(spell_data_t t)
{
var ret = new List<Effect>();
foreach (var ef in t.effects)
{
ret.Add(dbc.Effects[ef]);
}
return ret;
}
public static spell_data_t FindDebuff(String token)
{
if (SimcNames.debuffs.ContainsKey(token))
{
var simcSpell = SimcNames.debuffs[token];
if (simcSpell.Count == 1)
{
return dbc.Spells[simcSpell[0].V2];
}
foreach (var s in simcSpell)
{
if (s.V1 == WoWSpec.None || s.V1 == Me.Specialization)
{
return dbc.Spells[s.V2];
}
}
}
var spells = GetAllSpells(token);
uint lid = uint.MaxValue;
bool casdam = false;
if (spells.Count == 1) return dbc.Spells[spells.First().id];
foreach (var spell in spells)
{
if (spell.tooltip.Length < 2) continue;
bool hasAura = false;
bool hasDamage = false;
foreach (var ef in GetAllSpellEffects(spell))
{
if (ef.type.Equals("E_APPLY_AURA"))
{
hasAura = true;
if (ef.sub_type.Contains("DAMAGE"))
hasDamage = true;
}
}
if (!hasAura) continue;
if (!casdam && hasDamage)
{
lid = spell.id;
casdam = true;
}
if ((casdam && hasDamage) || (!casdam && !hasDamage) && spell.id < lid)
{
lid = spell.id;
}
}
if (lid < uint.MaxValue)
return dbc.Spells[lid];
throw new Exception("No Debuff named " + token + " found");
}
public static spell_data_t FindBuff(String token)
{
if (SimcNames.buffs.ContainsKey(token))
{
var simcSpell = SimcNames.buffs[token];
if (simcSpell.Count == 1)
{
return dbc.Spells[simcSpell[0].V2];
}
foreach (var s in simcSpell)
{
if (s.V1 == WoWSpec.None || s.V1 == Me.Specialization)
{
return dbc.Spells[s.V2];
}
}
}
var spells = GetAllSpells(token);
uint lid = uint.MaxValue;
if (spells.Count == 1) return dbc.Spells[spells.First().id];
foreach (var spell in spells)
{
if (spell.tooltip.Length < 2) continue;
bool hasAura = false;
foreach (var ef in GetAllSpellEffects(spell))
{
if (ef.type.Equals("E_APPLY_AURA") && !ef.sub_type.Contains("DAMAGE"))
{
hasAura = true;
}
}
if (!hasAura) continue;
if (spell.id < lid) lid = spell.id;
}
if (lid < uint.MaxValue)
return dbc.Spells[lid];
throw new Exception("No Buff named "+token+" found");
}
public Composite CombatIteration()
{
return new Action(delegate
{
//if (iterationCounter%7 == 0)
/*if (console != null %% console.Va)console.BeginInvoke((System.Action)(() =>
{
console.reset();
}));*/
//console.BeginInvoke(new Delegate(console,"reset"));
//console.reset();
//Write(Me.Pet.);
combatIterationCount++;
IterationTimer.Restart();
if (SpellIsTargeting)
{
SimcraftImpl.Write("Wanting to click: " + clickUnit);
//Write("Clicking: " + clickUnit.Location + " " + iterationCounter);
SpellManager.ClickRemoteLocation(clickUnit.Location);
clickUnit = null;
}
//Write("u:{0} b:{1} f:{2}", unholy.current, death.current, frost.current);
//OverrideSpell.Pulse();
return RunStatus.Failure;
});
}
public Composite IterationEnd()
{
return new Action(delegate
{
IterationTimer.Stop();
iterationTotal += IterationTimer.ElapsedMilliseconds;
//if (IterationTimer.ElapsedMilliseconds > 1) Write(DateTime.Now.Millisecond+": "+IterationTimer.ElapsedMilliseconds+"");
if (combatIterationCount % 150 == 0) SimcraftImpl.Write("avgIte: " + (iterationTotal / combatIterationCount));
//Write(""+IterationTimer.ElapsedMilliseconds);
});
}
static Regex token = new Regex("[^a-z_ 0-9]");
private static String Tokenize(String s)
{
s = s.ToLower();
s = token.Replace(s, "");
s = s.Replace(' ', '_');
return s;
}
private void COMBATLOG_EVENT_UNFILTERED(object sender, LuaEventArgs args)
{
/*var s = "";
foreach (var arg in args.Args)
{
s += arg.ToString() + " ";
}*/
Logging.Write(args.EventName);
}
private void UNIT_SPELLCAST_SUCCEEDED(object sender, LuaEventArgs args)
{
//Logging.Write(args.EventName);
//Write("bc: "+pet.buff.beast_cleave.up);
//Write("ff: " + buff.frenzy.stack);
//(Write("rav"+talent.ravager.enabled);
//Write("ava:"+talent.avatar.enabled);
/* var sw = new Stopwatch();
sw.Restart();
string cc = "local can_cast = {};";
int i = 0;
foreach (var sp in current_action_list.spells)
{
cc += "u, m = IsUsableSpell(\""+"Kill Command"+"\"); can_cast["+i+"] = u;";
i++;
}
cc += "return unpack(can_cast);";
Lua.GetReturnValues(cc);
Logging.Write(""+sw.ElapsedTicks+" checked spells "+i);*/
if (args.Args[0].ToString().Equals("player"))
{
uint spellid = uint.Parse(args.Args[4].ToString());
if (!dbc.Spells.ContainsKey(spellid)) return;
LastSpellCast = dbc.Spells[spellid];
prev.spell = LastSpellCast;
LogDebug("Cast: " + LastSpellCast.name);
if (LastSpellCast.id == 78203)
{
var s = new Stopwatch();
s.Start();
apparitions.Add(s);
}
if (LastSpellCast.id == 8092)
{
if (conditionUnit != null)
conditionUnit.ApplyMindHarvest();
}
if (LastSpellCast.id == 20271)
{
last_judgment_target = conditionUnit;
}
if (LastSpellCast.gcd > 0)
prev_gcd.spell = LastSpellCast;
if (LastSpellCast.name.Contains("Seal of"))
{
seal.active = LastSpellCast.token.Split('_')[2];
}
if (talent.steady_focus.enabled)
{
if (LastSpellCast.id == 77767)
{
BuffProxy.cShots++;
if (BuffProxy.cShots == 2)
{
BuffProxy.cShots = 0;
SimcraftImpl.Write(DateTime.Now + ": Steady Shots!");
}
}
if (CobraReset.Contains(LastSpellCast.id) && BuffProxy.cShots > 0)
{
BuffProxy.cShots = 0;
}
}
}
}
public override void Initialize()
{
var x = SimCSettings.currentSettings;
}
public WoWSpec Specialisation = WoWSpec.None;
public void ContextChange(object sender, LuaEventArgs args)
{
talent.Reset();
glyph.Reset();
spell.Reset();
line_cds.Clear();
PlayerAuras.Reset();
PetAuras.Reset();
_class = StyxWoW.Me.Class;
//_spec = Me.Specialization;
var oldctx = Context;
Context = (StyxWoW.Me.CurrentMap.IsArena || StyxWoW.Me.CurrentMap.IsBattleground)
? WoWContext.PvP
: WoWContext.PvE;
if (Context != oldctx) SimcraftImpl.Write("Switching to " + Context + " Mode");
ooc = DateTime.Now;
RebuildBehaviors();
}
public static ProfileSelector SelectorWindow = new ProfileSelector();
public static DevConsole console = new DevConsole();
public WoWSpec _spec = WoWSpec.None;
public override void Start()
{
try
{
Specialisation = WoWSpec.None;
NamedComposite.Sequence = "";
TreeRoot.TicksPerSecond = 8;
ProfileManager.LoadEmpty();
//_oldRoutine = RoutineManager.Current; //Save it so we can restore it later
RoutineManager.Current = new ProxyRoutine();
Lua.Events.RemoveFilter("COMBATLOG_EVENT_UNFILTERED");
Lua.Events.AttachEvent("UNIT_SPELLCAST_SUCCEEDED", UNIT_SPELLCAST_SUCCEEDED);
Lua.Events.AttachEvent("COMBATLOG_EVENT_UNFILTERED", COMBATLOG_EVENT_UNFILTERED);
Lua.Events.AttachEvent("CHARACTER_POINTS_CHANGED", ContextChange);
Lua.Events.AttachEvent("PLAYER_LOGOUT", ContextChange);
Lua.Events.AttachEvent("PLAYER_TALENT_UPDATE", ContextChange);
Lua.Events.AttachEvent("UNIT_AURA", PlayerAuras.UNIT_AURA);
Lua.Events.AttachEvent("UNIT_AURA", PetAuras.UNIT_AURA);
ContextChange(null, null);
RegisterHotkeys();
}
catch (Exception e)
{
SimcraftImpl.Write(e.ToString());
}
}
public override void Stop()
{
//SimcraftImpl.Write(NamedComposite.Sequence);
NameCount = 'A';
TreeRoot.ResetTicksPerSecond();
//RoutineManager.Current = _oldRoutine;
UnregisterHotkeys();
Lua.Events.DetachEvent("UNIT_SPELLCAST_SUCCEEDED", UNIT_SPELLCAST_SUCCEEDED);
Lua.Events.DetachEvent("CHARACTER_POINTS_CHANGED", ContextChange);
Lua.Events.DetachEvent("PLAYER_LOGOUT", ContextChange);
Lua.Events.DetachEvent("PLAYER_TALENT_UPDATE", ContextChange);
Lua.Events.DetachEvent("UNIT_AURA", PlayerAuras.UNIT_AURA);
Lua.Events.DetachEvent("UNIT_AURA", PetAuras.UNIT_AURA);
Lua.Events.DetachEvent("COMBATLOG_EVENT_UNFILTERED", COMBATLOG_EVENT_UNFILTERED);
}
public class AuraProxy : Proxy
{
private String Unit;
private Stopwatch iterationTimer = new Stopwatch();
public struct Aura
{
public uint Spell;
public Decimal Duration;
public int Stack;
public Decimal ExpirationTime;
public String Caster;
public String DebuffType;
private SimcraftImpl simc
{
get { return SimcraftImpl.inst; }
}
public TimeSpan TimeLeft()
{
var time = simc.GetTime();
var sLeft = ExpirationTime - time;
sLeft *= 1000;
if (sLeft < 0) return TimeSpan.Zero;
return new TimeSpan(0, 0, 0, 0, (int)sLeft);
}
}
public bool GetAuraUp(uint id)
{
return auras.ContainsKey(id);
}
public TimeSpan GetAuraTimeLeft(uint id)
{
if (!auras.ContainsKey(id)) return TimeSpan.Zero;
return auras[id].TimeLeft();
}
public Decimal GetAuraDuration(uint id)
{
if (!auras.ContainsKey(id)) return 0;
return auras[id].Duration;
}
public Decimal GetAuraStacks(uint id)
{
if (!auras.ContainsKey(id)) return 0;
return auras[id].Stack;
}
public AuraProxy(String unit)
{
Unit = unit;
}
private SimcraftImpl simc
{
get { return SimcraftImpl.inst; }
}
private int lastIteCount = -1;
Dictionary<uint, Aura> auras = new Dictionary<uint, Aura>();
public void Reset()
{
auras.Clear();
}
public void UNIT_AURA(object sender, LuaEventArgs args)
{
iterationTimer.Restart();
//if (lastIteCount == iterationCounter) return;
//lastIteCount = iterationCounter;
String u = args.Args[0].ToString();
if (!u.Equals(Unit)) return;
auras.Clear();
int i = 1;
try
{
var lt =
Lua.GetReturnValues(
"auras={} for i=1,40 do local u = \"\" local p = \",\" local a,b,c,d,e,f,g,h,j,k,l = UnitAura(\""+Unit+"\",i);" +
"a=a and a or u;b=b and b or u;c=c and c or u;d=d and d or u;e=e and e or u;f=f and f or u;g=g and g or u;h=h and h or u;j=j and j or u;k=k and k or u;l=l and l or u; " +
"z = d..p..e..p..f..p..g..p..h..p..l; auras[i] = z;" +
"end return unpack(auras)");
foreach (var ar in lt)
{
var ars = ar.Split(',');
if (ars[5].Length < 2) continue;
var a = new Aura
{
Caster = ars[4].ToString(),
Duration = Convert.ToDecimal(ars[2].ToString()),
ExpirationTime = Convert.ToDecimal(ars[3].ToString()),
Stack = Convert.ToInt32(ars[0].ToString()),
};
var sid = Convert.ToUInt32(ars[5]);
/*if (!dbc.Spells.ContainsKey(sid))
{
//Logging.Write("No Spell with ID "+sid);
continue;
}*/
a.Spell = sid;
auras[sid] = a;
//Logging.Write("id({0}) stack({1}) duration({2}) expiration({3}) caster({4})", sid,
// a.Stack, a.Duration, simc.GetTime(), a.TimeLeft());
}