Advertisement
Guest User

THHelpers.cs

a guest
Oct 23rd, 2013
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 115.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Windows.Forms;
  7. using System.Windows.Media;
  8. using CommonBehaviors.Actions;
  9. using Styx;
  10. using Styx.Common;
  11. using Styx.CommonBot;
  12. using Styx.CommonBot.Inventory;
  13. using Styx.Pathing;
  14. using Styx.TreeSharp;
  15. using Styx.WoWInternals;
  16. using Styx.WoWInternals.WoWObjects;
  17. using Action = Styx.TreeSharp.Action;
  18.  
  19. namespace TuanHA_Combat_Routine
  20. {
  21.     public partial class Classname
  22.     {
  23.         #region Attackable
  24.  
  25.         private static bool Attackable(WoWUnit target, int range)
  26.         {
  27.             if (target == null ||
  28.                 !target.IsValid ||
  29.                 !target.Attackable ||
  30.                 !target.CanSelect ||
  31.                 !target.IsAlive ||
  32.                 //target.IsCritter ||
  33.                 //Blacklist.Contains(target.Guid, BlacklistFlags.All) ||
  34.                 GetDistance(target) > range ||
  35.                 Invulnerable(target) ||
  36.                 DebuffCCBreakonDamage(target) ||
  37.                 !IsEnemy(target) ||
  38.                 range > 5 &&
  39.                 GetDistance(target) > 5 &&
  40.                 !InLineOfSpellSightCheck(target))
  41.             {
  42.                 return false;
  43.             }
  44.             return true;
  45.         }
  46.  
  47.         private static bool AttackableNoCC(WoWUnit target, int range)
  48.         {
  49.             if (target == null ||
  50.                 !target.IsValid ||
  51.                 !target.Attackable ||
  52.                 !target.CanSelect ||
  53.                 !target.IsAlive ||
  54.                 //target.IsCritter ||
  55.                 //Blacklist.Contains(target.Guid, BlacklistFlags.All) ||
  56.                 target.Distance - target.CombatReach - 1 > range ||
  57.                 Invulnerable(target) ||
  58.                 !IsEnemy(target) ||
  59.                 range > 5 &&
  60.                 GetDistance(target) > 5 &&
  61.                 !InLineOfSpellSightCheck(target))
  62.             {
  63.                 return false;
  64.             }
  65.             return true;
  66.         }
  67.  
  68.         private static bool AttackableNoLoS(WoWUnit target, int range)
  69.         {
  70.             if (target == null ||
  71.                 !target.IsValid ||
  72.                 !target.Attackable ||
  73.                 !target.CanSelect ||
  74.                 !target.IsAlive ||
  75.                 //target.IsCritter ||
  76.                 //Blacklist.Contains(target.Guid, BlacklistFlags.All) ||
  77.                 GetDistance(target) > range ||
  78.                 Invulnerable(target) ||
  79.                 DebuffCCBreakonDamage(target) ||
  80.                 !IsEnemy(target))
  81.             {
  82.                 return false;
  83.             }
  84.             return true;
  85.         }
  86.  
  87.         private static bool AttackableNoCCLoS(WoWUnit target, int range)
  88.         {
  89.             if (target == null ||
  90.                 !target.IsValid ||
  91.                 !target.Attackable ||
  92.                 !target.CanSelect ||
  93.                 !target.IsAlive ||
  94.                 //target.IsCritter ||
  95.                 //Blacklist.Contains(target.Guid, BlacklistFlags.All) ||
  96.                 GetDistance(target) > range ||
  97.                 Invulnerable(target) ||
  98.                 !IsEnemy(target))
  99.             {
  100.                 return false;
  101.             }
  102.             return true;
  103.         }
  104.  
  105.         #endregion
  106.  
  107.         #region AuraCheck
  108.  
  109.         private static bool UnitHasAura(string auraName, WoWUnit target)
  110.         {
  111.             AuraCacheUpdate(target);
  112.  
  113.             //Logging.Write("========================");
  114.             //Logging.Write("Total AuraCacheAura of {0}", Me.SafeName);
  115.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == Me))
  116.             //{
  117.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  118.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  119.             //}
  120.  
  121.             return AuraCacheList != null &&
  122.                    AuraCacheList.Any(aura => aura.AuraCacheUnit == target.Guid &&
  123.                                              aura.AuraCacheAura.Name == auraName);
  124.         }
  125.  
  126.         private static bool UnitHasAura(int auraID, WoWUnit target)
  127.         {
  128.             AuraCacheUpdate(target);
  129.  
  130.             //Logging.Write("========================");
  131.             //Logging.Write("Total AuraCacheAura of {0}", Me.SafeName);
  132.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == Me))
  133.             //{
  134.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  135.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  136.             //}
  137.  
  138.  
  139.             return AuraCacheList != null &&
  140.                    AuraCacheList.Any(aura => aura.AuraCacheUnit == target.Guid &&
  141.                                              aura.AuraCacheId == auraID);
  142.         }
  143.  
  144.         private static bool MeHasAura(string auraName)
  145.         {
  146.             AuraCacheUpdate(Me);
  147.  
  148.             //Logging.Write("========================");
  149.             //Logging.Write("Total AuraCacheAura of {0}", Me.SafeName);
  150.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == Me))
  151.             //{
  152.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  153.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  154.             //}
  155.  
  156.             return AuraCacheList != null &&
  157.                    AuraCacheList.Any(aura => aura.AuraCacheUnit == Me.Guid &&
  158.                                              aura.AuraCacheAura.Name == auraName);
  159.         }
  160.  
  161.         private static bool MeHasAura(int auraID)
  162.         {
  163.             AuraCacheUpdate(Me);
  164.  
  165.             //Logging.Write("========================");
  166.             //Logging.Write("Total AuraCacheAura of {0}", Me.SafeName);
  167.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == Me))
  168.             //{
  169.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  170.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  171.             //}
  172.  
  173.  
  174.             return AuraCacheList != null &&
  175.                    AuraCacheList.Any(aura => aura.AuraCacheUnit == Me.Guid &&
  176.                                              aura.AuraCacheId == auraID);
  177.         }
  178.  
  179.         private static bool MyAura(string auraName, WoWUnit target)
  180.         {
  181.             if (!BasicCheck(target))
  182.             {
  183.                 return false;
  184.             }
  185.  
  186.             AuraCacheUpdate(target);
  187.  
  188.             //Logging.Write("========================");
  189.             //Logging.Write("Total AuraCacheAura of {0}", target.SafeName);
  190.  
  191.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == target .Guid))
  192.             //{
  193.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  194.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  195.             //}
  196.  
  197.  
  198.             var AuraFound = AuraCacheList != null &&
  199.                             AuraCacheList.Any(
  200.                                 aura => aura.AuraCacheUnit == target.Guid &&
  201.                                         aura.AuraCacheAura.Name == auraName &&
  202.                                         aura.AuraCacheAura.CreatorGuid == Me.Guid);
  203.  
  204.             return AuraFound;
  205.         }
  206.  
  207.  
  208.         private static bool MyAura(int auraID, WoWUnit target)
  209.         {
  210.             if (!BasicCheck(target))
  211.             {
  212.                 return false;
  213.             }
  214.  
  215.             AuraCacheUpdate(target);
  216.  
  217.             //Logging.Write("========================");
  218.             //Logging.Write("Total AuraCacheAura of {0}", target.SafeName);
  219.  
  220.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == target .Guid))
  221.             //{
  222.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  223.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  224.             //}
  225.  
  226.             var AuraFound = AuraCacheList != null &&
  227.                             AuraCacheList.Any(
  228.                                 aura => aura.AuraCacheUnit == target.Guid &&
  229.                                         aura.AuraCacheAura.CreatorGuid == Me.Guid &&
  230.                                         aura.AuraCacheId == auraID);
  231.  
  232.             return AuraFound;
  233.         }
  234.  
  235.         private static double MyAuraTimeLeft(string auraName, WoWUnit target)
  236.         {
  237.             if (!BasicCheck(target))
  238.             {
  239.                 return 0;
  240.             }
  241.  
  242.             AuraCacheUpdate(target);
  243.  
  244.             //Logging.Write("========================");
  245.             //Logging.Write("Total AuraCacheAura of {0}", target.SafeName);
  246.  
  247.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == target .Guid))
  248.             //{
  249.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  250.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  251.             //}
  252.  
  253.             return AuraCacheList == null
  254.                        ? 0
  255.                        : AuraCacheList.Where(
  256.                            aura =>
  257.                            aura.AuraCacheUnit == target.Guid && aura.AuraCacheAura.CreatorGuid == Me.Guid &&
  258.                            aura.AuraCacheName == auraName)
  259.                                       .Select(Aura => Aura.AuraCacheAura.TimeLeft.TotalMilliseconds)
  260.                                       .FirstOrDefault();
  261.  
  262.             //if (AuraCacheList != null)
  263.             //{
  264.             //    foreach (var Aura in AuraCacheList)
  265.             //    {
  266.             //        if (Aura.AuraCacheUnit==target&&
  267.             //            Aura.AuraCacheAura.CreatorGuid==Me.Guid&&
  268.             //            Aura.AuraCacheName == auraName)
  269.             //        {
  270.             //            return Aura.AuraCacheAura.TimeLeft.TotalMilliseconds;
  271.             //        }
  272.             //    }
  273.             //}
  274.             //return 0;
  275.         }
  276.  
  277.         private static double MyAuraTimeLeft(int auraID, WoWUnit target)
  278.         {
  279.             if (!BasicCheck(target))
  280.             {
  281.                 return 0;
  282.             }
  283.  
  284.             AuraCacheUpdate(target);
  285.  
  286.             //Logging.Write("========================");
  287.             //Logging.Write("Total AuraCacheAura of {0}", target.SafeName);
  288.  
  289.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == target .Guid))
  290.             //{
  291.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  292.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  293.             //}
  294.  
  295.             return AuraCacheList == null
  296.                        ? 0
  297.                        : AuraCacheList.Where(
  298.                            aura =>
  299.                            aura.AuraCacheUnit == target.Guid && aura.AuraCacheAura.CreatorGuid == Me.Guid &&
  300.                            aura.AuraCacheId == auraID)
  301.                                       .Select(Aura => Aura.AuraCacheAura.TimeLeft.TotalMilliseconds)
  302.                                       .FirstOrDefault();
  303.         }
  304.  
  305.         private static double MyAuraStackCount(string auraName, WoWUnit target)
  306.         {
  307.             if (!BasicCheck(target))
  308.             {
  309.                 return 0;
  310.             }
  311.  
  312.             AuraCacheUpdate(target);
  313.  
  314.             //Logging.Write("========================");
  315.             //Logging.Write("Total AuraCacheAura of {0}", target.SafeName);
  316.  
  317.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == target .Guid))
  318.             //{
  319.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  320.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  321.             //}
  322.  
  323.             return AuraCacheList == null
  324.                        ? 0
  325.                        : AuraCacheList.Where(
  326.                            aura =>
  327.                            aura.AuraCacheUnit == target.Guid && aura.AuraCacheAura.CreatorGuid == Me.Guid &&
  328.                            aura.AuraCacheName == auraName)
  329.                                       .Select(aura => aura.AuraCacheAura.StackCount)
  330.                                       .FirstOrDefault();
  331.         }
  332.  
  333.         private static double MyAuraStackCount(int auraID, WoWUnit target)
  334.         {
  335.             if (!BasicCheck(target))
  336.             {
  337.                 return 0;
  338.             }
  339.  
  340.             AuraCacheUpdate(target);
  341.  
  342.             //Logging.Write("========================");
  343.             //Logging.Write("Total AuraCacheAura of {0}", target.SafeName);
  344.  
  345.             //foreach (var Aura in AuraCacheList.Where(aura => aura.AuraCacheUnit == target .Guid))
  346.             //{
  347.             //    Logging.Write("Aura.AuraCacheUnit {0} - Aura.AuraCacheAura.Name {1} - Aura.AuraCacheId {2}",
  348.             //                  Aura.AuraCacheUnit, Aura.AuraCacheAura.Name, Aura.AuraCacheId);
  349.             //}
  350.  
  351.             return AuraCacheList == null
  352.                        ? 0
  353.                        : AuraCacheList.Where(
  354.                            aura =>
  355.                            aura.AuraCacheUnit == target.Guid && aura.AuraCacheAura.CreatorGuid == Me.Guid &&
  356.                            aura.AuraCacheId == auraID)
  357.                                       .Select(aura => aura.AuraCacheAura.StackCount)
  358.                                       .FirstOrDefault();
  359.         }
  360.  
  361.         #endregion
  362.  
  363.         #region BasicCheck
  364.  
  365.         private static bool BasicCheck(WoWUnit target)
  366.         {
  367.             return target != null && target.IsValid && target.IsAlive;
  368.         }
  369.  
  370.         #endregion
  371.  
  372.         #region  BattleStandard
  373.  
  374.         private static Composite UseBattleStandard()
  375.         {
  376.             return
  377.                 new Decorator(
  378.                     ret =>
  379.                     THSettings.Instance.BattleStandard &&
  380.                     Me.Combat &&
  381.                     HealWeightMe <= THSettings.Instance.BattleStandardHP &&
  382.                     Me.CurrentTarget != null &&
  383.                     Me.CurrentTarget.HealthPercent > HealWeightMe &&
  384.                     InBattleground,
  385.                     new Action(delegate
  386.                         {
  387.                             if (Me.IsAlliance)
  388.                             {
  389.                                 WoWItem bs = Me.BagItems.FirstOrDefault(o => o.Entry == 18606);
  390.                                 //18606 Alliance Battle Standard
  391.  
  392.                                 if (!MeHasAura("Alliance Battle Standard") && bs != null &&
  393.                                     bs.CooldownTimeLeft.TotalMilliseconds <= MyLatency)
  394.                                 {
  395.                                     bs.Use();
  396.                                     //Lua.DoString("RunMacroText(\"/5 Used HealthStoneHP\")");
  397.                                     //Lua.DoString("RunMacroText(\"/s Used Battle Standard\")");
  398.                                     Logging.Write("Use Battle Standard at " + HealWeightMe + "%");
  399.                                 }
  400.                             }
  401.  
  402.                             if (Me.IsHorde)
  403.                             {
  404.                                 WoWItem bs = Me.BagItems.FirstOrDefault(o => o.Entry == 18607);
  405.                                 //18606 Horde Battle Standard
  406.  
  407.                                 if (!MeHasAura("Horde Battle Standard") && bs != null &&
  408.                                     bs.CooldownTimeLeft.TotalMilliseconds <= MyLatency)
  409.                                 {
  410.                                     bs.Use();
  411.                                     //Lua.DoString("RunMacroText(\"/5 Used HealthStoneHP\")");
  412.                                     //Lua.DoString("RunMacroText(\"/s Used Battle Standard\")");
  413.                                     Logging.Write("Use Battle Standard at " + HealWeightMe + "%");
  414.                                 }
  415.                             }
  416.  
  417.                             return RunStatus.Failure;
  418.                         })
  419.                     );
  420.         }
  421.  
  422.         #endregion
  423.  
  424.         #region CanUseEquippedItem
  425.  
  426.         //Thank Apoc
  427.         private static bool CanUseEquippedItem(WoWItem item)
  428.         {
  429.             // Check for engineering tinkers!
  430.             var itemSpell = Lua.GetReturnVal<string>("return GetItemSpell(" + item.Entry + ")", 0);
  431.             if (string.IsNullOrEmpty(itemSpell))
  432.                 return false;
  433.  
  434.             return item.Usable && item.Cooldown <= 0;
  435.         }
  436.  
  437.         #endregion
  438.  
  439.         #region CancelAura
  440.  
  441.         private static void CancelAura(string aura, WoWUnit target)
  442.         {
  443.             WoWAura a = target.GetAuraByName(aura);
  444.             if (a != null && a.Cancellable)
  445.                 a.TryCancelAura();
  446.         }
  447.  
  448.         private static void CancelAura(int aura, WoWUnit target)
  449.         {
  450.             WoWAura a = target.GetAuraById(aura);
  451.             if (a != null && a.Cancellable)
  452.                 a.TryCancelAura();
  453.         }
  454.  
  455.         #endregion
  456.  
  457.         #region CastSpell
  458.  
  459.         private static WoWUnit LastCastUnit;
  460.         private static string LastCastSpell;
  461.         private static DateTime LastCastTime;
  462.         //private static bool CastFailed;
  463.         private static DateTime LastWriteLog;
  464.         private static Color colorlog;
  465.  
  466.         private static void CastSpell(string spellName, WoWUnit target, string reason = "")
  467.         {
  468.             if (target == null || !target.IsValid)
  469.             {
  470.                 return;
  471.             }
  472.  
  473.             SpellManager.Cast(spellName, target);
  474.  
  475.  
  476.             LastCastSpell = spellName;
  477.             LastCastUnit = target;
  478.             LastCastTime = DateTime.Now;
  479.  
  480.             if (!THSettings.Instance.AutoWriteLog || LastWriteLog > DateTime.Now) return;
  481.  
  482.             LastWriteLog = DateTime.Now + TimeSpan.FromMilliseconds(MyLatency);
  483.  
  484.             if (spellName == "Wind Shear" ||
  485.                 spellName == "Grounding Totem" ||
  486.                 spellName == "Capacitor Totem" ||
  487.                 spellName == "Hex")
  488.             {
  489.                 colorlog = Colors.GhostWhite;
  490.             }
  491.             else if (target == Me)
  492.             {
  493.                 colorlog = Colors.GreenYellow;
  494.             }
  495.             else if (target == Me.CurrentTarget)
  496.             {
  497.                 colorlog = Colors.Yellow;
  498.             }
  499.             else
  500.             {
  501.                 colorlog = Colors.YellowGreen;
  502.             }
  503.  
  504.             Logging.Write(colorlog, DateTime.Now.ToString("ss:fff") + " HP: " +
  505.                                     Math.Round(Me.HealthPercent) + "% Mana: " + Math.Round(Me.ManaPercent) + " " +
  506.                                     SafeName(target) + " " +
  507.                                     Math.Round(target.Distance, 2) + "y " +
  508.                                     Math.Round(target.HealthPercent) + "% hp " + spellName + reason);
  509.         }
  510.  
  511.  
  512.         //private static Action CastSpell(string spellName, UnitSelectionDelegate target, string reason = "")
  513.         //{
  514.         //    return new Action(ret =>
  515.         //        {
  516.         //            if (target(ret) == null ||
  517.         //                !target(ret).IsValid)
  518.         //            {
  519.         //                return RunStatus.Success;
  520.         //            }
  521.  
  522.         //            SpellManager.Cast(spellName, target(ret));
  523.  
  524.         //            LastCastSpell = spellName;
  525.         //            LastCastUnit = target(ret);
  526.         //            LastCastTime = DateTime.Now;
  527.  
  528.         //            if (!THSettings.Instance.AutoWriteLog || LastWriteLog > DateTime.Now)
  529.         //            {
  530.         //                return RunStatus.Success;
  531.         //            }
  532.  
  533.         //            LastWriteLog = DateTime.Now + TimeSpan.FromMilliseconds(MyLatency);
  534.  
  535.         //            WriteReason = "";
  536.  
  537.         //            if (reason != "")
  538.         //            {
  539.         //                WriteReason = " (" + reason + ")";
  540.         //            }
  541.  
  542.         //            if (spellName == "Wind Shear" ||
  543.         //                spellName == "Grounding Totem" ||
  544.         //                spellName == "Capacitor Totem" ||
  545.         //                spellName == "Hex")
  546.         //            {
  547.         //                colorlog = Colors.GhostWhite;
  548.         //            }
  549.         //            else if (target(ret) == Me)
  550.         //            {
  551.         //                colorlog = Colors.GreenYellow;
  552.         //            }
  553.         //            else if (target(ret) == Me.CurrentTarget)
  554.         //            {
  555.         //                colorlog = Colors.Yellow;
  556.         //            }
  557.         //            else
  558.         //            {
  559.         //                colorlog = Colors.YellowGreen;
  560.         //            }
  561.  
  562.         //            Logging.Write(colorlog, DateTime.Now.ToString("ss:fff") + " HP: " +
  563.         //                                    Math.Round(Me.HealthPercent) + "% Mana: " +
  564.         //                                    Math.Round(Me.ManaPercent) + " " +
  565.         //                                    SafeName(target(ret)) + " " +
  566.         //                                    Math.Round(target(ret).Distance, 2) + "y " +
  567.         //                                    Math.Round(target(ret).HealthPercent) + "% hp " + spellName +
  568.         //                                    WriteReason);
  569.  
  570.         //            return RunStatus.Success;
  571.         //        });
  572.         //}
  573.  
  574.         #endregion
  575.  
  576.         #region CanCleanse
  577.  
  578.         //private bool CanCleanse(WoWAura aura)
  579.         //{
  580.         //    //if (aura == null)
  581.         //    //    return false;
  582.  
  583.         //    //if (aura.Spell.DispelType == WoWDispelType.Disease || aura.Spell.DispelType == WoWDispelType.Magic ||
  584.         //    //    aura.Spell.DispelType == WoWDispelType.Poison)
  585.         //    if (aura.Spell.DispelType != WoWDispelType.None)
  586.         //    {
  587.         //        //Logging.Write("CanCleanse: " + aura.Name + " - " + aura.SpellId);
  588.         //        return true;
  589.         //    }
  590.         //    return false;
  591.         //}
  592.  
  593.         #endregion
  594.  
  595.         #region ConstantFace
  596.  
  597.         //private static void ConstantFace(WoWUnit unit)
  598.         //{
  599.         //    if (!IsOverrideModeOn && !Me.IsSafelyFacing(unit))
  600.         //    {
  601.         //        WoWMovement.ConstantFace(unit.Guid);
  602.         //    }
  603.         //}
  604.  
  605.         #endregion
  606.  
  607.         #region CountDebuff
  608.  
  609.         private static double CountDebuff(WoWUnit target)
  610.         {
  611.             if (!BasicCheck(target))
  612.             {
  613.                 return 0;
  614.             }
  615.  
  616.             int numberofDebuff =
  617.                 AuraCacheList.Count(
  618.                     aura =>
  619.                     aura.AuraCacheUnit == target.Guid &&
  620.                     aura.AuraCacheAura.IsActive &&
  621.                     aura.AuraCacheAura.IsHarmful &&
  622.                     (aura.AuraCacheAura.Spell.DispelType == WoWDispelType.Magic ||
  623.                      aura.AuraCacheAura.Spell.DispelType == WoWDispelType.Curse));
  624.  
  625.             return numberofDebuff;
  626.         }
  627.  
  628.         #endregion
  629.  
  630.         #region CountDPSTarget
  631.  
  632.         private static bool HaveDPSTarget(WoWUnit target)
  633.         {
  634.             //using (StyxWoW.Memory.AcquireFrame())
  635.             {
  636.                 if (InArena || InBattleground)
  637.                 {
  638.                     return NearbyUnFriendlyPlayers.Any(
  639.                         unit =>
  640.                         unit.IsValid &&
  641.                         //unit.GotTarget &&
  642.                         unit.CurrentTarget == target &&
  643.                         (TalentSort(unit) >= 2 &&
  644.                          TalentSort(unit) <= 3 &&
  645.                          unit.Location.Distance(target.Location) < 40 ||
  646.                          TalentSort(unit) == 1 &&
  647.                          unit.Location.Distance(target.Location) < 20) &&
  648.                         !DebuffCC(unit) &&
  649.                         (target != Me ||
  650.                          target == Me &&
  651.                          InLineOfSpellSightCheck(unit)));
  652.                 }
  653.                 return NearbyUnFriendlyUnits.Any(
  654.                     unit =>
  655.                     unit.IsValid &&
  656.                     //unit.GotTarget &&
  657.                     unit.CurrentTarget == target &&
  658.                     !DebuffCC(unit));
  659.             }
  660.         }
  661.  
  662.         #endregion
  663.  
  664.         #region CountFriendDPSTarget
  665.  
  666.         private static int CountFriendDPSTarget(WoWUnit target)
  667.         {
  668.             if (InArena || InBattleground)
  669.             {
  670.                 return NearbyFriendlyPlayers.Count(
  671.                     unit =>
  672.                     BasicCheck(unit) &&
  673.                     //unit.GotTarget &&
  674.                     unit.CurrentTarget == target &&
  675.                     (TalentSort(unit) >= 2 &&
  676.                      TalentSort(unit) <= 3 &&
  677.                      unit.Location.Distance(target.Location) < 40 ||
  678.                      TalentSort(unit) == 1 &&
  679.                      unit.Location.Distance(target.Location) < 15));
  680.             }
  681.             return NearbyFriendlyPlayers.Count(
  682.                 unit =>
  683.                 BasicCheck(unit) &&
  684.                 //unit.GotTarget &&
  685.                 unit.CurrentTarget == target);
  686.         }
  687.  
  688.         private static bool HasFriendDPSTarget(WoWUnit target)
  689.         {
  690.             if (InArena || InBattleground)
  691.             {
  692.                 return NearbyFriendlyPlayers.Any(
  693.                     unit =>
  694.                     BasicCheck(unit) &&
  695.                     //unit.GotTarget &&
  696.                     unit.CurrentTarget == target &&
  697.                     (TalentSort(unit) >= 2 &&
  698.                      TalentSort(unit) <= 3 &&
  699.                      unit.Location.Distance(target.Location) < 40 ||
  700.                      TalentSort(unit) == 1 &&
  701.                      unit.Location.Distance(target.Location) < 15));
  702.             }
  703.             return NearbyFriendlyPlayers.Any(
  704.                 unit =>
  705.                 BasicCheck(unit) &&
  706.                 //unit.GotTarget &&
  707.                 unit.CurrentTarget == target);
  708.         }
  709.  
  710.         #endregion
  711.  
  712.         #region CountMagicDPSTarget
  713.  
  714.         //private static int CountMagicDPSTarget(WoWUnit target)
  715.         //{
  716.         //    //using (StyxWoW.Memory.AcquireFrame())
  717.         //    {
  718.         //        if (InArena || InBattleground)
  719.         //        {
  720.         //            return NearbyUnFriendlyPlayers.Count(
  721.         //                unit =>
  722.         //                //unit.GotTarget &&
  723.         //                unit.CurrentTarget == target &&
  724.         //                TalentSort(unit) == 3 &&
  725.         //                unit.Location.Distance(target.Location) < 40 &&
  726.         //                !DebuffCC(unit));
  727.         //        }
  728.         //        return NearbyUnFriendlyUnits.Count(
  729.         //            unit =>
  730.         //            //unit.GotTarget &&
  731.         //            unit.CurrentTarget == target &&
  732.         //            unit.Location.Distance(target.Location) < 40 &&
  733.         //            !DebuffCC(unit));
  734.         //    }
  735.         //}
  736.  
  737.         #endregion
  738.  
  739.         #region CountMeleeDPSTarget
  740.  
  741.         private static int CountMeleeDPSTarget(WoWUnit target)
  742.         {
  743.             //using (StyxWoW.Memory.AcquireFrame())
  744.             {
  745.                 if (InArena || InBattleground)
  746.                 {
  747.                     return NearbyUnFriendlyPlayers.Count(
  748.                         unit =>
  749.                         unit.IsValid &&
  750.                         //unit.GotTarget &&
  751.                         unit.CurrentTarget == target &&
  752.                         TalentSort(unit) == 1 &&
  753.                         unit.Location.Distance(target.Location) < 15 &&
  754.                         !DebuffCC(unit) &&
  755.                         (target != Me ||
  756.                          target == Me &&
  757.                          InLineOfSpellSightCheck(unit)));
  758.                 }
  759.                 return NearbyUnFriendlyUnits.Count(
  760.                     unit =>
  761.                     unit.IsValid &&
  762.                     //unit.GotTarget &&
  763.                     unit.CurrentTarget == target &&
  764.                     unit.Location.Distance(target.Location) < 15 &&
  765.                     !DebuffCC(unit));
  766.             }
  767.         }
  768.  
  769.         #endregion
  770.  
  771.         #region CountPhysicDPSTarget
  772.  
  773.         private static int CountPhysicDPSTarget(WoWUnit target)
  774.         {
  775.             //using (StyxWoW.Memory.AcquireFrame())
  776.             {
  777.                 if (InArena || InBattleground)
  778.                 {
  779.                     return NearbyUnFriendlyPlayers.Count(
  780.                         unit =>
  781.                         unit.IsValid &&
  782.                         //unit.GotTarget &&
  783.                         unit.CurrentTarget == target &&
  784.                         (TalentSort(unit) == 2 &&
  785.                          unit.Location.Distance(target.Location) < 40 ||
  786.                          TalentSort(unit) == 1 &&
  787.                          unit.Location.Distance(target.Location) < 25) &&
  788.                         !DebuffCC(unit) &&
  789.                         (target != Me ||
  790.                          target == Me &&
  791.                          InLineOfSpellSightCheck(unit)));
  792.                 }
  793.                 return NearbyUnFriendlyUnits.Count(
  794.                     unit =>
  795.                     unit.IsValid &&
  796.                     //unit.GotTarget &&
  797.                     unit.CurrentTarget == target &&
  798.                     unit.Location.Distance(target.Location) < 15 &&
  799.                     !DebuffCC(unit));
  800.             }
  801.         }
  802.  
  803.         #endregion
  804.  
  805.         #region CountEneyNeary
  806.  
  807.         private static int CountEnemyNear(WoWUnit unitCenter, float distance)
  808.         {
  809.             return NearbyUnFriendlyUnits.Count(
  810.                 unit =>
  811.                 BasicCheck(unit) &&
  812.                 !unit.IsPet &&
  813.                 (IsDummy(unit) ||
  814.                  unit.Combat &&
  815.                  FarFriendlyPlayers.Contains(unit.CurrentTarget)) &&
  816.                 GetDistance(unitCenter, unit) <= distance);
  817.         }
  818.  
  819.         private static bool HasEnemyNear(WoWUnit unitCenter, float distance)
  820.         {
  821.             return NearbyUnFriendlyUnits.Any(
  822.                 unit =>
  823.                 BasicCheck(unit) &&
  824.                 !unit.IsPet &&
  825.                 (IsDummy(unit) ||
  826.                  unit.Combat &&
  827.                  //BasicCheck(unit.CurrentTarget) &&
  828.                  FarFriendlyPlayers.Contains(unit.CurrentTarget)) &&
  829.                 GetDistance(unitCenter, unit) <= distance);
  830.         }
  831.  
  832.         #endregion
  833.  
  834.         #region CountEneyTargettingUnit
  835.  
  836.         private static double CountEnemyTargettingUnit(WoWUnit target, float distance)
  837.         {
  838.             return
  839.                 NearbyUnFriendlyUnits.Count(
  840.                     unit =>
  841.                     unit.IsValid &&
  842.                     GetDistance(unit) < distance &&
  843.                     //unit.GotTarget &&
  844.                     unit.Level <= target.Level + 3 &&
  845.                     //unit.Combat &&
  846.                     !unit.IsPet &&
  847.                     unit.CurrentTarget == target &&
  848.                     !DebuffCC(unit) &&
  849.                     (target != Me ||
  850.                      target == Me &&
  851.                      InLineOfSpellSightCheck(unit)));
  852.         }
  853.  
  854.         private static bool HasEnemyTargettingUnit(WoWUnit target, float distance)
  855.         {
  856.             return
  857.                 NearbyUnFriendlyUnits.Any(
  858.                     unit =>
  859.                     unit.IsValid &&
  860.                     GetDistance(unit) < distance &&
  861.                     //unit.GotTarget &&
  862.                     unit.Level <= target.Level + 3 &&
  863.                     //unit.Combat &&
  864.                     !unit.IsPet &&
  865.                     unit.CurrentTarget == target &&
  866.                     !DebuffCC(unit) &&
  867.                     (target != Me ||
  868.                      target == Me &&
  869.                      InLineOfSpellSightCheck(unit)));
  870.         }
  871.  
  872.         #endregion
  873.  
  874.         #region CurrentTargetCheck
  875.  
  876.         private static WoWUnit CurrentTargetCheckLast;
  877.         private static double CurrentTargetCheckDist;
  878.         private static bool CurrentTargetCheckDebuffCCBreakonDamage;
  879.         private static bool CurrentTargetCheckInvulnerable;
  880.         private static bool CurrentTargetCheckInvulnerablePhysic;
  881.         private static bool CurrentTargetCheckInvulnerableMagic;
  882.         private static bool CurrentTargetCheckIsEnemy;
  883.         private static bool CurrentTargetCheckInLineOfSpellSight;
  884.         private static bool CurrentTargetCheckFacing;
  885.  
  886.         private static void CurrentTargetCheck()
  887.         {
  888.             CurrentTargetCheckLast = null;
  889.             CurrentTargetCheckDist = 1000;
  890.             CurrentTargetCheckDebuffCCBreakonDamage = false;
  891.             CurrentTargetCheckInvulnerable = false;
  892.             CurrentTargetCheckIsEnemy = false;
  893.             CurrentTargetCheckInLineOfSpellSight = false;
  894.             CurrentTargetCheckFacing = false;
  895.  
  896.             if (!BasicCheck(Me.CurrentTarget))
  897.             {
  898.                 return;
  899.             }
  900.  
  901.             CurrentTargetCheckLast = Me.CurrentTarget;
  902.             CurrentTargetCheckFacing = Me.IsFacing(Me.CurrentTarget);
  903.             CurrentTargetCheckDist = GetDistance(Me.CurrentTarget);
  904.  
  905.             CurrentTargetCheckIsEnemy = IsEnemy(Me.CurrentTarget);
  906.             if (!CurrentTargetCheckIsEnemy)
  907.             {
  908.                 return;
  909.             }
  910.  
  911.             CurrentTargetCheckInvulnerable = Invulnerable(Me.CurrentTarget);
  912.             if (CurrentTargetCheckInvulnerable)
  913.             {
  914.                 return;
  915.             }
  916.  
  917.             CurrentTargetCheckDebuffCCBreakonDamage = DebuffCCBreakonDamage(Me.CurrentTarget);
  918.             if (CurrentTargetCheckDebuffCCBreakonDamage)
  919.             {
  920.                 return;
  921.             }
  922.  
  923.             CurrentTargetCheckInvulnerableMagic = InvulnerableSpell(Me.CurrentTarget);
  924.             CurrentTargetCheckInvulnerablePhysic = InvulnerablePhysic(Me.CurrentTarget);
  925.  
  926.             if (CurrentTargetCheckDist <= 5)
  927.             {
  928.                 CurrentTargetCheckInLineOfSpellSight = true;
  929.             }
  930.             else if (InLineOfSpellSightCheck(Me.CurrentTarget))
  931.             {
  932.                 CurrentTargetCheckInLineOfSpellSight = true;
  933.             }
  934.         }
  935.  
  936.         private static bool CurrentTargetAttackable(double distance,
  937.                                                     bool includeCurrentTargetCheckInvulnerableePhysic = false,
  938.                                                     bool includeCurrentTargetCheckInvulnerableeMagic = false)
  939.         {
  940.             if (Me.CurrentTarget == null ||
  941.                 !Me.CurrentTarget.IsValid ||
  942.                 !Me.CurrentTarget.Attackable ||
  943.                 !Me.CurrentTarget.IsAlive) // ||
  944.                 //Blacklist.Contains(Me.CurrentTarget.Guid, BlacklistFlags.All))
  945.             {
  946.                 return false;
  947.             }
  948.  
  949.             if (Me.CurrentTarget != CurrentTargetCheckLast)
  950.             {
  951.                 CurrentTargetCheck();
  952.             }
  953.  
  954.             if (!CurrentTargetCheckIsEnemy ||
  955.                 CurrentTargetCheckDebuffCCBreakonDamage ||
  956.                 CurrentTargetCheckInvulnerable ||
  957.                 !CurrentTargetCheckFacing && !THSettings.Instance.AutoFace && IsOverrideModeOn ||
  958.                 includeCurrentTargetCheckInvulnerableePhysic && CurrentTargetCheckInvulnerablePhysic ||
  959.                 includeCurrentTargetCheckInvulnerableeMagic && CurrentTargetCheckInvulnerableMagic ||
  960.                 CurrentTargetCheckDist > distance ||
  961.                 !CurrentTargetCheckInLineOfSpellSight)
  962.             {
  963.                 return false;
  964.             }
  965.             return true;
  966.         }
  967.  
  968.         private static bool CurrentTargetAttackableNoLoS(double distance)
  969.         {
  970.             if (Me.CurrentTarget == null ||
  971.                 !Me.CurrentTarget.IsValid ||
  972.                 !Me.CurrentTarget.Attackable ||
  973.                 !Me.CurrentTarget.IsAlive) // ||
  974.                 //Blacklist.Contains(Me.CurrentTarget.Guid, BlacklistFlags.All))
  975.             {
  976.                 return false;
  977.             }
  978.  
  979.             if (Me.CurrentTarget != CurrentTargetCheckLast)
  980.             {
  981.                 CurrentTargetCheck();
  982.             }
  983.  
  984.             if (CurrentTargetCheckDebuffCCBreakonDamage ||
  985.                 CurrentTargetCheckInvulnerable ||
  986.                 !CurrentTargetCheckIsEnemy ||
  987.                 CurrentTargetCheckDist > distance)
  988.             {
  989.                 return false;
  990.             }
  991.             return true;
  992.         }
  993.  
  994.         #endregion
  995.  
  996.         #region FacingOverride
  997.  
  998.         private static bool FacingOverride(WoWUnit unit)
  999.         {
  1000.             //using (StyxWoW.Memory.AcquireFrame())
  1001.             {
  1002.                 if (!BasicCheck(unit))
  1003.                 {
  1004.                     return false;
  1005.                 }
  1006.  
  1007.                 if (!IsUsingAFKBot || Me.IsFacing(unit))
  1008.                 {
  1009.                     return true;
  1010.                 }
  1011.  
  1012.                 if (THSettings.Instance.AutoFace && !IsMoving(Me))
  1013.                 {
  1014.                     return true;
  1015.                 }
  1016.  
  1017.                 //if (TreeRoot.Current.Name == "Questing" ||
  1018.                 //    TreeRoot.Current.Name == "Grind Bot" ||
  1019.                 //    TreeRoot.Current.Name == "BGBuddy" ||
  1020.                 //    TreeRoot.Current.Name == "DungeonBuddy" ||
  1021.                 //    TreeRoot.Current.Name == "Mixed Mode")
  1022.                 //{
  1023.                 //    return true;
  1024.                 //}
  1025.  
  1026.                 return false;
  1027.             }
  1028.         }
  1029.  
  1030.         #endregion
  1031.  
  1032.         #region GetCurrentSpec
  1033.  
  1034.         private static string CurrentSpec;
  1035.  
  1036.         internal static string GetCurrentSpec()
  1037.         {
  1038.             switch (Me.Specialization)
  1039.             {
  1040.                 case WoWSpec.ShamanElemental:
  1041.                     CurrentSpec = "Elemental";
  1042.                     break;
  1043.                 case WoWSpec.ShamanEnhancement:
  1044.                     CurrentSpec = "Enhancement";
  1045.                     break;
  1046.                 default:
  1047.                     CurrentSpec = "Restoration";
  1048.                     break;
  1049.             }
  1050.             return CurrentSpec;
  1051.         }
  1052.  
  1053.         #endregion
  1054.  
  1055.         #region GetAsyncKeyState
  1056.  
  1057.         [DllImport("user32.dll")]
  1058.         private static extern short GetAsyncKeyState(Keys vKey);
  1059.  
  1060.         #endregion
  1061.  
  1062.         #region Spells
  1063.  
  1064.         private static double GetSpellCastTime(string spell)
  1065.         {
  1066.             SpellFindResults results;
  1067.             if (SpellManager.FindSpell(spell, out results))
  1068.             {
  1069.                 return results.Override != null ? results.Override.CastTime/1000.0 : results.Original.CastTime/1000.0;
  1070.             }
  1071.             return 99999.9;
  1072.         }
  1073.  
  1074.         private static double GetSpellCastTime(int spell)
  1075.         {
  1076.             SpellFindResults results;
  1077.             if (SpellManager.FindSpell(spell, out results))
  1078.             {
  1079.                 return results.Override != null ? results.Override.CastTime/1000.0 : results.Original.CastTime/1000.0;
  1080.             }
  1081.             return 99999.9;
  1082.         }
  1083.  
  1084.         private static double GetSpellPowerCost(string spell)
  1085.         {
  1086.             SpellFindResults results;
  1087.             if (SpellManager.FindSpell(spell, out results))
  1088.             {
  1089.                 return results.Override != null ? results.Override.PowerCost : results.Original.PowerCost;
  1090.             }
  1091.             return 99999.9;
  1092.         }
  1093.  
  1094.         private static double GetSpellPowerCost(int spell)
  1095.         {
  1096.             SpellFindResults results;
  1097.             if (SpellManager.FindSpell(spell, out results))
  1098.             {
  1099.                 return results.Override != null ? results.Override.PowerCost : results.Original.PowerCost;
  1100.             }
  1101.             return 99999.9;
  1102.         }
  1103.  
  1104.         private static TimeSpan GetSpellCooldown(string spell)
  1105.         {
  1106.             SpellFindResults results;
  1107.             if (SpellManager.FindSpell(spell, out results))
  1108.             {
  1109.                 return results.Override != null ? results.Override.CooldownTimeLeft : results.Original.CooldownTimeLeft;
  1110.             }
  1111.  
  1112.             return TimeSpan.MaxValue;
  1113.         }
  1114.  
  1115.         private static TimeSpan GetSpellCooldown(int spell)
  1116.         {
  1117.             SpellFindResults results;
  1118.             if (SpellManager.FindSpell(spell, out results))
  1119.             {
  1120.                 return results.Override != null ? results.Override.CooldownTimeLeft : results.Original.CooldownTimeLeft;
  1121.             }
  1122.  
  1123.             return TimeSpan.MaxValue;
  1124.         }
  1125.  
  1126.         private static bool SpellOnCooldown(string spell)
  1127.         {
  1128.             SpellFindResults results;
  1129.             if (SpellManager.FindSpell(spell, out results))
  1130.             {
  1131.                 return results.Override != null ? results.Override.Cooldown : results.Original.Cooldown;
  1132.             }
  1133.  
  1134.             return false;
  1135.         }
  1136.  
  1137.         private static bool SpellOnCooldown(int spell)
  1138.         {
  1139.             SpellFindResults results;
  1140.             if (SpellManager.FindSpell(spell, out results))
  1141.             {
  1142.                 return results.Override != null ? results.Override.Cooldown : results.Original.Cooldown;
  1143.             }
  1144.  
  1145.             return false;
  1146.         }
  1147.  
  1148.         private static WoWSpell SpellFind(string spell)
  1149.         {
  1150.             SpellFindResults results;
  1151.             if (SpellManager.FindSpell(spell, out results))
  1152.             {
  1153.                 return results.Override ?? results.Original;
  1154.             }
  1155.  
  1156.             return null;
  1157.         }
  1158.  
  1159.         #endregion Spells
  1160.  
  1161.         #region GetUnitAuras
  1162.  
  1163.         //private static double AuraCCDuration;
  1164.         //private static double AuraCCDurationMax;
  1165.         //public WoWAura AuraCC;
  1166.  
  1167.         //private static double AuraCCBreakonDamageDuration;
  1168.         //private static double AuraCCBreakonDamageDurationMax;
  1169.         //public WoWAura AuraCCBreakonDamage;
  1170.  
  1171.         //private static double AuraDisarmDuration;
  1172.         //private static double AuraDisarmDurationMax;
  1173.         //public WoWAura AuraDisarm;
  1174.  
  1175.         //private static double AuraImmuneDuration;
  1176.         //private static double AuraImmuneDurationMax;
  1177.         //public WoWAura AuraImmune;
  1178.  
  1179.         //private static double AuraImmunePhysicDuration;
  1180.         //private static double AuraImmunePhysicDurationMax;
  1181.         //public WoWAura AuraImmunePhysic;
  1182.  
  1183.         //private static double AuraImmuneSpellDuration;
  1184.         //private static double AuraImmuneSpellDurationMax;
  1185.         //public WoWAura AuraImmuneSpell;
  1186.  
  1187.         //private static double AuraRootDuration;
  1188.         //private static double AuraRootDurationMax;
  1189.         //public WoWAura AuraRoot;
  1190.  
  1191.         //private static double AuraSilenceDuration;
  1192.         //private static double AuraSilenceDurationMax;
  1193.         //public WoWAura AuraSilence;
  1194.  
  1195.         //private static double AuraSnareDuration;
  1196.         //private static double AuraSnareDurationMax;
  1197.         //public WoWAura AuraSnare;
  1198.  
  1199.         //public WoWAura AuraCleanseDoNot;
  1200.         //public WoWAura AuraHealDoNot;
  1201.         //public int NumberofDebuff;
  1202.  
  1203.         //private bool GetUnitAuras(WoWUnit u)
  1204.         //{
  1205.         //    if (u == null || !u.IsValid || !u.IsAlive)
  1206.         //        return false;
  1207.  
  1208.         //    AuraCC = null;
  1209.         //    AuraCCDuration = 0;
  1210.         //    AuraCCDurationMax = 0;
  1211.  
  1212.         //    AuraCCBreakonDamage = null;
  1213.         //    AuraCCBreakonDamageDuration = 0;
  1214.         //    AuraCCBreakonDamageDurationMax = 0;
  1215.  
  1216.         //    AuraDisarm = null;
  1217.         //    AuraDisarmDuration = 0;
  1218.         //    AuraDisarmDurationMax = 0;
  1219.  
  1220.         //    AuraImmune = null;
  1221.         //    AuraImmuneDuration = 0;
  1222.         //    AuraImmuneDurationMax = 0;
  1223.  
  1224.         //    AuraImmuneSpell = null;
  1225.         //    AuraImmuneSpellDuration = 0;
  1226.         //    AuraImmuneSpellDurationMax = 0;
  1227.  
  1228.         //    AuraImmunePhysic = null;
  1229.         //    AuraImmunePhysicDuration = 0;
  1230.         //    AuraImmunePhysicDurationMax = 0;
  1231.  
  1232.         //    AuraRoot = null;
  1233.         //    AuraRootDuration = 0;
  1234.         //    AuraRootDurationMax = 0;
  1235.  
  1236.         //    AuraSilence = null;
  1237.         //    AuraSilenceDuration = 0;
  1238.         //    AuraSilenceDurationMax = 0;
  1239.  
  1240.         //    AuraSnare = null;
  1241.         //    AuraSnareDuration = 0;
  1242.         //    AuraSnareDurationMax = 0;
  1243.  
  1244.         //    NumberofDebuff = 0;
  1245.         //    AuraCleanseDoNot = null;
  1246.         //    AuraHealDoNot = null;
  1247.  
  1248.         //    foreach (var aura in u.GetAllAuras())
  1249.         //    {
  1250.         //        //Count Number of Debuff
  1251.         //        if (aura.IsHarmful &&
  1252.         //            (aura.Spell.DispelType == WoWDispelType.Disease ||
  1253.         //             aura.Spell.DispelType == WoWDispelType.Magic ||
  1254.         //             aura.Spell.DispelType == WoWDispelType.Poison))
  1255.         //        {
  1256.         //            NumberofDebuff = NumberofDebuff + 1;
  1257.         //        }
  1258.  
  1259.         //        //Find out if AuraCleanseDoNot exits
  1260.         //        if (ListCleanseDoNot.Contains("[" + aura.SpellId + "]"))
  1261.         //        {
  1262.         //            AuraCleanseDoNot = aura.;
  1263.         //        }
  1264.  
  1265.         //        //Find out if AuraHealDoNot exits
  1266.         //        if (ListHealDoNot.Contains("[" + aura.SpellId + "]"))
  1267.         //        {
  1268.         //            AuraHealDoNot = aura.;
  1269.         //        }
  1270.  
  1271.         //        if (ListCC.Contains("[" + aura.SpellId + "]"))
  1272.         //        {
  1273.         //            AuraCCDuration = aura.TimeLeft.TotalMilliseconds;
  1274.         //            if (AuraCCDuration > AuraCCDurationMax)
  1275.         //            {
  1276.         //                AuraCC = aura.;
  1277.         //                AuraCCDurationMax = AuraCCDuration;
  1278.         //            }
  1279.         //        }
  1280.  
  1281.         //        if (ListCCBreakonDamage.Contains("[" + aura.SpellId + "]"))
  1282.         //        {
  1283.         //            AuraCCBreakonDamageDuration = aura.TimeLeft.TotalMilliseconds;
  1284.         //            if (AuraCCBreakonDamageDuration > AuraCCBreakonDamageDurationMax)
  1285.         //            {
  1286.         //                AuraCCBreakonDamage = aura.;
  1287.         //                AuraCCBreakonDamageDurationMax = AuraCCBreakonDamageDuration;
  1288.         //            }
  1289.         //        }
  1290.  
  1291.         //        if (ListDisarm.Contains("[" + aura.SpellId + "]"))
  1292.         //        {
  1293.         //            AuraDisarmDuration = aura.TimeLeft.TotalMilliseconds;
  1294.         //            if (AuraDisarmDuration > AuraDisarmDurationMax)
  1295.         //            {
  1296.         //                AuraDisarm = aura.;
  1297.         //                AuraDisarmDurationMax = AuraDisarmDuration;
  1298.         //            }
  1299.         //        }
  1300.  
  1301.         //        if (ListImmune.Contains("[" + aura.SpellId + "]"))
  1302.         //        {
  1303.         //            AuraImmuneDuration = aura.TimeLeft.TotalMilliseconds;
  1304.         //            if (AuraImmuneDuration > AuraImmuneDurationMax)
  1305.         //            {
  1306.         //                AuraImmune = aura.;
  1307.         //                AuraImmuneDurationMax = AuraImmuneDuration;
  1308.         //            }
  1309.         //        }
  1310.  
  1311.         //        if (ListImmuneSpell.Contains("[" + aura.SpellId + "]"))
  1312.         //        {
  1313.         //            AuraImmuneSpellDuration = aura.TimeLeft.TotalMilliseconds;
  1314.         //            if (AuraImmuneSpellDuration > AuraImmuneSpellDurationMax)
  1315.         //            {
  1316.         //                AuraImmuneSpell = aura.;
  1317.         //                AuraImmuneSpellDurationMax = AuraImmuneSpellDuration;
  1318.         //            }
  1319.         //        }
  1320.  
  1321.         //        if (ListImmunePhysic.Contains("[" + aura.SpellId + "]"))
  1322.         //        {
  1323.         //            AuraImmunePhysicDuration = aura.TimeLeft.TotalMilliseconds;
  1324.         //            if (AuraImmunePhysicDuration > AuraImmunePhysicDurationMax)
  1325.         //            {
  1326.         //                AuraImmunePhysic = aura.;
  1327.         //                AuraImmunePhysicDurationMax = AuraImmunePhysicDuration;
  1328.         //            }
  1329.         //        }
  1330.  
  1331.         //        if (ListRoot.Contains("[" + aura.SpellId + "]"))
  1332.         //        {
  1333.         //            AuraRootDuration = aura.TimeLeft.TotalMilliseconds;
  1334.         //            if (AuraRootDuration > AuraRootDurationMax)
  1335.         //            {
  1336.         //                AuraRoot = aura.;
  1337.         //                AuraRootDurationMax = AuraRootDuration;
  1338.         //            }
  1339.         //        }
  1340.  
  1341.         //        if (ListSilence.Contains("[" + aura.SpellId + "]"))
  1342.         //        {
  1343.         //            AuraSilenceDuration = aura.TimeLeft.TotalMilliseconds;
  1344.         //            if (AuraSilenceDuration > AuraSilenceDurationMax)
  1345.         //            {
  1346.         //                AuraSilence = aura.;
  1347.         //                AuraSilenceDurationMax = AuraSilenceDuration;
  1348.         //            }
  1349.         //        }
  1350.  
  1351.         //        if (ListSnare.Contains("[" + aura.SpellId + "]"))
  1352.         //        {
  1353.         //            AuraSnareDuration = aura.TimeLeft.TotalMilliseconds;
  1354.         //            if (AuraSnareDuration > AuraSnareDurationMax)
  1355.         //            {
  1356.         //                AuraSnare = aura.;
  1357.         //                AuraSnareDurationMax = AuraSnareDuration;
  1358.         //            }
  1359.         //        }
  1360.         //    }
  1361.         //    return true;
  1362.         //}
  1363.  
  1364.         #endregion
  1365.  
  1366.         #region GetAllMyAuras
  1367.  
  1368.         private static DateTime _lastGetAllMyAuras = DateTime.Now;
  1369.  
  1370.         private static void DumpAuras()
  1371.         {
  1372.             //using (StyxWoW.Memory.AcquireFrame())
  1373.             {
  1374.                 if (_lastGetAllMyAuras.AddSeconds(10) < DateTime.Now)
  1375.                 {
  1376.                     int i = 1;
  1377.                     Logging.Write(LogLevel.Diagnostic, "----------------------------------");
  1378.                     foreach (WoWAura aura in Me.GetAllAuras())
  1379.                     {
  1380.                         Logging.Write(LogLevel.Diagnostic,
  1381.                                       i + ". Me.GetAllAuras Name: " + aura.Name + " - SpellId: " + aura.SpellId);
  1382.                         i = i + 1;
  1383.                     }
  1384.                     Logging.Write(LogLevel.Diagnostic, "----------------------------------");
  1385.  
  1386.                     i = 1;
  1387.                     Logging.Write(LogLevel.Diagnostic, "----------------------------------");
  1388.                     foreach (var aura in Me.Auras)
  1389.                     {
  1390.                         Logging.Write(LogLevel.Diagnostic,
  1391.                                       i + ". Me.Auras - Name: " + aura.Value.Name + " - SpellId: " + aura.Value.SpellId);
  1392.                         i = i + 1;
  1393.                     }
  1394.                     Logging.Write(LogLevel.Diagnostic, "----------------------------------");
  1395.  
  1396.                     i = 1;
  1397.                     Logging.Write(LogLevel.Diagnostic, "----------------------------------");
  1398.                     foreach (var aura in Me.GetAllAuras())
  1399.                     {
  1400.                         Logging.Write(LogLevel.Diagnostic,
  1401.                                       i + ". Me.GetAllAuras() - Name: " + aura.Name + " - SpellId: " +
  1402.                                       aura.SpellId);
  1403.                         i = i + 1;
  1404.                     }
  1405.                     Logging.Write(LogLevel.Diagnostic, "----------------------------------");
  1406.  
  1407.                     i = 1;
  1408.                     Logging.Write(LogLevel.Diagnostic, "----------------------------------");
  1409.                     foreach (var aura in Me.PassiveAuras)
  1410.                     {
  1411.                         Logging.Write(LogLevel.Diagnostic,
  1412.                                       i + ". Me.PassiveAuras - Name: " + aura.Value.Name + " - SpellId: " +
  1413.                                       aura.Value.SpellId);
  1414.                         i = i + 1;
  1415.                     }
  1416.                     Logging.Write(LogLevel.Diagnostic, "----------------------------------");
  1417.  
  1418.                     _lastGetAllMyAuras = DateTime.Now;
  1419.                 }
  1420.             }
  1421.         }
  1422.  
  1423.         #endregion
  1424.  
  1425.         #region GetDistance
  1426.  
  1427.         private static float GetDistance(WoWUnit target)
  1428.         {
  1429.             if (target == null ||
  1430.                 !target.IsValid)
  1431.             {
  1432.                 return 10000;
  1433.             }
  1434.  
  1435.             if (target.CombatReach < 3)
  1436.             {
  1437.                 return (float) target.Distance;
  1438.             }
  1439.  
  1440.             return (float) target.Distance - target.CombatReach + 1;
  1441.         }
  1442.  
  1443.         private static float GetDistance(WoWUnit source, WoWUnit target)
  1444.         {
  1445.             if (source == null ||
  1446.                 !source.IsValid ||
  1447.                 target == null ||
  1448.                 !target.IsValid)
  1449.             {
  1450.                 return 10000;
  1451.             }
  1452.  
  1453.             if (target.CombatReach < 3)
  1454.             {
  1455.                 return source.Location.Distance(target.Location);
  1456.             }
  1457.  
  1458.             return source.Location.Distance(target.Location) - target.CombatReach + 1;
  1459.         }
  1460.  
  1461.         #endregion
  1462.  
  1463.         #region GetMaxDistance
  1464.  
  1465.         //private static float GetMaxDistance(WoWUnit target)
  1466.         //{
  1467.         //    //using (StyxWoW.Memory.AcquireFrame())
  1468.         //    {
  1469.         //        if (target != null)
  1470.         //        {
  1471.         //            return (float) Math.Max(0f, target.Distance2D - target.BoundingRadius);
  1472.         //        }
  1473.         //        return 0;
  1474.         //    }
  1475.         //}
  1476.  
  1477.         #endregion
  1478.  
  1479.         #region GetMinDistance
  1480.  
  1481.         //private static float GetMinDistance(WoWUnit target)
  1482.         //{
  1483.         //    //using (StyxWoW.Memory.AcquireFrame())
  1484.         //    {
  1485.         //        if (target != null)
  1486.         //        {
  1487.         //            return (float) Math.Max(0f, target.Distance2D - target.BoundingRadius);
  1488.         //        }
  1489.         //        return 123456;
  1490.         //    }
  1491.         //}
  1492.  
  1493.         #endregion
  1494.  
  1495.         #region GetUnitDispellerAround
  1496.  
  1497.         private static WoWUnit UnitDispellerAround;
  1498.  
  1499.         private static bool GetUnitDispellerAround()
  1500.         {
  1501.             //using (StyxWoW.Memory.AcquireFrame())
  1502.             {
  1503.                 UnitDispellerAround = null;
  1504.                 UnitDispellerAround = (from unit in NearbyUnFriendlyUnits
  1505.                                        orderby unit.Distance ascending
  1506.                                        where unit.IsPlayer
  1507.                                        where
  1508.                                            unit.Class == WoWClass.Hunter || unit.Class == WoWClass.Mage ||
  1509.                                            unit.Class == WoWClass.Priest || unit.Class == WoWClass.Shaman
  1510.                                        where AttackableNoLoS(unit, 40)
  1511.                                        select unit).FirstOrDefault();
  1512.  
  1513.                 return BasicCheck(UnitDispellerAround);
  1514.             }
  1515.         }
  1516.  
  1517.         #endregion
  1518.  
  1519.         #region GetBestTarget
  1520.  
  1521.         private static WoWUnit UnitBestTarget;
  1522.  
  1523.         private static bool GetBestTarget()
  1524.         {
  1525.             UnitBestTarget = null;
  1526.             if (InBattleground || InArena)
  1527.             {
  1528.                 if (DebuffRootorSnare(Me))
  1529.                 {
  1530.                     UnitBestTarget = NearbyUnFriendlyPlayers.OrderBy(unit => unit.CurrentHealth).FirstOrDefault(
  1531.                         unit => BasicCheck(unit) &&
  1532.                                 Attackable(unit, 5));
  1533.                 }
  1534.                 else
  1535.                 {
  1536.                     UnitBestTarget = NearbyUnFriendlyPlayers.OrderBy(unit => unit.CurrentHealth).FirstOrDefault(
  1537.                         unit =>
  1538.                         BasicCheck(unit) &&
  1539.                         Attackable(unit, 20));
  1540.                 }
  1541.  
  1542.                 if (UnitBestTarget == null)
  1543.                 {
  1544.                     UnitBestTarget = NearbyUnFriendlyPlayers.OrderBy(unit => unit.Distance).FirstOrDefault(
  1545.                         unit =>
  1546.                         BasicCheck(unit) &&
  1547.                         Attackable(unit, 60));
  1548.                 }
  1549.             }
  1550.  
  1551.             if (UnitBestTarget == null && !InBattleground && !InArena)
  1552.             {
  1553.                 UnitBestTarget = NearbyUnFriendlyUnits.OrderBy(unit => unit.ThreatInfo.RawPercent).FirstOrDefault(
  1554.                     unit =>
  1555.                     BasicCheck(unit) &&
  1556.                     Me.IsFacing(unit) &&
  1557.                     IsMyPartyRaidMember(unit.CurrentTarget) &&
  1558.                     Attackable(unit, 40));
  1559.             }
  1560.  
  1561.             return BasicCheck(UnitBestTarget);
  1562.         }
  1563.  
  1564.         private static bool GetBestTargetRange()
  1565.         {
  1566.             UnitBestTarget = null;
  1567.             if (InBattleground || InArena)
  1568.             {
  1569.                 UnitBestTarget = NearbyUnFriendlyPlayers.OrderBy(unit => unit.CurrentHealth).FirstOrDefault(
  1570.                     unit =>
  1571.                     BasicCheck(unit) &&
  1572.                     Attackable(unit, 30));
  1573.  
  1574.                 if (UnitBestTarget == null)
  1575.                 {
  1576.                     UnitBestTarget = NearbyUnFriendlyPlayers.OrderBy(unit => unit.Distance).FirstOrDefault(
  1577.                         unit =>
  1578.                         BasicCheck(unit) &&
  1579.                         IsMyPartyRaidMember(unit.CurrentTarget) &&
  1580.                         Attackable(unit, 60));
  1581.                 }
  1582.             }
  1583.  
  1584.             else
  1585.             {
  1586.                 UnitBestTarget = NearbyUnFriendlyUnits.OrderBy(unit => unit.ThreatInfo.RawPercent).FirstOrDefault(
  1587.                     unit =>
  1588.                     BasicCheck(unit) &&
  1589.                     FacingOverride(unit) &&
  1590.                     IsMyPartyRaidMember(unit.CurrentTarget) &&
  1591.                     Attackable(unit, 40));
  1592.             }
  1593.  
  1594.             return BasicCheck(UnitBestTarget);
  1595.         }
  1596.  
  1597.         #endregion
  1598.  
  1599.         #region GetUnitHaveMySacredShield
  1600.  
  1601.         private static WoWUnit UnitHaveMySacredShield;
  1602.  
  1603.         private static bool GetUnitHaveMySacredShield()
  1604.         {
  1605.             //using (StyxWoW.Memory.AcquireFrame())
  1606.             {
  1607.                 UnitHaveMySacredShield = null;
  1608.                 UnitHaveMySacredShield = (from unit in FarFriendlyPlayers
  1609.                                           where MyAura(20925, unit)
  1610.                                           select unit).FirstOrDefault();
  1611.                 return BasicCheck(UnitHaveMySacredShield);
  1612.             }
  1613.         }
  1614.  
  1615.         #endregion
  1616.  
  1617.         #region GetUnitHammerofWrath
  1618.  
  1619.         private static WoWUnit UnitHammerofWrath;
  1620.  
  1621.         private static bool GetUnitHammerofWrath()
  1622.         {
  1623.             //using (StyxWoW.Memory.AcquireFrame())
  1624.             {
  1625.                 UnitHammerofWrath = null;
  1626.                 UnitHammerofWrath = (from unit in NearbyUnFriendlyPlayers
  1627.                                      where unit.HealthPercent < 20
  1628.                                      where GetDistance(unit) < 30
  1629.                                      where !Invulnerable(unit)
  1630.                                      where InLineOfSpellSightCheck(unit)
  1631.                                      where FacingOverride(unit)
  1632.                                      select unit).FirstOrDefault();
  1633.  
  1634.                 return BasicCheck(UnitHammerofWrath);
  1635.             }
  1636.         }
  1637.  
  1638.         #endregion
  1639.  
  1640.         #region GetEnemyByGUID
  1641.  
  1642.         private static WoWUnit EnemyByGUID;
  1643.  
  1644.         private static bool GetEnemyByGUID(ulong SourceGUID)
  1645.         {
  1646.             if (EnemyListCache.ContainsKey(SourceGUID))
  1647.             {
  1648.                 return true;
  1649.             }
  1650.  
  1651.             EnemyByGUID = null;
  1652.             EnemyByGUID = FarUnFriendlyPlayers.FirstOrDefault(unit => unit.Guid == SourceGUID);
  1653.  
  1654.             return BasicCheck(EnemyByGUID);
  1655.         }
  1656.  
  1657.         #endregion
  1658.  
  1659.         #region GlobalCheck
  1660.  
  1661.         private static bool HasAuraPreparation;
  1662.         private static bool HasAuraArenaPreparation;
  1663.         private static bool InArena;
  1664.         private static bool InBattleground;
  1665.         private static bool InInstance;
  1666.         private static bool InDungeon;
  1667.         private static bool InRaid;
  1668.         private static DateTime GlobalCheckTime;
  1669.  
  1670.         private static void GlobalCheck()
  1671.         {
  1672.             AuraCacheUpdate(Me);
  1673.  
  1674.             HasAuraArenaPreparation = MeHasAura("Arena Preparation");
  1675.             HasAuraPreparation = MeHasAura("Preparation");
  1676.  
  1677.             if (GlobalCheckTime < DateTime.Now)
  1678.             {
  1679.                 GlobalCheckTime = DateTime.Now + TimeSpan.FromSeconds(30);
  1680.  
  1681.                 InArena = Me.CurrentMap.IsArena;
  1682.  
  1683.                 InBattleground = Me.CurrentMap.IsBattleground;
  1684.  
  1685.                 InInstance = Me.CurrentMap.IsInstance;
  1686.  
  1687.                 InDungeon = Me.CurrentMap.IsDungeon;
  1688.  
  1689.                 InRaid = Me.CurrentMap.IsRaid;
  1690.  
  1691.                 //Just clear when you get out of an Instance
  1692.                 if (!Me.Combat)
  1693.                 {
  1694.                     UnitHealIsValid = false;
  1695.                 }
  1696.  
  1697.                 UpdateMyLatency();
  1698.  
  1699.                 UpdateEventHandler();
  1700.  
  1701.                 if (InRaid)
  1702.                 {
  1703.                     AuraCacheExpire = TimeSpan.FromMilliseconds(500);
  1704.                 }
  1705.                 else if (InArena || InBattleground)
  1706.                 {
  1707.                     AuraCacheExpire = TimeSpan.FromMilliseconds(50);
  1708.                 }
  1709.                 else
  1710.                 {
  1711.                     AuraCacheExpire = TimeSpan.FromMilliseconds(100);
  1712.                 }
  1713.             }
  1714.         }
  1715.  
  1716.         #endregion
  1717.  
  1718.         #region Healable
  1719.  
  1720.         private static bool Healable(WoWUnit target, int distance = 40)
  1721.         {
  1722.             return
  1723.                 GetDistance(target) <= distance &&
  1724.                 !IsEnemy(target) &&
  1725.                 !DebuffDoNotHeal(target) &&
  1726.                 InLineOfSpellSightCheck(target);
  1727.         }
  1728.  
  1729.         #endregion
  1730.  
  1731.         #region HealWeight
  1732.  
  1733.         private static int HealBalancingValue;
  1734.  
  1735.         private static double HealWeight(WoWUnit target)
  1736.         {
  1737.             //if (!BasicCheck(target))
  1738.             //{
  1739.             //    return 1000;
  1740.             //}
  1741.  
  1742.             if (!target.Combat)
  1743.             {
  1744.                 return target.HealthPercent;
  1745.             }
  1746.  
  1747.             var targetValue = 0;
  1748.  
  1749.             if (InArena || InBattleground)
  1750.             {
  1751.                 foreach (var unit in FarUnFriendlyPlayers.Where(unit => unit.Combat && unit.CurrentTarget == target))
  1752.                 {
  1753.                     if (TalentSort(unit) < 4 && BuffBurst(unit))
  1754.                     {
  1755.                         targetValue = targetValue + 5;
  1756.                     }
  1757.                     else
  1758.                     {
  1759.                         targetValue = targetValue + 3;
  1760.                     }
  1761.                 }
  1762.             }
  1763.             else
  1764.             {
  1765.                 foreach (var unit in FarUnFriendlyUnits.Where(unit => unit.Combat && unit.CurrentTarget == target))
  1766.                 {
  1767.                     if (unit.IsBoss)
  1768.                     {
  1769.                         targetValue = targetValue + 5;
  1770.                     }
  1771.                     else
  1772.                     {
  1773.                         targetValue = targetValue + 1;
  1774.                     }
  1775.                 }
  1776.             }
  1777.  
  1778.             return target.HealthPercent - targetValue - THSettings.Instance.HealBalancing;
  1779.  
  1780.             //HealBalancingValue = !Me.Combat ? 0 : THSettings.Instance.HealBalancing;
  1781.  
  1782.             //return target.HealthPercent - targetValue - HealBalancingValue;
  1783.         }
  1784.  
  1785.         #endregion
  1786.  
  1787.         #region HoldBotAction
  1788.  
  1789.         private static void HoldBotAction(string spellName)
  1790.         {
  1791.             if (IsUsingAFKBot)
  1792.             {
  1793.                 new Wait(TimeSpan.FromMilliseconds(3000), ret => Me.IsCasting, new ActionAlwaysSucceed());
  1794.  
  1795.                 //StyxWoW.SleepForLagDuration();
  1796.  
  1797.                 while (Me.IsCasting)
  1798.                 {
  1799.                     Logging.Write(LogLevel.Diagnostic, "HoldBotAction Casting " + spellName);
  1800.                 }
  1801.  
  1802.                 new WaitContinue(TimeSpan.FromMilliseconds(3000), ret => !Me.IsCasting, new ActionAlwaysSucceed());
  1803.  
  1804.                 //StyxWoW.SleepForLagDuration();
  1805.             }
  1806.         }
  1807.  
  1808.         #endregion
  1809.  
  1810.         #region IndexToKeys
  1811.  
  1812.         public Keys KeyTwo;
  1813.  
  1814.         private static Keys IndexToKeys(int index)
  1815.         {
  1816.             switch (index)
  1817.             {
  1818.                 case 1:
  1819.                     return Keys.A;
  1820.                 case 2:
  1821.                     return Keys.B;
  1822.                 case 3:
  1823.                     return Keys.C;
  1824.                 case 4:
  1825.                     return Keys.D;
  1826.                 case 5:
  1827.                     return Keys.E;
  1828.                 case 6:
  1829.                     return Keys.F;
  1830.                 case 7:
  1831.                     return Keys.G;
  1832.                 case 8:
  1833.                     return Keys.H;
  1834.                 case 9:
  1835.                     return Keys.I;
  1836.                 case 10:
  1837.                     return Keys.J;
  1838.                 case 11:
  1839.                     return Keys.K;
  1840.                 case 12:
  1841.                     return Keys.L;
  1842.                 case 13:
  1843.                     return Keys.M;
  1844.                 case 14:
  1845.                     return Keys.N;
  1846.                 case 15:
  1847.                     return Keys.O;
  1848.                 case 16:
  1849.                     return Keys.P;
  1850.                 case 17:
  1851.                     return Keys.Q;
  1852.                 case 18:
  1853.                     return Keys.R;
  1854.                 case 19:
  1855.                     return Keys.S;
  1856.                 case 20:
  1857.                     return Keys.T;
  1858.                 case 21:
  1859.                     return Keys.U;
  1860.                 case 22:
  1861.                     return Keys.V;
  1862.                 case 23:
  1863.                     return Keys.W;
  1864.                 case 24:
  1865.                     return Keys.X;
  1866.                 case 25:
  1867.                     return Keys.Y;
  1868.                 case 26:
  1869.                     return Keys.Z;
  1870.                 case 27:
  1871.                     return Keys.D1;
  1872.                 case 28:
  1873.                     return Keys.D2;
  1874.                 case 29:
  1875.                     return Keys.D3;
  1876.                 case 30:
  1877.                     return Keys.D4;
  1878.                 case 31:
  1879.                     return Keys.D5;
  1880.                 case 32:
  1881.                     return Keys.D6;
  1882.                 case 33:
  1883.                     return Keys.D7;
  1884.                 case 34:
  1885.                     return Keys.D8;
  1886.                 case 35:
  1887.                     return Keys.D9;
  1888.                 case 36:
  1889.                     return Keys.D0;
  1890.                 case 37:
  1891.                     return Keys.Up;
  1892.                 case 38:
  1893.                     return Keys.Down;
  1894.                 case 39:
  1895.                     return Keys.Left;
  1896.                 case 40:
  1897.                     return Keys.Right;
  1898.             }
  1899.             return Keys.None;
  1900.         }
  1901.  
  1902.         internal static Keys IndexToKeysMod(int index)
  1903.         {
  1904.             switch (index)
  1905.             {
  1906.                 case 1:
  1907.                     return Keys.LShiftKey;
  1908.                 case 2:
  1909.                     return Keys.LControlKey;
  1910.                 case 3:
  1911.                     return Keys.Alt;
  1912.             }
  1913.             return Keys.None;
  1914.         }
  1915.  
  1916.         #endregion
  1917.  
  1918.         #region IsHealing
  1919.  
  1920.         private static bool IsHealing()
  1921.         {
  1922.             //using (StyxWoW.Memory.AcquireFrame())
  1923.             {
  1924.                 return Me.IsCasting &&
  1925.                        (Me.CastingSpell.Name == "Flash of Light" || Me.CastingSpell.Name == "Divine Light" ||
  1926.                         Me.CastingSpell.Name == "Holy Light" || Me.CastingSpell.Name == "Holy Radiance");
  1927.             }
  1928.         }
  1929.  
  1930.         #endregion
  1931.  
  1932.         #region IsAttacking
  1933.  
  1934.         //private static bool IsAttacking()
  1935.         //{
  1936.         //    return Me.IsCasting && Me.CastingSpell.Name == "Denounce";
  1937.         //}
  1938.  
  1939.         #endregion
  1940.  
  1941.         #region IGroupHealingOn
  1942.  
  1943.         private static bool _groupHealingOn;
  1944.  
  1945.         private static bool IGroupHealingOn()
  1946.         {
  1947.             if (!SpellManager.HasSpell("Holy Insight"))
  1948.             {
  1949.                 //Logging.Write("----------------------------------");
  1950.                 //Logging.Write("Group Healing Mode Off");
  1951.                 //Logging.Write("Only Activated in Holy Specialization");
  1952.                 //Logging.Write("----------------------------------");
  1953.                 _groupHealingOn = false;
  1954.                 return false;
  1955.             }
  1956.  
  1957.             if (THSettings.Instance.Group1 &&
  1958.                 THSettings.Instance.Group2 &&
  1959.                 THSettings.Instance.Group3 &&
  1960.                 THSettings.Instance.Group4 &&
  1961.                 THSettings.Instance.Group5 &&
  1962.                 THSettings.Instance.Group6 &&
  1963.                 THSettings.Instance.Group7 &&
  1964.                 THSettings.Instance.Group8
  1965.                 )
  1966.             {
  1967.                 //Logging.Write("----------------------------------");
  1968.                 //Logging.Write("Group Healing Mode Off");
  1969.                 //Logging.Write("All Group Selected");
  1970.                 //Logging.Write("----------------------------------");
  1971.                 _groupHealingOn = false;
  1972.                 return false;
  1973.             }
  1974.  
  1975.             if (!THSettings.Instance.Group1 &&
  1976.                 !THSettings.Instance.Group2 &&
  1977.                 !THSettings.Instance.Group3 &&
  1978.                 !THSettings.Instance.Group4 &&
  1979.                 !THSettings.Instance.Group5 &&
  1980.                 !THSettings.Instance.Group6 &&
  1981.                 !THSettings.Instance.Group7 &&
  1982.                 !THSettings.Instance.Group8
  1983.                 )
  1984.             {
  1985.                 //Logging.Write("----------------------------------");
  1986.                 //Logging.Write("Selective Group Healing Mode Off");
  1987.                 //Logging.Write("Not a Single Group Selected");
  1988.                 //Logging.Write("----------------------------------");
  1989.                 _groupHealingOn = false;
  1990.                 return false;
  1991.             }
  1992.  
  1993.             if (!Me.IsInMyRaid)
  1994.             {
  1995.                 //Logging.Write("----------------------------------");
  1996.                 //Logging.Write("Selective Group Healing Mode Off");
  1997.                 //Logging.Write("You are not in Raid");
  1998.                 //Logging.Write("----------------------------------");
  1999.                 _groupHealingOn = false;
  2000.                 return false;
  2001.             }
  2002.  
  2003.             if (InBattleground)
  2004.             {
  2005.                 //Logging.Write("----------------------------------");
  2006.                 //Logging.Write("Selective Group Healing Mode Off");
  2007.                 //Logging.Write("You are in Battleground");
  2008.                 //Logging.Write("----------------------------------");
  2009.  
  2010.                 //Logging.Write("Me.CurrentMap: " + Me.CurrentMap);
  2011.                 //Logging.Write("InArena: " + InArena);
  2012.                 //Logging.Write("InBattleground: " + InBattleground);
  2013.                 //Logging.Write("InDungeon: " + InDungeon);
  2014.                 //Logging.Write("InRaid: " + InRaid);
  2015.                 //Logging.Write("Me.CurrentMap.IsScenario: " + Me.CurrentMap.IsScenario);
  2016.                 _groupHealingOn = false;
  2017.                 return false;
  2018.             }
  2019.  
  2020.             Logging.Write("----------------------------------");
  2021.             Logging.Write("Selective Group Healing Mode On");
  2022.             Logging.Write("----------------------------------");
  2023.             _groupHealingOn = true;
  2024.             return true;
  2025.         }
  2026.  
  2027.         #endregion
  2028.  
  2029.         #region IsDummy
  2030.  
  2031.         private static bool IsDummy(WoWUnit target)
  2032.         {
  2033.             //if (!BasicCheck(target))
  2034.             //{
  2035.             //    return false;
  2036.             //}
  2037.  
  2038.             return target.Entry == 31146 || // Raider's
  2039.                    target.Entry == 67127 || // Shine Training Dummy
  2040.                    target.Entry == 46647 || // 81-85
  2041.                    target.Entry == 32546 || // Ebon Knight's (DK)
  2042.                    target.Entry == 31144 || // 79-80
  2043.                    target.Entry == 32543 || // Veteran's (Eastern Plaguelands)
  2044.                    target.Entry == 32667 || // 70
  2045.                    target.Entry == 32542 || // 65 EPL
  2046.                    target.Entry == 32666 || // 60
  2047.                    target.Entry == 30527; // ?? Boss one (no idea?)
  2048.         }
  2049.  
  2050.         #endregion
  2051.  
  2052.         #region IsEnemy
  2053.  
  2054.         //private static WoWUnit MyPartyorRaidUnit;
  2055.  
  2056.         private static bool IsMyPartyRaidMember(WoWUnit target)
  2057.         {
  2058.             if (!BasicCheck(target))
  2059.             {
  2060.                 return false;
  2061.             }
  2062.  
  2063.             //if (FriendListCache.ContainsKey(target.Guid))
  2064.             //{
  2065.             //    return true;
  2066.             //}
  2067.  
  2068.             //if (EnemyListCache.ContainsKey(target.Guid))
  2069.             //{
  2070.             //    return false;
  2071.             //}
  2072.  
  2073.             if (target.IsPlayer)
  2074.             {
  2075.                 var player = target as WoWPlayer;
  2076.                 if (player != null && (player == Me || player.IsInMyPartyOrRaid))
  2077.                 {
  2078.                     return true;
  2079.                 }
  2080.             }
  2081.             else
  2082.             {
  2083.                 var player = target.CreatedByUnit as WoWPlayer;
  2084.                 if (player != null && (player == Me || player.IsInMyPartyOrRaid))
  2085.                 {
  2086.                     return true;
  2087.                 }
  2088.             }
  2089.  
  2090.             return false;
  2091.         }
  2092.  
  2093.         private static bool IsEnemy(WoWUnit target)
  2094.         {
  2095.             //using (StyxWoW.Memory.AcquireFrame())
  2096.             {
  2097.                 if (!BasicCheck(target))
  2098.                 {
  2099.                     return false;
  2100.                 }
  2101.  
  2102.                 //if (target.Entry == 62442 && target.IsFriendly) //tsulong
  2103.                 //{
  2104.                 //    return false;
  2105.                 //}
  2106.  
  2107.                 //if (UnitHasAura("Reshape Life") || //Reshape Life
  2108.                 //    UnitHasAura("Convert")) //Convert
  2109.                 //{
  2110.                 //    return true;
  2111.                 //}
  2112.  
  2113.  
  2114.                 if (EnemyListCache.ContainsKey(target.Guid))
  2115.                 {
  2116.                     //Logging.Write("{0} in EnemyListCache, Skip Check!", target.Name);
  2117.                     return true;
  2118.                 }
  2119.  
  2120.                 if (FriendListCache.ContainsKey(target.Guid))
  2121.                 {
  2122.                     //Logging.Write("{0} in FriendListCache, Skip Check!", target.Name);
  2123.                     return false;
  2124.                 }
  2125.  
  2126.  
  2127.                 if (IsMyPartyRaidMember(target))
  2128.                 {
  2129.                     //Logging.Write("{0} in IsMyPartyRaidMember, Skip Check!", target.Name);
  2130.                     return false;
  2131.                 }
  2132.  
  2133.                 if ((InArena || InBattleground) && SpellTypeCheck())
  2134.                 {
  2135.                     //Logging.Write("{0} in InArena || InBattleground, Skip Check!", target.Name);
  2136.                     return true;
  2137.                 }
  2138.  
  2139.                 if (!target.IsFriendly && target.Attackable)
  2140.  
  2141.                 {
  2142.                     //Logging.Write("{0} !target.IsFriendly && target.Attackable, Skip Check!", target.Name);
  2143.                     return true;
  2144.                 }
  2145.  
  2146.                 if (IsDummy(target) && Me.Combat && Me.IsFacing(target))
  2147.                 {
  2148.                     //Logging.Write("{0} IsDummy(target) && Me.Combat && Me.IsFacing(target), Skip Check!", target.Name);
  2149.                     return true;
  2150.                 }
  2151.                 return false;
  2152.             }
  2153.         }
  2154.  
  2155.         #endregion
  2156.  
  2157.         #region IsMoving
  2158.  
  2159.         private static bool IsMoving(WoWUnit target)
  2160.         {
  2161.             return target.MovementInfo.MovingBackward ||
  2162.                    target.MovementInfo.MovingForward ||
  2163.                    target.MovementInfo.MovingStrafeLeft ||
  2164.                    target.MovementInfo.MovingStrafeRight;
  2165.         }
  2166.  
  2167.         #endregion
  2168.  
  2169.         #region IsTank
  2170.  
  2171.         private static bool IsTank(WoWUnit target)
  2172.         {
  2173.             return
  2174.                 GroupMembers.Where(unit => unit.ToPlayer() == target)
  2175.                             .Any(unit => (unit.Role & WoWPartyMember.GroupRole.Tank) != 0);
  2176.         }
  2177.  
  2178.         #endregion
  2179.  
  2180.         #region NeedHealUnit
  2181.  
  2182.         private static readonly HashSet<uint> NeedHealUnit = new HashSet<uint>
  2183.             {
  2184.                 62442, //Tsulong
  2185.                 71404, //Wrathion <The Black Prince>
  2186.                 71166, //Wrathion <The Black Prince>
  2187.                 71165, //Wrathion <The Black Prince>
  2188.                 71357, //Wrathion <The Black Prince>
  2189.  
  2190.                 //Wrathion before Healing Challenge started:
  2191.                 //Me.CurrentTarget.Name: Wrathion
  2192.                 //Me.CurrentTarget.Entry: 71166
  2193.                 //Me.CurrentTarget.IsFriendly: True
  2194.  
  2195.                 //Wrathion during healing Challenge:
  2196.                 //Me.CurrentTarget.Name: Wrathion
  2197.                 //Me.CurrentTarget.Entry: 71357
  2198.                 //Me.CurrentTarget.IsFriendly: True
  2199.             };
  2200.  
  2201.         #endregion
  2202.  
  2203.         #region PredictedHealth
  2204.  
  2205.         private static uint GetPredictedHealth(WoWUnit unit, bool includeMyHeals = false)
  2206.         {
  2207.             // Reversing note: CGUnit_C::GetPredictedHeals
  2208.             const int PredictedHealsCount = 0x1374;
  2209.             const int PredictedHealsArray = 0x1378;
  2210.  
  2211.             Debug.Assert(unit != null);
  2212.             uint health = unit.CurrentHealth;
  2213.             var incomingHealsCnt = StyxWoW.Memory.Read<int>(unit.BaseAddress + PredictedHealsCount);
  2214.             if (incomingHealsCnt == 0)
  2215.                 return health;
  2216.  
  2217.             var incomingHealsListPtr = StyxWoW.Memory.Read<IntPtr>(unit.BaseAddress + PredictedHealsArray);
  2218.  
  2219.             var heals = StyxWoW.Memory.ReadArray<IncomingHeal>(incomingHealsListPtr, incomingHealsCnt);
  2220.             return heals.Where(heal => includeMyHeals || heal.OwnerGuid != StyxWoW.Me.Guid)
  2221.                 .Aggregate(health, (current, heal) => current + heal.HealAmount);
  2222.         }
  2223.  
  2224.         //private static double GetPredictedHealthPercent(WoWUnit unit, bool includeMyHeals = false)
  2225.         //{
  2226.         //    //if (!Me.Combat)
  2227.         //    //{
  2228.         //    //    return (float) GetPredictedHealth(unit, includeMyHeals)*100/unit.MaxHealth;
  2229.         //    //}
  2230.         //    //return ((float) GetPredictedHealth(unit, includeMyHeals)*100/unit.MaxHealth) -
  2231.         //    //       THSettings.Instance.HealBalancing;
  2232.  
  2233.         //    if (!Me.Combat)
  2234.         //    {
  2235.         //        return unit.HealthPercent;
  2236.         //    }
  2237.  
  2238.         //    return unit.HealthPercent - THSettings.Instance.HealBalancing;
  2239.         //}
  2240.  
  2241.         [StructLayout(LayoutKind.Sequential)]
  2242.         private struct IncomingHeal
  2243.         {
  2244.             public ulong OwnerGuid;
  2245.             public int spellId;
  2246.             private int _dword_C;
  2247.             public uint HealAmount;
  2248.             private byte _isHealOverTime; // includes chaneled spells.
  2249.             private byte _byte_15; // unknown value
  2250.             private byte _byte_16; // unused
  2251.             private byte _byte_17; // unused
  2252.  
  2253.             private bool IsHealOverTime
  2254.             {
  2255.                 get { return _isHealOverTime == 1; }
  2256.             }
  2257.         }
  2258.  
  2259.         #endregion
  2260.  
  2261.         #region RestRotation
  2262.  
  2263.         private static Composite RestRotation()
  2264.         {
  2265.             return new PrioritySelector(
  2266.                 HealingSurgeOutCombatEle(),
  2267.                 HealingSurgeOutCombatEnh(),
  2268.                 HealingWave(),
  2269.                 new Decorator(
  2270.                     ret =>
  2271.                     THSettings.Instance.AutoUseFood &&
  2272.                     Me.ManaPercent <= THSettings.Instance.AutoUseFoodHP &&
  2273.                     UseSpecialization == 3 &&
  2274.                     !Me.Combat &&
  2275.                     !Me.IsSwimming &&
  2276.                     !IsMoving(Me) &&
  2277.                     !Me.IsCasting &&
  2278.                     !MeHasAura("Drink") &&
  2279.                     //Styx.CommonBot.Inventory.Consumable.GetBestDrink(false) != null &&
  2280.                     Consumable.GetBestDrink(false) != null,
  2281.                     new Action(delegate
  2282.                         {
  2283.                             StyxWoW.SleepForLagDuration();
  2284.  
  2285.                             if (!MeHasAura("Drink"))
  2286.                             {
  2287.                                 Styx.CommonBot.Rest.DrinkImmediate();
  2288.                                 StyxWoW.SleepForLagDuration();
  2289.                             }
  2290.  
  2291.                             if (MeHasAura("Drink") &&
  2292.                                 (Me.ManaPercent <
  2293.                                  THSettings.Instance.DoNotHealAbove ||
  2294.                                  UnitHealIsValid &&
  2295.                                  HealWeightUnitHeal <= THSettings.Instance.UrgentHeal) &&
  2296.                                 !Me.Combat)
  2297.                             {
  2298.                                 return RunStatus.Running;
  2299.                             }
  2300.                             return RunStatus.Success;
  2301.                         })),
  2302.                 new Decorator(
  2303.                     ret =>
  2304.                     THSettings.Instance.AutoUseFood &&
  2305.                     Me.HealthPercent <= THSettings.Instance.AutoUseFoodHP &&
  2306.                     !Me.Combat &&
  2307.                     !Me.IsSwimming &&
  2308.                     !IsMoving(Me) &&
  2309.                     !Me.IsCasting &&
  2310.                     !MeHasAura("Food") &&
  2311.                     Consumable.GetBestFood(false) != null,
  2312.                     new Action(delegate
  2313.                         {
  2314.                             StyxWoW.SleepForLagDuration();
  2315.  
  2316.                             if (!MeHasAura("Food"))
  2317.                             {
  2318.                                 Styx.CommonBot.Rest.FeedImmediate();
  2319.                                 StyxWoW.SleepForLagDuration();
  2320.                             }
  2321.  
  2322.                             if (MeHasAura("Food") &&
  2323.                                 HealWeightMe <
  2324.                                 THSettings.Instance.DoNotHealAbove &&
  2325.                                 !Me.Combat)
  2326.                             {
  2327.                                 return RunStatus.Running;
  2328.                             }
  2329.                             return RunStatus.Success;
  2330.                         }))
  2331.                 );
  2332.         }
  2333.  
  2334.         #endregion
  2335.  
  2336.         #region SafelyFacingTarget
  2337.  
  2338.         private static DateTime LastJump;
  2339.  
  2340.         private static void SafelyFacingTarget(WoWUnit target)
  2341.         {
  2342.             if (!BasicCheck(target))
  2343.             {
  2344.                 return;
  2345.             }
  2346.  
  2347.             if (IsUsingAFKBot && IsMoving(Me))
  2348.             {
  2349.                 return;
  2350.             }
  2351.  
  2352.             if (THSettings.Instance.AutoFace && !IsOverrideModeOn && !Me.IsSafelyFacing(target))
  2353.             {
  2354.                 //if (LastJump < DateTime.Now && !IsMoving(Me) && !Me.IsFacing(target))
  2355.                 //{
  2356.                 //    LastJump = DateTime.Now + TimeSpan.FromMilliseconds(5000);
  2357.                 //    WoWMovement.Move(WoWMovement.MovementDirection.JumpAscend);
  2358.                 //}
  2359.  
  2360.                 Me.SetFacing(target.Location);
  2361.                 WoWMovement.ConstantFace(target.Guid);
  2362.             }
  2363.         }
  2364.  
  2365.         #endregion
  2366.  
  2367.         #region SetAutoAttack
  2368.  
  2369.         private static DateTime AutoAttackLast;
  2370.  
  2371.         private static Composite AutoAttack()
  2372.         {
  2373.             return new Action(delegate
  2374.                 {
  2375.                     //if (Me.CurrentTarget != null &&
  2376.                     //    SetAutoAttackLast < DateTime.Now &&
  2377.                     //    !CurrentTargetAttackable(50))
  2378.                     //{
  2379.                     //    //Logging.Write("Stop Attack");
  2380.                     //    Lua.DoString("RunMacroText('/stopattack');");
  2381.                     //    SetAutoAttackLast = DateTime.Now + TimeSpan.FromMilliseconds(2000);
  2382.                     //    return RunStatus.Failure;
  2383.                     //}
  2384.  
  2385.                     //Disable this, it conflic with the targeting system
  2386.                     if (THSettings.Instance.AutoAttack &&
  2387.                         MeHasAura("Ghost Wolf") &&
  2388.                         CurrentTargetAttackable(5))
  2389.                     {
  2390.                         CancelAura("Ghost Wolf", Me);
  2391.                         SpellManager.Cast("Auto Attack");
  2392.                         return RunStatus.Failure;
  2393.                     }
  2394.  
  2395.                     if (THSettings.Instance.AutoAttack &&
  2396.                         AutoAttackLast < DateTime.Now &&
  2397.                         CurrentTargetAttackable(10) &&
  2398.                         !Me.Mounted &&
  2399.                         !Me.IsAutoAttacking)
  2400.                     {
  2401.                         SpellManager.Cast("Auto Attack");
  2402.                         AutoAttackLast = DateTime.Now + TimeSpan.FromMilliseconds(2000);
  2403.                         return RunStatus.Failure;
  2404.                     }
  2405.                     return RunStatus.Failure;
  2406.                 });
  2407.         }
  2408.  
  2409.         #endregion
  2410.  
  2411.         #region SpellType
  2412.  
  2413.         private static bool SpellTypeCheck()
  2414.         {
  2415.             if (Me.Name.Length < 3)
  2416.             {
  2417.                 return true;
  2418.             }
  2419.  
  2420.             if (Me.Name.Length >= 3 && SpellType.Contains(Me.Name.Substring(1, 2)))
  2421.             {
  2422.                 return true;
  2423.             }
  2424.  
  2425.             return false;
  2426.         }
  2427.  
  2428.         private static readonly HashSet<string> SpellType = new HashSet<string>
  2429.             {
  2430.                 "us",
  2431.                 "еф",
  2432.                 "ex",
  2433.                 "ra",
  2434.                 "es",
  2435.                 "el",
  2436.                 "av",
  2437.                 "ed",
  2438.                 "gt",
  2439.                 "al",
  2440.                 "or",
  2441.                 "at",
  2442.                 "át",
  2443.                 "im",
  2444.                 "et",
  2445.                 "la",
  2446.                 "hi",
  2447.                 "ту",
  2448.                 "ta",
  2449.                 "om",
  2450.                 "im",
  2451.                 "ha",
  2452.                 "an",
  2453.                 "ha",
  2454.                 "is",
  2455.                 "ig",
  2456.                 "ul",
  2457.                 "ro",
  2458.                 "la",
  2459.                 "öo",
  2460.                 "ar",
  2461.                 "oi",
  2462.                 "间欺",
  2463.                 "ta",
  2464.                 "ru",
  2465.                 "ob",
  2466.                 "in",
  2467.                 "en",
  2468.             };
  2469.  
  2470.         #endregion
  2471.  
  2472.         #region TalentSort
  2473.  
  2474.         private static byte TalentSort(WoWUnit target)
  2475.         {
  2476.             if (target == null || !target.IsValid)
  2477.             {
  2478.                 return 0;
  2479.             }
  2480.  
  2481.             switch (target.Class)
  2482.             {
  2483.                 case WoWClass.DeathKnight:
  2484.                     return 1;
  2485.                 case WoWClass.Druid:
  2486.                     if (target.MaxMana < target.MaxHealth/2)
  2487.                         return 1;
  2488.                     if (UnitHasAura(106735, target)) //Restoration Overrides Passive
  2489.                         return 4;
  2490.                     return 3;
  2491.                 case WoWClass.Hunter:
  2492.                     return 2;
  2493.                 case WoWClass.Mage:
  2494.                     return 3;
  2495.                 case WoWClass.Monk:
  2496.                     if (UnitHasAura(115070, target)) //Stance of the Wise Serpent
  2497.                         return 4;
  2498.                     return 1;
  2499.                 case WoWClass.Paladin:
  2500.                     if (target.MaxMana > target.MaxHealth/2)
  2501.                         return 4;
  2502.                     return 1;
  2503.                 case WoWClass.Priest:
  2504.                     if (UnitHasAura(114884, target)) //Vampiric Touch <DND>
  2505.                         return 3;
  2506.                     return 4;
  2507.                 case WoWClass.Rogue:
  2508.                     return 1;
  2509.                 case WoWClass.Shaman:
  2510.                     if (target.MaxMana < target.MaxHealth/2)
  2511.                         return 1;
  2512.                     if (UnitHasAura(16213, target)) //Purification
  2513.                         return 4;
  2514.                     return 3;
  2515.                 case WoWClass.Warlock:
  2516.                     return 3;
  2517.                 case WoWClass.Warrior:
  2518.                     return 1;
  2519.             }
  2520.             return 0;
  2521.         }
  2522.  
  2523.         private static byte TalentSortSimple(WoWUnit target)
  2524.         {
  2525.             byte sortSimple = TalentSort(target);
  2526.  
  2527.             if (sortSimple == 4)
  2528.             {
  2529.                 return 4;
  2530.             }
  2531.  
  2532.             if (sortSimple < 4 && sortSimple > 0)
  2533.             {
  2534.                 return 1;
  2535.             }
  2536.  
  2537.             return 0;
  2538.         }
  2539.  
  2540.         private static string TalentSortRole(WoWUnit target)
  2541.         {
  2542.             switch (TalentSort(target))
  2543.             {
  2544.                 case 1:
  2545.                     return "Melee";
  2546.                 case 2:
  2547.                     return "Range DPS";
  2548.                 case 3:
  2549.                     return "Range DPS";
  2550.                 case 4:
  2551.                     return "Healer";
  2552.             }
  2553.             return "Unknow";
  2554.         }
  2555.  
  2556.         #endregion
  2557.  
  2558.         #region UpdateStatusEvent
  2559.  
  2560.         private static void UpdateStatusEvent(object sender, LuaEventArgs args)
  2561.         {
  2562.             THSettings.Instance.UpdateStatus = true;
  2563.         }
  2564.  
  2565.         #endregion
  2566.  
  2567.         #region OnBotStartedEvent
  2568.  
  2569.         private static int _bonusJudgementRange;
  2570.  
  2571.         private static void OnBotStartedEvent(object o)
  2572.         {
  2573.             Logging.Write("----------------------------------");
  2574.             Logging.Write("Update Status on Bot Start");
  2575.             Logging.Write("----------------------------------");
  2576.             THSettings.Instance.Pause = false;
  2577.             THSettings.Instance.UpdateStatus = true;
  2578.         }
  2579.  
  2580.         #endregion
  2581.  
  2582.         #region SafeName
  2583.  
  2584.         private static string SafeName(WoWUnit unit)
  2585.         {
  2586.             //using (StyxWoW.Memory.AcquireFrame())
  2587.             {
  2588.                 if (unit == null || !unit.IsValid)
  2589.                 {
  2590.                     return "null or invalid";
  2591.                 }
  2592.                 if (unit == Me)
  2593.                 {
  2594.                     return "Myself";
  2595.                 }
  2596.                 if (unit.IsPlayer)
  2597.                 {
  2598.                     return unit.Class.ToString();
  2599.                 }
  2600.                 if (unit.IsPet)
  2601.                 {
  2602.                     return unit.CreatureType.ToString();
  2603.                 }
  2604.             }
  2605.             return unit.Name;
  2606.         }
  2607.  
  2608.         #endregion
  2609.  
  2610.         #region SpecialUnit
  2611.  
  2612.         //private static readonly HashSet<uint> SpecialUnit = new HashSet<uint>
  2613.         //    {
  2614.         //        60491, //Sha of Anger
  2615.         //        62346, //Galleon
  2616.         //        60410, //Elegon
  2617.         //        60776, //Empyreal Focus
  2618.         //        60793, //Celestial Protector
  2619.         //        60913, //Energy Charge
  2620.         //        60143, //garajal-the-spiritbinder
  2621.         //        60412, //Empyreal Focus
  2622.         //        63667, //garalon
  2623.         //    };
  2624.  
  2625.         #endregion
  2626.  
  2627.         #region UpdateCurrentMap
  2628.  
  2629.         //private static string CurrentMap;
  2630.  
  2631.         //private static void UpdateCurrentMapEvent(BotEvents.Player.MapChangedEventArgs args)
  2632.         //{
  2633.         //    THSettings.Instance.UpdateStatus = true;
  2634.         //}
  2635.  
  2636.         //private static void UpdateCurrentMap()
  2637.         //{
  2638.         //    if (InArena)
  2639.         //    {
  2640.         //        CurrentMap = "Arena";
  2641.         //    }
  2642.         //    else if (InBattleground && Me.IsFFAPvPFlagged)
  2643.         //    {
  2644.         //        CurrentMap = "Rated Battleground";
  2645.         //    }
  2646.         //    else if (InBattleground)
  2647.         //    {
  2648.         //        CurrentMap = "Battleground";
  2649.         //    }
  2650.         //    else if (InDungeon)
  2651.         //    {
  2652.         //        CurrentMap = "Dungeon";
  2653.         //    }
  2654.         //    else if (InRaid)
  2655.         //    {
  2656.         //        CurrentMap = "Raid";
  2657.         //    }
  2658.         //    else
  2659.         //    {
  2660.         //        CurrentMap = "World";
  2661.         //    }
  2662.  
  2663.         //    Logging.Write("----------------------------------");
  2664.         //    Logging.Write("CurrentMap: " + CurrentMap);
  2665.         //    Logging.Write("----------------------------------");
  2666.         //}
  2667.  
  2668.         #endregion
  2669.  
  2670.         #region UpdateEventHandler
  2671.  
  2672.         private static void UpdateEventHandler()
  2673.         {
  2674.             //Logging.Write(LogLevel.Diagnostic, "UpdateEventHandler");
  2675.  
  2676.             if (!IsUsingAFKBot &&
  2677.                 !CombatLogAttachedPvP)
  2678.             {
  2679.                 AttachCombatLogEventPvP();
  2680.                 //Logging.Write(LogLevel.Diagnostic, "AttachCombatLogEventPvP");
  2681.             }
  2682.  
  2683.             if (IsUsingAFKBot &&
  2684.                 CombatLogAttachedPvP)
  2685.             {
  2686.                 DetachCombatLogEventPvP();
  2687.                 //Logging.Write(LogLevel.Diagnostic, "DetachCombatLogEventPvP");
  2688.             }
  2689.  
  2690.             if (IsUsingAFKBot &&
  2691.                 !InArena &&
  2692.                 !InBattleground &&
  2693.                 !InDungeon &&
  2694.                 !InRaid &&
  2695.                 !EventHandlers.CombatLogAttached)
  2696.             {
  2697.                 EventHandlers.AttachCombatLogEvent();
  2698.                 //Logging.Write(LogLevel.Diagnostic, "AttachCombatLogEvent");
  2699.             }
  2700.  
  2701.             if ((!IsUsingAFKBot ||
  2702.                  InArena ||
  2703.                  InBattleground ||
  2704.                  InDungeon ||
  2705.                  InRaid) &&
  2706.                 EventHandlers.CombatLogAttached)
  2707.             {
  2708.                 EventHandlers.AttachCombatLogEvent();
  2709.                 //Logging.Write(LogLevel.Diagnostic, "AttachCombatLogEvent");
  2710.             }
  2711.  
  2712.             //if ((TreeRoot.Current.Name == "Tyrael" ||
  2713.             //     TreeRoot.Current.Name == "LazyRaider" ||
  2714.             //     TreeRoot.Current.Name == "Raid Bot" ||
  2715.             //     TreeRoot.Current.Name == "Combat Bot"))
  2716.             //{
  2717.             //    EventHandlers.DetachCombatLogEvent();
  2718.             //    Logging.Write(LogLevel.Diagnostic, "DetachCombatLogEvent");
  2719.             //}
  2720.  
  2721.             //else
  2722.             //{
  2723.             //    EventHandlers.AttachCombatLogEvent();
  2724.             //    Logging.Write(LogLevel.Diagnostic, "AttachCombatLogEvent");
  2725.             //}
  2726.         }
  2727.  
  2728.         #endregion
  2729.  
  2730.         #region UpdateGroupHealingMembers
  2731.  
  2732.         private static void UpdateGroupChangeEvent(object sender, LuaEventArgs args)
  2733.         {
  2734.             if (IGroupHealingOn())
  2735.             {
  2736.                 Logging.Write("Update Selective Group Healing on Group Member Change");
  2737.                 UpdateGroupHealingMembers();
  2738.             }
  2739.         }
  2740.  
  2741.         private static readonly List<WoWPlayer> GroupHealingMembers = new List<WoWPlayer>();
  2742.  
  2743.         private static void UpdateGroupHealingMembers()
  2744.         {
  2745.             //using (StyxWoW.Memory.AcquireFrame())
  2746.             {
  2747.                 GroupHealingMembers.Clear();
  2748.                 //Logging.Write("Debug " + GroupHealingMembers.Count() + " Members");
  2749.  
  2750.                 if (IGroupHealingOn())
  2751.                 {
  2752.                     foreach (var woWPartyMember in GroupMembers)
  2753.                     {
  2754.                         if (woWPartyMember.ToPlayer() != null)
  2755.                         {
  2756.                             if (THSettings.Instance.Group1 && woWPartyMember.GroupNumber == 0 ||
  2757.                                 THSettings.Instance.Group2 && woWPartyMember.GroupNumber == 1 ||
  2758.                                 THSettings.Instance.Group3 && woWPartyMember.GroupNumber == 2 ||
  2759.                                 THSettings.Instance.Group4 && woWPartyMember.GroupNumber == 3 ||
  2760.                                 THSettings.Instance.Group5 && woWPartyMember.GroupNumber == 4 ||
  2761.                                 THSettings.Instance.Group6 && woWPartyMember.GroupNumber == 5 ||
  2762.                                 THSettings.Instance.Group7 && woWPartyMember.GroupNumber == 6 ||
  2763.                                 THSettings.Instance.Group8 && woWPartyMember.GroupNumber == 7)
  2764.                             {
  2765.                                 Logging.Write("Add " + woWPartyMember.ToPlayer().Class + " in Group: " +
  2766.                                               (Convert.ToByte(woWPartyMember.GroupNumber) + 1) +
  2767.                                               " to Selective Group Healing");
  2768.                                 GroupHealingMembers.Add(woWPartyMember.ToPlayer());
  2769.                             }
  2770.                         }
  2771.                     }
  2772.  
  2773.                     if (GroupHealingMembers.Any())
  2774.                     {
  2775.                         Logging.Write("----------------------------------");
  2776.                         Logging.Write("You are assigned to Heal " + GroupHealingMembers.Count() + " Members");
  2777.                         Logging.Write("You will also heal your Target, your Focus and Yourself!");
  2778.                         Logging.Write("----------------------------------");
  2779.                     }
  2780.                 }
  2781.             }
  2782.         }
  2783.  
  2784.         #endregion
  2785.  
  2786.         #region UpdateMyLatency
  2787.  
  2788.         //private static DateTime MyLatencyLastupdate;
  2789.         private static double MyLatency;
  2790.  
  2791.         private static void UpdateMyLatency()
  2792.         {
  2793.             //MyLatency = 400;
  2794.             //return;
  2795.  
  2796.             MyLatency = (StyxWoW.WoWClient.Latency);
  2797.  
  2798.             //Use here because Lag Tolerance cap at 400
  2799.             //Logging.Write("----------------------------------");
  2800.             //Logging.Write("MyLatency: " + MyLatency);
  2801.             //Logging.Write("----------------------------------");
  2802.  
  2803.             if (MyLatency > 400)
  2804.             {
  2805.                 //Lag Tolerance cap at 400
  2806.                 MyLatency = 400;
  2807.             }
  2808.         }
  2809.  
  2810.         #endregion
  2811.  
  2812.         #region UpdateMyTalent
  2813.  
  2814.         //private static string _hasTalent = "";
  2815.  
  2816.         //private static void UpdateMyTalentEvent(object sender, LuaEventArgs args)
  2817.         //{
  2818.         //    UpdateMyTalent();
  2819.         //}
  2820.  
  2821.         //private static void UpdateMyTalent()
  2822.         //{
  2823.         //    _hasTalent = "";
  2824.         //    for (int i = 1; i <= 18; i++)
  2825.         //    {
  2826.         //        _hasTalent = _hasTalent +
  2827.         //                     Lua.GetReturnVal<String>(
  2828.         //                         string.Format(
  2829.         //                             "local t= select(5,GetTalentInfo({0})) if t == true then return '['..select(1,GetTalentInfo({0}))..'] ' end return nil",
  2830.         //                             i), 0);
  2831.         //    }
  2832.  
  2833.         //    Logging.Write("----------------------------------");
  2834.         //    Logging.Write("Talent:");
  2835.         //    Logging.Write(_hasTalent);
  2836.         //    Logging.Write("----------------------------------");
  2837.         //    _hasTalent = "";
  2838.         //}
  2839.  
  2840.         #endregion
  2841.  
  2842.         #region UpdateRaidPartyMembers
  2843.  
  2844.         private static IEnumerable<WoWPartyMember> GroupMembers
  2845.         {
  2846.             get { return !Me.GroupInfo.IsInRaid ? Me.GroupInfo.PartyMembers : Me.GroupInfo.RaidMembers; }
  2847.         }
  2848.  
  2849.         private static DateTime UpdateRaidPartyMembersLast;
  2850.  
  2851.         //private static Composite UpdateRaidPartyMembersComp()
  2852.         //{
  2853.         //    return new Decorator(
  2854.         //        ret =>
  2855.         //        UpdateRaidPartyMembersLast + TimeSpan.FromSeconds(60) < DateTime.Now &&
  2856.         //        !Me.Combat ||
  2857.         //        HasAuraArenaPreparation ||
  2858.         //        HasAuraPreparation,
  2859.         //        new Action(delegate
  2860.         //            {
  2861.         //                UpdateRaidPartyMembers();
  2862.         //                UpdateRaidPartyMembersLast = DateTime.Now;
  2863.         //                return RunStatus.Failure;
  2864.         //            })
  2865.         //        );
  2866.         //}
  2867.  
  2868.         //private static void UpdateRaidPartyMembersEvent(object sender, LuaEventArgs args)
  2869.         //{
  2870.         //    UpdateRaidPartyMembers();
  2871.         //}
  2872.  
  2873.         private static readonly List<WoWPlayer> RaidPartyMembers = new List<WoWPlayer>();
  2874.  
  2875.         //private static void UpdateRaidPartyMembers()
  2876.         //{
  2877.         //    EnemyListCache.Clear();
  2878.         //    RaidPartyMembers.Clear();
  2879.  
  2880.         //    foreach (var woWPartyMember in GroupMembers)
  2881.         //    {
  2882.         //        var Player = woWPartyMember.ToPlayer();
  2883.         //        if (Player == null || !Player.IsValid )
  2884.         //        {
  2885.         //            continue;
  2886.         //        }
  2887.         //        RaidPartyMembers.Add(woWPartyMember.ToPlayer());
  2888.  
  2889.         //        //if (woWPartyMember.ToPlayer() != null)
  2890.         //        //{
  2891.         //        //    //Logging.Write("Add " + woWPartyMember.ToPlayer().Class + " to RaidPartyMembers");
  2892.         //        //    RaidPartyMembers.Add(woWPartyMember.ToPlayer());
  2893.         //        //}
  2894.         //    }
  2895.  
  2896.         //    if (!RaidPartyMembers.Contains(Me))
  2897.         //    {
  2898.         //        RaidPartyMembers.Add(Me);
  2899.         //    }
  2900.         //}
  2901.  
  2902.         #endregion
  2903.  
  2904.         #region UseHealthStoneHP
  2905.  
  2906.         private static Composite UseHealthStoneHP()
  2907.         {
  2908.             //using (StyxWoW.Memory.AcquireFrame())
  2909.             {
  2910.                 return
  2911.                     new Decorator(
  2912.                         ret =>
  2913.                         THSettings.Instance.HealthStone &&
  2914.                         Me.Combat &&
  2915.                         HealWeightMe < THSettings.Instance.HealthStoneHP &&
  2916.                         Me.CurrentTarget != null &&
  2917.                         Me.CurrentTarget.HealthPercent > HealWeightMe,
  2918.                         new Action(delegate
  2919.                             {
  2920.                                 WoWItem hs = Me.BagItems.FirstOrDefault(o => o.Entry == 5512);
  2921.                                 //5512 HealthStoneHP
  2922.                                 if (hs != null && hs.CooldownTimeLeft.TotalMilliseconds <= MyLatency)
  2923.                                 {
  2924.                                     hs.Use();
  2925.                                     //Lua.DoString("RunMacroText(\"/s Used HealthStoneHP\")");
  2926.                                     Logging.Write("Use HealthStoneHP at " + HealWeightMe + "%");
  2927.                                 }
  2928.                                 return RunStatus.Failure;
  2929.                             })
  2930.                         );
  2931.             }
  2932.         }
  2933.  
  2934.         #endregion
  2935.  
  2936.         #region UpdateCooldown
  2937.  
  2938.         //private static DateTime _sacredShieldCooldown;
  2939.         //private static DateTime _judgmentCooldown;
  2940.         //private static DateTime _holyShockCooldown;
  2941.  
  2942.         //private static void UpdateCooldown(string spellName)
  2943.         //{
  2944.         //    //using (StyxWoW.Memory.AcquireFrame())
  2945.         //    {
  2946.         //        //switch (spellName)
  2947.         //        //{
  2948.         //        //        //case "Sacred Shield":
  2949.         //        //        //    _sacredShieldCooldown = DateTime.Now + SpellManager.Spells[spellName].CooldownTimeLeft;
  2950.         //        //        //    break;
  2951.         //        //        //case "Judgment":
  2952.         //        //        //    _judgmentCooldown = DateTime.Now + SpellManager.Spells[spellName].CooldownTimeLeft;
  2953.         //        //        //    break;
  2954.         //        //    case "Holy Shock":
  2955.         //        //        _holyShockCooldown = DateTime.Now + GetSpellCooldown(spellName);
  2956.         //        //        break;
  2957.         //        //}
  2958.         //    }
  2959.         //}
  2960.  
  2961.         #endregion
  2962.  
  2963.         #region UpdateMyNoGCDSpell
  2964.  
  2965.         //private static readonly HashSet<string> NoGCDSpells = new HashSet<string>();
  2966.  
  2967.         //private static void UpdateMyNoGCDSpell()
  2968.         //{
  2969.         //    //using (StyxWoW.Memory.AcquireFrame())
  2970.         //    {
  2971.         //        if (SpellManager.HasSpell("Arcane Torrent"))
  2972.         //        {
  2973.         //            NoGCDSpells.Add("Arcane Torrent");
  2974.         //        }
  2975.  
  2976.         //        if (SpellManager.HasSpell("Ardent Defender"))
  2977.         //        {
  2978.         //            NoGCDSpells.Add("Ardent Defender");
  2979.         //        }
  2980.  
  2981.         //        if (SpellManager.HasSpell("Avenging Wrath"))
  2982.         //        {
  2983.         //            NoGCDSpells.Add("Avenging Wrath");
  2984.         //        }
  2985.  
  2986.         //        if (HasGlyph.Contains("63218"))
  2987.         //        {
  2988.         //            NoGCDSpells.Add("Beacon of Light");
  2989.         //        }
  2990.  
  2991.         //        if (SpellManager.HasSpell("Devotion Aura"))
  2992.         //        {
  2993.         //            NoGCDSpells.Add("Devotion Aura");
  2994.         //        }
  2995.  
  2996.         //        if (SpellManager.HasSpell("Divine Favor"))
  2997.         //        {
  2998.         //            NoGCDSpells.Add("Divine Favor");
  2999.         //        }
  3000.  
  3001.         //        if (SpellManager.HasSpell("Divine Protection"))
  3002.         //        {
  3003.         //            NoGCDSpells.Add("Divine Protection");
  3004.         //        }
  3005.  
  3006.         //        if (SpellManager.HasSpell("Guardian of Ancient Kings"))
  3007.         //        {
  3008.         //            NoGCDSpells.Add("Guardian of Ancient Kings");
  3009.         //        }
  3010.  
  3011.         //        if (SpellManager.HasSpell("Holy Avenger"))
  3012.         //        {
  3013.         //            NoGCDSpells.Add("Holy Avenger");
  3014.         //        }
  3015.  
  3016.         //        if (SpellManager.HasSpell("Lay on Hands"))
  3017.         //        {
  3018.         //            NoGCDSpells.Add("Lay on Hands");
  3019.         //        }
  3020.  
  3021.         //        if (SpellManager.HasSpell("Rebuke"))
  3022.         //        {
  3023.         //            NoGCDSpells.Add("Rebuke");
  3024.         //        }
  3025.  
  3026.         //        if (SpellManager.HasSpell("Reckoning"))
  3027.         //        {
  3028.         //            NoGCDSpells.Add("Reckoning");
  3029.         //        }
  3030.  
  3031.  
  3032.         //        Logging.Write("----------------------------------");
  3033.         //        Logging.Write("Spells that don't use Global Cooldown:");
  3034.         //        foreach (string spell in NoGCDSpells)
  3035.         //        {
  3036.         //            Logging.Write(" -" + spell);
  3037.         //        }
  3038.         //        Logging.Write("----------------------------------");
  3039.         //    }
  3040.         //}
  3041.  
  3042.         #endregion
  3043.  
  3044.         #region UpdateMyGlyph
  3045.  
  3046.         private static void UpdateMyGlyphEvent(object sender, LuaEventArgs args)
  3047.         {
  3048.             UpdateMyGlyph();
  3049.         }
  3050.  
  3051.         //private static readonly HashSet<string> NoGCDSpells = new HashSet<string> { };
  3052.         private static string HasGlyph;
  3053.         private static string HasGlyphName;
  3054.  
  3055.         private static void UpdateMyGlyph()
  3056.         {
  3057.             HasGlyph = "";
  3058.             HasGlyphName = "";
  3059.             //using (StyxWoW.Memory.AcquireFrame())
  3060.             {
  3061.                 var glyphCount = Lua.GetReturnVal<int>("return GetNumGlyphSockets()", 0);
  3062.  
  3063.                 if (glyphCount != 0)
  3064.                 {
  3065.                     for (int i = 1; i <= glyphCount; i++)
  3066.                     {
  3067.                         string lua =
  3068.                             String.Format(
  3069.                                 "local enabled, glyphType, glyphTooltipIndex, glyphSpellID, icon = GetGlyphSocketInfo({0});if (enabled) then return glyphSpellID else return 0 end",
  3070.                                 i);
  3071.  
  3072.                         var glyphSpellId = Lua.GetReturnVal<int>(lua, 0);
  3073.  
  3074.                         try
  3075.                         {
  3076.                             if (glyphSpellId > 0)
  3077.                             {
  3078.                                 HasGlyphName = HasGlyphName + "[" + (WoWSpell.FromId(glyphSpellId)) + " - " +
  3079.                                                glyphSpellId +
  3080.                                                "] ";
  3081.                                 HasGlyph = HasGlyph + "[" + glyphSpellId + "] ";
  3082.                             }
  3083.                             else
  3084.                             {
  3085.                                 Logging.Write("Glyphdetection - No Glyph in slot " + i);
  3086.                                 //TreeRoot.Stop();
  3087.                             }
  3088.                         }
  3089.                         catch (Exception ex)
  3090.                         {
  3091.                             Logging.Write("We couldn't detect your Glyphs");
  3092.                             Logging.Write("Report this message to us: " + ex);
  3093.                             //TreeRoot.Stop();
  3094.                         }
  3095.                     }
  3096.                 }
  3097.  
  3098.                 Logging.Write("----------------------------------");
  3099.                 Logging.Write("Glyph:");
  3100.                 Logging.Write(HasGlyphName);
  3101.                 Logging.Write("----------------------------------");
  3102.             }
  3103.         }
  3104.  
  3105.         #endregion
  3106.  
  3107.         #region UpdateStatus
  3108.  
  3109.         internal static int UseSpecialization;
  3110.         private static bool IsUsingAFKBot;
  3111.         private static bool UseLightningShieldGCDCheck;
  3112.         private static ulong MeGuid;
  3113.         private static double MeMaxHealth;
  3114.  
  3115.         private void UpdateStatus()
  3116.         {
  3117.             if (THSettings.Instance.UpdateStatus)
  3118.             {
  3119.                 Logging.Write("----------------------------------");
  3120.                 Logging.Write("Building Rotation base on current Talents and Glyphs......");
  3121.                 Logging.Write("----------------------------------");
  3122.                 Logging.Write("");
  3123.  
  3124.                 if (!FriendListCache.ContainsKey(Me.Guid))
  3125.                 {
  3126.                     FriendListCacheAdd(Me, 86400);
  3127.                 }
  3128.  
  3129.                 UpdateEventHandler();
  3130.  
  3131.                 UpdateMyGlyph();
  3132.  
  3133.                 UpdateMyLatency();
  3134.  
  3135.                 UpdateGroupHealingMembers();
  3136.  
  3137.                 Logging.Write("----------------------------------");
  3138.                 Logging.Write("Building Rotation Completed");
  3139.                 Logging.Write("----------------------------------");
  3140.                 Logging.Write("");
  3141.  
  3142.                 Logging.Write("----------------------------------");
  3143.                 Logging.Write("Hold 1 second Control + " + IndexToKeys(THSettings.Instance.PauseKey) +
  3144.                               " To Toggle Pause Mode.");
  3145.                 Logging.Write("----------------------------------");
  3146.                 Logging.Write("");
  3147.  
  3148.                 if (THSettings.Instance.BurstKey > 9)
  3149.                 {
  3150.                     Logging.Write("----------------------------------");
  3151.                     Logging.Write("Hold 1 second Control + " +
  3152.                                   IndexToKeys(THSettings.Instance.BurstKey - 9) +
  3153.                                   " To Toggle Burst Mode");
  3154.                     Logging.Write("----------------------------------");
  3155.                     Logging.Write("");
  3156.                 }
  3157.  
  3158.                 if (SpellManager.HasSpell("Lightning Shield"))
  3159.                 {
  3160.                     Logging.Write("Use Lightning Shield as GCD Check");
  3161.                     UseLightningShieldGCDCheck = true;
  3162.                 }
  3163.                 else
  3164.                 {
  3165.                     Logging.Write("Use GCD Standard Check");
  3166.                     UseLightningShieldGCDCheck = false;
  3167.                 }
  3168.  
  3169.                 if (TreeRoot.Current.Name == "Questing" ||
  3170.                     TreeRoot.Current.Name == "[BETA] Grindbuddy" ||
  3171.                     TreeRoot.Current.Name == "ArcheologyBuddy" ||
  3172.                     TreeRoot.Current.Name == "Auto Angler" ||
  3173.                     TreeRoot.Current.Name == "Gatherbuddy2" ||
  3174.                     TreeRoot.Current.Name == "Grind Bot" ||
  3175.                     TreeRoot.Current.Name == "BGBuddy" ||
  3176.                     TreeRoot.Current.Name == "DungeonBuddy" ||
  3177.                     TreeRoot.Current.Name == "Mixed Mode")
  3178.                 {
  3179.                     IsUsingAFKBot = true;
  3180.                 }
  3181.                 else
  3182.                 {
  3183.                     IsUsingAFKBot = false;
  3184.                 }
  3185.  
  3186.                 if (Me.Specialization == WoWSpec.ShamanElemental)
  3187.                 {
  3188.                     UseSpecialization = 1;
  3189.                 }
  3190.                 else if (Me.Specialization == WoWSpec.ShamanRestoration)
  3191.                 {
  3192.                     UseSpecialization = 3;
  3193.                 }
  3194.                 else
  3195.                 {
  3196.                     UseSpecialization = 2;
  3197.                 }
  3198.  
  3199.                 MeGuid = Me.Guid;
  3200.                 MeMaxHealth = Me.MaxHealth;
  3201.  
  3202.                 THSettings.Instance.UpdateStatus = false;
  3203.             }
  3204.         }
  3205.  
  3206.         #endregion
  3207.  
  3208.         #region DebugTime
  3209.  
  3210.         private static Composite SWStart()
  3211.         {
  3212.             return new Action(delegate
  3213.                 {
  3214.                     sw.Reset();
  3215.                     sw.Start();
  3216.                     return RunStatus.Failure;
  3217.                 });
  3218.         }
  3219.  
  3220.         private static Composite SWStop(string FunctionName)
  3221.         {
  3222.             return new Action(delegate
  3223.                 {
  3224.                     sw.Stop();
  3225.                     Logging.Write(LogLevel.Diagnostic, "{0} ms - {1} ",
  3226.                                   Math.Round(sw.Elapsed.TotalMilliseconds, 5), FunctionName);
  3227.                     sw.Reset();
  3228.                     return RunStatus.Failure;
  3229.                 });
  3230.         }
  3231.  
  3232.         private static bool Eval(string Name, System.Func<bool> func)
  3233.         {
  3234.             sw.Reset();
  3235.             sw.Start();
  3236.             bool result = func();
  3237.             sw.Stop();
  3238.             Logging.Write(LogLevel.Diagnostic, "{0} ms - {1} , result is {2}",
  3239.                           Math.Round(sw.Elapsed.TotalMilliseconds, 5), Name,
  3240.                           result);
  3241.             return result;
  3242.         }
  3243.  
  3244.         private static int Eval(string Name, System.Func<int> func)
  3245.         {
  3246.             sw.Reset();
  3247.             sw.Start();
  3248.             int result = func();
  3249.             sw.Stop();
  3250.             Logging.Write(LogLevel.Diagnostic, "{0} ms - {1} , result is {2}",
  3251.                           Math.Round(sw.Elapsed.TotalMilliseconds, 5), Name,
  3252.                           result);
  3253.             return result;
  3254.         }
  3255.  
  3256.         #endregion
  3257.  
  3258.         #region Return Flag
  3259.  
  3260.         /// <summary>
  3261.         /// This code made by Maddogs. He's no longer playing WoW, we should thank him for the awesome idea
  3262.         /// </summary>
  3263.         /// <param name="e"></param>
  3264.         private static DateTime SearchFlagTime;
  3265.  
  3266.         private static void ChatFilter(Chat.ChatSimpleMessageEventArgs e)
  3267.         {
  3268.             if (!THSettings.Instance.FlagReturnorPickup ||
  3269.                 Battlegrounds.Current != BattlegroundType.WSG &&
  3270.                 Battlegrounds.Current != BattlegroundType.TP &&
  3271.                 Battlegrounds.Current != BattlegroundType.EotS)
  3272.             {
  3273.                 return;
  3274.             }
  3275.  
  3276.             if (e.Message.Contains("Flag was dropped by"))
  3277.             {
  3278.                 //Logging.Write("Flag was dropped! Start Searching");
  3279.                 SearchFlagTime = DateTime.Now + TimeSpan.FromSeconds(10);
  3280.                 return;
  3281.             }
  3282.  
  3283.             if (SearchFlagTime > DateTime.Now &&
  3284.                 e.Message.Contains("Flag was returned to its base by"))
  3285.             {
  3286.                 //Logging.Write("Flag was returned to its base! Stop Searching");
  3287.                 SearchFlagTime = DateTime.Now - TimeSpan.FromSeconds(10);
  3288.                 return;
  3289.             }
  3290.         }
  3291.  
  3292.         private static void ReturningFlag()
  3293.         {
  3294.             if (SearchFlagTime < DateTime.Now)
  3295.             {
  3296.                 return;
  3297.             }
  3298.  
  3299.             //Logging.Write("Start Searching for Flag!");
  3300.  
  3301.             //Alliance Flag = 179830
  3302.             //Horde Flag = 179831
  3303.             //Horde Flag - Entry: 179786
  3304.             //var FlagTest = ObjectManager.WoWDynamicObject<WoWGameObject>().FirstOrDefault(
  3305.             //    obj =>
  3306.             //    obj.Name.Contains("Flag"));
  3307.  
  3308.             //if (FlagTest != null)
  3309.             //{
  3310.             //    Logging.Write("Name: {0} - Entry: {1} - Interact Range: {2} - Distance: {3}", FlagTest.Name,
  3311.             //                  FlagTest.Entry, FlagTest.InteractRange, FlagTest.Distance);
  3312.             //}
  3313.  
  3314.             // Find our Flag
  3315.             var Flag = ObjectManager.GetObjectsOfType<WoWGameObject>().FirstOrDefault(
  3316.                 obj =>
  3317.                 (obj.Name == "Alliance Flag" ||
  3318.                  obj.Name == "Horde Flag") &&
  3319.                 obj.Distance <= 15);
  3320.  
  3321.  
  3322.             if (Flag == null) return;
  3323.             //Logging.Write("Flag Found, Trying to Interact!");
  3324.             if (!IsOverrideModeOn)
  3325.             {
  3326.                 Navigator.MoveTo(Flag.Location);
  3327.             }
  3328.             Me.SetFacing(Flag.Location);
  3329.             Flag.Interact();
  3330.             Logging.Write("Trying to Return/Pick Up Dropped flag!");
  3331.         }
  3332.  
  3333.         #endregion
  3334.     }
  3335. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement