forked from andmer/simpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimcraftTop.cs
832 lines (674 loc) · 28.4 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
//This BotBase was created by Apoc, I take no credit for anything within this code
//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;
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 dynamic totem
{
get { return pet; }
}
public String CobraReset = "[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 String 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 StatProxy stat;
public WoWUnit Target1
{
get
{
try
{
return Me.CurrentTarget;
}
catch
{
return null;
}
}
}
public String FindDatabase()
{
Logging.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 String SimcraftLogPath = @"Logs/Simcraft/";
public static String SimcraftLogfile;//
public static Database dbc;
public SimcraftImpl()
{
SimcraftLogfile = SimcraftLogPath + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss") + " - " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + " " + Tokenize(Me.Name) + ".log";
//Logging.Write("go!");
try
{
dbc = Serializer.DeSerializeObject(FindDatabase());
}
catch (Exception e)
{
Logging.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;
}
Logging.Write("Count "+dbc.Spells.Count);
Directory.CreateDirectory(SimcraftProfilePath);
Directory.CreateDirectory(SimcraftLogPath);
inst = this;
active_dot = new ActiveDot();
//trinket = new TrinketProxy(() => StyxWoW.Me.ToUnit(), this);
health = new HealthProxy(() => StyxWoW.Me.ToUnit(), this);
energy = new EnergyProxy(() => StyxWoW.Me.ToUnit(), this);
focus = new FocusProxy(() => StyxWoW.Me.ToUnit(), this);
chi = new ChiProxy(() => StyxWoW.Me.ToUnit(), this);
rage = new RageProxy(() => StyxWoW.Me.ToUnit(), this);
buff = new BuffProxy(() => StyxWoW.Me.ToUnit(), this);
debuff = new DebuffProxy(() => conditionUnit, this);
talent = new TalentProxy(() => StyxWoW.Me.ToUnit(), this);
cooldown = new CooldownProxy(() => StyxWoW.Me.ToUnit(), this);
spell = new SpellProxy(() => StyxWoW.Me.ToUnit(), this);
combo_points = new ComboPointProxy(() => StyxWoW.Me.ToUnit(), this);
target = new TargetProxy(() => conditionUnit, this);
runic_power = new RunicPowerProxy(() => StyxWoW.Me.ToUnit(), this);
disease = new DiseaseProxy(this);
blood = new RuneProxy(() => StyxWoW.Me.ToUnit(), this, RuneType.Blood);
unholy = new RuneProxy(() => StyxWoW.Me.ToUnit(), this, RuneType.Unholy);
frost = new RuneProxy(() => StyxWoW.Me.ToUnit(), this, RuneType.Frost);
death = new RuneProxy(() => StyxWoW.Me.ToUnit(), this, RuneType.Death);
glyph = new GlyphProxy(() => StyxWoW.Me.ToUnit(), this);
set_bonus = new SetBonusProxy();
prev_gcd = new PrevGcdProxy();
prev = new PrevGcdProxy();
pet = new PetProxy("def");
eclipse_energy = new EclipseProxy(() => StyxWoW.Me.ToUnit(), this);
mana = new ManaProxy(() => StyxWoW.Me.ToUnit(), this);
holy_power = new HolyPowerProxy(() => StyxWoW.Me.ToUnit(), this);
seal = new SealProxy();
actions = new ActionProxy();
stat = new StatProxy();
obliterate = new ObliterateProxy();
//Logging.Write("eyo");
dbc.ClassSpells["invoke_xuen"] = DBGetClassSpell("invoke_xuen_the_white_tiger").id;//dbc.Spells["invoke_xuen_the_white_tiger"].id;
dbc.ClassSpells["tigereye_brew_use"] = DBGetClassSpell("tigereye_brew").id;
dbc.ClassSpells["combo_breaker_bok"] = DBGetClassSpell("combo_breaker_blackout_kick").id;
dbc.ClassSpells["combo_breaker_tp"] = DBGetClassSpell("tigereye_brew").id;
dbc.ClassSpells["combo_breaker_ce"] = DBGetClassSpell("combo_breaker_tiger_palm").id;
dbc.ClassSpells["storm_earth_and_fire_target"] = DBGetClassSpell("storm_earth_and_fire").id;
dbc.ClassSpells["service_pet"] = DBGetSpell("grimoire_of_service").id;
var arch = DBGetSpell("Archmage's Incandescence");
var garch = DBGetSpell("Archmage's Greater Incandescence");
dbc.Spells[arch.id, arch.token + "_agi"] = arch;
dbc.Spells[arch.id, arch.token + "_str"] = arch;
dbc.Spells[arch.id, arch.token + "_int"] = arch;
dbc.Spells[garch.id, garch.token + "_agi"] = garch;
dbc.Spells[garch.id, garch.token + "_str"] = garch;
dbc.Spells[garch.id, garch.token + "_int"] = garch;
}
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();
SimcraftImpl.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);
var old = Superlog;
Superlog = true;
SimcraftImpl.Write(code, Colors.White, LogLevel.Diagnostic);
//Console.WriteLine(code);
Superlog = old;
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()
{
//Logging.Write("go!");
/*try
{
dbc = Serializer.DeSerializeObject(FindDatabase());
}
catch (Exception e)
{
Logging.Write(e.ToString());
}*/
var e = Serializer.DeSerializeObject("db.dbc");
spell_data_t[] a = new spell_data_t[e.Spells.Values.Count];
e.Spells.Values.CopyTo(a, 0);
foreach (var v in a)
{
e.Spells[v.id, v.token] = v;
int count = 0;
foreach (var eid in v.effects)
{
if (e.Effects[eid].sub_type.Contains("PERIODIC") && e.Effects[eid].type.Contains("E_APPLY_AURA"))
count++;
}
if (count > 1) Console.WriteLine(v.name+" has multiple periodic");
}
Console.WriteLine("Count " + e.Spells.Count);
Console.ReadKey();
}
public Composite CombatIteration()
{
return new Action(delegate
{
//Logging.Write(Me.Pet.);
IterationTimer.Restart();
if (SpellIsTargeting)
{
SimcraftImpl.Write("Wanting to click: " + clickUnit);
//Logging.Write("Clicking: " + clickUnit.Location + " " + iterationCounter);
SpellManager.ClickRemoteLocation(clickUnit.Location);
clickUnit = null;
}
//Logging.Write("u:{0} b:{1} f:{2}", unholy.current, death.current, frost.current);
iterationCounter++;
UpdateLimiters();
energy.Pulse();
focus.Pulse();
OverrideSpell.Pulse();
return RunStatus.Failure;
});
}
public Composite IterationEnd()
{
return new Action(delegate
{
IterationTimer.Stop();
iterationTotal += IterationTimer.ElapsedMilliseconds;
if (iterationCounter % 150 == 0) SimcraftImpl.Write("avgIte: " + (iterationTotal / iterationCounter));
//Logging.Write(""+IterationTimer.ElapsedMilliseconds);
});
}
public MagicValueType gcd
{
get
{
//if (!dbc.ClassSpells.ContainsKey(Tokenize(_conditionSpell))) return new MagicValueType(1.5);
//return new MagicValueType(dbc.ClassSpells[Tokenize(_conditionSpell)].Gcd);
return spell[_conditionSpell].gcd;
}
}
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 String[] weird_gcd_fuckers = new[] {"Ravager"};
private void UNIT_SPELLCAST_SUCCEEDED(object sender, LuaEventArgs args)
{
if (args.Args[0].ToString().Equals("player"))
{
//Logging.Write("Renddur: "+debuff.rupture.ticks_remain);
//Logging.Write(""+DBGetSpell("Whirlwind").Gcd);
//SimcraftImpl.Write(blood.frac + " " + frost.frac + " " + unholy.frac + " " + death.frac+ " " +blood.current + " " + frost.current + " " + unholy.current + " " + death.current+ " "+disease.ticking+ " "+disease.max_remains+ " "+disease.min_remains);
LastSpellCast = args.Args[1].ToString();
if (LastSpellCast.Equals("Shadowy Apparition"))
{
var s = new Stopwatch();
s.Start();
apparitions.Add(s);
}
if (LastSpellCast.Equals("Mind Blast"))
{
if (conditionUnit != null)
conditionUnit.ApplyMindHarvest();
}
if (LastSpellCast.Contains("Seal of"))
{
seal.active = Tokenize(LastSpellCast).Split('_')[2];
//Logging.Write(seal.active);
}
if (LastSpellCast.Contains("Judgment"))
{
last_judgment_target = conditionUnit;
}
var spell = DBGetClassSpell(LastSpellCast);
if (spell.gcd > 0 || weird_gcd_fuckers.Contains(spell.name))
{
Logging.Write(spell.name);
prev_gcd.Id = spell.id;
//Logging.Write(spell.Name + " using Gcd Cast");
}
else
{
//Logging.Write(spell.Name + " without Gcd Cast");
}
prev.id = spell.id;
//Lua.DoString("_G[\"kane_spd\"] = \"" + LastSpellCast + "\";");
if (LastSpellCast.Equals(OverrideSpell.Spell))
{
SimcraftImpl.Write("Override Spell Cast, disabling");
OverrideSpell.Enabled = false;
}
if (Me.Specialization == WoWSpec.HunterSurvival && !talent[DBGetTalentSpell("Focusing Shot").name].enabled)
{
if (LastSpellCast.Equals(DBGetSpell("Cobra Shot").name) || LastSpellCast.Equals(DBGetTalentSpell("Focusing Shot").name))
{
BuffProxy.cShots++;
if (BuffProxy.cShots == 2)
{
BuffProxy.cShots = 0;
SimcraftImpl.Write(DateTime.Now + ": Steady Shots!");
}
}
if (CobraReset.Contains(LastSpellCast) && BuffProxy.cShots > 0)
{
BuffProxy.cShots = 0;
}
}
}
}
public void LogDebug(String stuff)
{
Write(stuff,Colors.Violet,LogLevel.Diagnostic);
}
public override void Initialize()
{
var x = SimCSettings.currentSettings;
}
public WoWSpec Specialisation = WoWSpec.None;
public void ContextChange(object sender, LuaEventArgs args)
{
//SimcraftImpl.Write(args != null ? args.EventName : "CTX");
talent.Reset();
glyph.Reset();
spell.Reset();
spell.Reset();
line_cds.Clear();
//actions.Reset();
_class = StyxWoW.Me.Class;
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 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.AttachEvent("UNIT_SPELLCAST_SUCCEEDED", UNIT_SPELLCAST_SUCCEEDED);
Lua.Events.AttachEvent("CHARACTER_POINTS_CHANGED", ContextChange);
Lua.Events.AttachEvent("PLAYER_LOGOUT", ContextChange);
Lua.Events.AttachEvent("PLAYER_TALENT_UPDATE", ContextChange);
ContextChange(null, null);
RegisterHotkeys();
}
catch (Exception e)
{
SimcraftImpl.Write(e.ToString());
}
}
public static void RegisterHotkeys()
{
HotkeysManager.Register("Simcraft Pause",
SimCSettings.currentSettings.Execution.key,
SimCSettings.currentSettings.Execution.mod,
hk =>
{
IsPaused = !IsPaused;
if (IsPaused)
{
Lua.DoString("print('Execution Paused!')");
// Make the bot use less resources while paused.
TreeRoot.TicksPerSecond = 5;
}
else
{
Lua.DoString("print('Execution Resumed!')");
// Kick it back into overdrive!
TreeRoot.TicksPerSecond = 8;
}
});
HotkeysManager.Register("Simcraft AOE",
SimCSettings.currentSettings.Aoe.key,
SimCSettings.currentSettings.Aoe.mod,
hk =>
{
Lua.DoString("if _G[\"kane_aoe\"] == true then _G[\"kane_aoe\"] = nil; print('AOE enabled'); else _G[\"kane_aoe\"] = true; print('AOE disabled') end");
});
HotkeysManager.Register("Simcraft Cooldowns",
SimCSettings.currentSettings.Cooldowns.key,
SimCSettings.currentSettings.Cooldowns.mod,
hk =>
{
Lua.DoString("if _G[\"kane_cds\"] == true then _G[\"kane_cds\"] = nil; print('Cds enabled') else _G[\"kane_cds\"] = true; print('Cds disabled') end");
});
}
public static void UnregisterHotkeys()
{
HotkeysManager.Unregister("Simcraft Pause");
HotkeysManager.Unregister("Simcraft Cooldowns");
HotkeysManager.Unregister("Simcraft AOE");
}
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);
}
public void RebuildBehaviors()
{
Composite simcRoot = null;
NameCount = 'A';
simcRoot = new PrioritySelector(
new Decorator(ret => IsPaused,
new Action(ret => RunStatus.Success)),
CallActionList(ActionProxy.ActionImpl.oocapl, ret => !StyxWoW.Me.Combat),
new Decorator(ret => StyxWoW.Me.Combat,
new LockSelector(
new Decorator(
ret => StyxWoW.Me.CurrentTarget != null && StyxWoW.Me.Combat,
new PrioritySelector(CombatIteration(), CastOverride(), actions.Selector, IterationEnd())))));
TreeHooks.Instance.ReplaceHook(SimcraftHookName, simcRoot);
//SimcraftImpl.Write(Specialisation+" "+Me.Specialization);
if (Me.Specialization != Specialisation)
{
SelectorWindow.ShowDialog();
}
Specialisation = Me.Specialization;
}
public Composite CastOverride()
{
return new PrioritySelector(
new Action(delegate
{
_conditionSpell = OverrideSpell.Spell;
return RunStatus.Failure;
}),
new Decorator(ret => OverrideSpell.Enabled,
new Action(delegate
{
if (CastSpell(OverrideSpell.Spell, OverrideSpell.Target, 3, "SpellOverride"))
return RunStatus.Success;
return RunStatus.Failure;
})));
}
public class SpellOverride
{
public enum OverrideTarget
{
Target,
Focus
}
public enum OverrideType
{
Location,
Target
}
private readonly String reset_spelloverride_lua = "_G[\"spelloverride\"] = nil";
private readonly String set_spelloverride_lua = "return _G[\"spelloverride\"]";
private String _overrideString;
public bool Enabled;
public WoWUnit Target;
public OverrideTarget TargetId;
public OverrideType TargetType;
public String Spell { get; private set; }
public bool IsLoc
{
get { return TargetType == OverrideType.Location; }
}
public void Pulse()
{
_overrideString = Lua.GetReturnVal<String>(set_spelloverride_lua, 0);
if (_overrideString == null) return;
//if (_overrideString.Length < 8) return;
Spell = _overrideString.Split(':')[1];
var i = Convert.ToInt32(_overrideString.Split(':')[0]);
var c = Convert.ToInt32(_overrideString.Split(':')[2]);
if (c == 0) TargetId = OverrideTarget.Target;
else TargetId = OverrideTarget.Focus;
if (TargetId == OverrideTarget.Target) Target = Me.CurrentTarget;
else Target = Me.FocusedUnit;
Enabled = true;
SimcraftImpl.Write("Spell Override: {0} via {1} on {2}", default(Color), LogLevel.Normal, Spell, TargetType, TargetId);
Lua.DoString(reset_spelloverride_lua);
}
}
public static bool Superlog = false;
#region Nested types
private class ProxyRoutine : CombatRoutine
{
public override string Name
{
get { return "Nullroutine"; }
}
public override WoWClass Class
{
get { return StyxWoW.Me.Class; }
}
}
private class LockSelector : PrioritySelector
{
public LockSelector(params Composite[] children)
: base(children)
{
}
public override RunStatus Tick(object context)
{
try
{
using (StyxWoW.Memory.AcquireFrame())
{
return base.Tick(context);
}
}
catch (Exception e)
{
Logging.WriteException(e);
}
return RunStatus.Success;
}
}
#endregion
}
public static class exts
{
private static List<WoWGuid> HarvestTarget = new List<WoWGuid>();
public static bool MindHarvest(this WoWUnit me)
{
if (HarvestTarget.Contains(me.Guid)) return false;
return true;
}
public static void ApplyMindHarvest(this WoWUnit me)
{
HarvestTarget.Add(me.Guid);
}
public static string ToLiteral(this string input)
{
using (var writer = new StringWriter())
{
using (var provider = CodeDomProvider.CreateProvider("CSharp"))
{
provider.GenerateCodeFromExpression(new CodePrimitiveExpression(input), writer, null);
return writer.ToString();
}
}
}
}
#region enums
#endregion
}