Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Styx.Combat.CombatRoutine;
  6. using Styx.WoWInternals.WoWObjects;
  7. using Styx.WoWInternals;
  8. using Styx.Logic.Combat;
  9. using Styx.Helpers;
  10. using Styx.Logic.Pathing;
  11. using Styx;
  12. using Styx.Logic;
  13.  
  14. namespace Druidhealz
  15. {
  16.     class Druidhealz : CombatRoutine
  17.     {
  18.         private WoWUnit lastCast;
  19.         private WoWUnit tank;
  20.         private Random rng;
  21.  
  22.         public override void Pulse()
  23.         {
  24.             if (Me != null && Me.IsValid && Me.IsAlive && Me.IsInInstance)
  25.             {
  26.                 tank = GetTank();
  27.                 if (tank == null)
  28.                 {
  29.                     tank = Me;
  30.                 }
  31.                 Combat();
  32.             }
  33.         }
  34.  
  35.         public override void Combat()
  36.         {
  37.             if (StyxWoW.GlobalCooldown)
  38.                 return;
  39.             else if (CancelHeal())
  40.                 return;
  41.             else if (Self())
  42.                 return;
  43.             else if (Healing())
  44.                 return;
  45.             else if (Cleansing())
  46.                 return;
  47.             else if (Swarm())
  48.                 return;
  49.             else if (Buff())
  50.                 return;
  51.         }
  52.  
  53.         private bool Swarm()
  54.         {
  55.             //if (!isAuraActive("Judgements of the Pure"))
  56.             //{
  57.             WoWUnit u = (from unit in ObjectManager.GetObjectsOfType<WoWUnit>(false, false)
  58.                          where unit.IsHostile
  59.                          where !unit.Dead
  60.                          where unit.CurrentTargetGuid == tank.Guid
  61.                          where unit.Distance < 40
  62.                          where unit.InLineOfSight
  63.                          select unit
  64.                         ).FirstOrDefault();
  65.             if (u != null && (!Me.Combat) && CC("Insect Swarm", u))
  66.             {
  67.                 C("Insect Swarm", u);
  68.                 return true;
  69.             }
  70.             //}
  71.             return false;
  72.         }
  73.  
  74.         private bool MoveTo(WoWUnit u)
  75.         {
  76.             if (!Me.IsMoving && u != null && u.Distance > 20)
  77.             {
  78.                 Navigator.MoveTo(NextTo(u));
  79.                 return true;
  80.             }
  81.             else
  82.             {
  83.                 return false;
  84.             }
  85.         }
  86.  
  87.         private WoWPoint NextTo(WoWUnit u)
  88.         {
  89.             if (rng == null)
  90.             {
  91.                 rng = new Random();
  92.             }
  93.             return WoWMathHelper.CalculatePointAtSide(u.Location, u.Rotation, rng.Next(10), rng.Next(2) == 1);
  94.         }
  95.  
  96.         private bool CancelHeal()
  97.         {
  98.             //Logging.Write("in CancelHeal");
  99.             if (Me.IsCasting && (lastCast != null && !lastCast.Dead && lastCast.HealthPercent >= 85))
  100.             {
  101.                 Logging.Write("Cancelling cast " + lastCast);
  102.                 lastCast = null;
  103.                 SpellManager.StopCasting();
  104.                 return true;
  105.             }
  106.             else if (Me.IsCasting)
  107.             {
  108.                 return true;
  109.             }
  110.             else
  111.             {
  112.                 return false;
  113.             }
  114.         }
  115.  
  116.         private WoWPlayer GetTank()
  117.         {
  118.             foreach (WoWPlayer p in Me.PartyMembers)
  119.             {
  120.                 if (IsTank(p))
  121.                 {
  122.                     return p;
  123.                 }
  124.             }
  125.             return null;
  126.         }
  127.  
  128.         private string DeUnicodify(string s)
  129.         {
  130.  
  131.             StringBuilder sb = new StringBuilder();
  132.             byte[] bytes = Encoding.UTF8.GetBytes(s);
  133.             foreach (byte b in bytes)
  134.             {
  135.                 if (b != 0)
  136.                     sb.Append("\\" + b);
  137.             }
  138.             return sb.ToString();
  139.         }
  140.  
  141.         private bool IsTank(WoWPlayer p)
  142.         {
  143.             return Lua.GetReturnValues("return UnitGroupRolesAssigned('" + DeUnicodify(p.Name) + "')").First() == "TANK";
  144.         }
  145.  
  146.         private bool Self()
  147.         {
  148.             if (Me.HealthPercent < 80 && CC("Barkskin"))
  149.             {
  150.                 C("Barksin");
  151.                 return true;
  152.             }
  153.             else if (Me.ManaPercent <= 50 && CC("Innervate"))
  154.             {
  155.                 C("Innervate");
  156.                 return true;
  157.             }
  158.             else
  159.             {
  160.                 return false;
  161.             }
  162.         }
  163.  
  164.         private bool Healing()
  165.         {
  166.             //Logging.Write("in Healing");
  167.             WoWPlayer tar = GetHealTarget();
  168.             if (tar != null)
  169.             {
  170.                 if (tar.Distance > 40 || !tar.InLineOfSight)
  171.                 {
  172.                     Logging.Write("moving to " + tar);
  173.                     MoveTo(tar);
  174.                     return true;
  175.                 }
  176.                 else
  177.                 {
  178.                     String s = null;
  179.                     bool needCast = false;
  180.                     double hp = tar.HealthPercent;
  181.  
  182.              
  183.                     if (tar.Guid == tank.Guid && (!tar.ActiveAuras.ContainsKey("Lifebloom") || tar.ActiveAuras["lifebloom"].StackCount < 3 || tar.ActiveAuras["lifebloom"].TimeLeft.Milliseconds <= 1500 ))
  184.                     {
  185.                         if(tar.HealthPercent < 50)
  186.                         {
  187.                             continue;
  188.                         }
  189.                         else if(tar.HealthPercent > 50)
  190.                         }
  191.                         s = "Lifebloom";
  192.                         {
  193.                     }
  194.                     else if (hp < 90 && !isAuraActive("Rejuvenation", tar))
  195.                     {
  196.                         s = "Rejuvenation";
  197.                     }
  198.                     else if (hp < 80 && !isAuraActive("Wild Growth", tar))
  199.                     {
  200.                         s = "Wild Growth";
  201.                     }
  202.                     else if (hp < 65 && isAuraActive("Rejuvenation", tar))
  203.                     {
  204.                         s = "Swiftmend";
  205.                     }
  206.                     else if (hp < 40)
  207.                     {
  208.                         s = "Nature's Swiftness";
  209.                     }
  210.  
  211.                     else if (Me.IsMoving)
  212.                     {
  213.                         Logging.Write("stopmove");
  214.                         WoWMovement.MoveStop();
  215.                         return true;
  216.                     }
  217.                     else if (isAuraActive("Nature's Swiftness"))
  218.                     {
  219.                         s = "Healing Touch";
  220.                         needCast = true;
  221.                     }
  222.                     else if (hp < 75 && !isAuraActive("Regrowth", tar))
  223.                     {
  224.                         s = "Regrowth";
  225.                         needCast = true;
  226.                     }
  227.  
  228.                     if (s != null && CC(s, tar))
  229.                     {
  230.                         if (!C(s, tar))
  231.                         {
  232.                             Logging.Write("castfail move to " + tar);
  233.                         }
  234.                         if (!needCast)
  235.                         {
  236.                             MoveTo(tar);
  237.                         }
  238.                         return true;
  239.                     }
  240.                     else
  241.                     {
  242.                         MoveTo(tar);
  243.                         return false;
  244.                     }
  245.                 }
  246.             }
  247.             else
  248.             {
  249.                 return false;
  250.             }
  251.         }
  252.  
  253.         private bool CC(string spell, WoWUnit target)
  254.         {
  255.             return SpellManager.CanCast(spell, target);
  256.         }
  257.  
  258.         private bool CC(string spell)
  259.         {
  260.             return SpellManager.CanCast(spell);
  261.         }
  262.  
  263.         private void ChainSpells(params string[] spells)
  264.         {
  265.             string macro = "";
  266.             foreach (string s in spells)
  267.             {
  268.                 macro += "CastSpellByName(\"" + s + "\", true);";
  269.             }
  270.             Lua.DoString(macro);
  271.         }
  272.  
  273.         private bool C(string spell, WoWUnit target)
  274.         {
  275.             if (SpellManager.Cast(spell, target))
  276.             {
  277.                 Logging.Write("cast " + spell + " " + target);
  278.                 lastCast = target;
  279.                 return true;
  280.             }
  281.             else
  282.             {
  283.                 return false;
  284.             }
  285.         }
  286.  
  287.         private bool C(string spell)
  288.         {
  289.             Logging.Write("selfcast " + spell);
  290.             lastCast = null;
  291.             return SpellManager.Cast(spell);
  292.         }
  293.  
  294.  
  295.         private bool Cleansing()
  296.         {
  297.             WoWPlayer p = GetCleanseTarget();
  298.             if (p != null)
  299.             {
  300.                 if (p.Distance > 40 || !p.InLineOfSight)
  301.                 {
  302.                     MoveTo(p);
  303.                     return true;
  304.                 }
  305.                 else if (CC("Remove Corruption", p))
  306.                 {
  307.                     C("Remove Corruption", p);
  308.                     return true;
  309.                 }
  310.                 else
  311.                 {
  312.                     Logging.Write("no Remove Corruption " + p);
  313.                     return false;
  314.                 }
  315.             }
  316.             else
  317.             {
  318.                 return false;
  319.             }
  320.         }
  321.  
  322.         private WoWPlayer GetCleanseTarget()
  323.         {
  324.             return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(true, true)
  325.                     orderby unit.HealthPercent ascending
  326.                     where !unit.Dead
  327.                     where !unit.IsGhost
  328.                     where unit.Distance < 80
  329.                     where NeedsCleanse(unit)
  330.                     select unit).FirstOrDefault();
  331.         }
  332.  
  333.         private bool NeedsCleanse(WoWPlayer p)
  334.         {
  335.             foreach (WoWAura a in p.ActiveAuras.Values)
  336.             {
  337.                 if (a.IsHarmful && Me.ManaPercent > 80)
  338.                 {
  339.                     WoWDispelType t = a.Spell.DispelType;
  340.                     if (t == WoWDispelType.Curse || t == WoWDispelType.Magic || t == WoWDispelType.Poison)
  341.                     {
  342.                         return true;
  343.                     }
  344.                 }
  345.             }
  346.             return false;
  347.         }
  348.  
  349.         private WoWPlayer GetHealTarget()
  350.         {
  351.             return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(true, true)
  352.                     orderby unit.HealthPercent ascending
  353.                     where !unit.Dead
  354.                     where !unit.IsGhost
  355.                     where unit.IsPet
  356.                     where unit.Distance < 80
  357.                     where unit.HealthPercent < 100
  358.                     select unit).FirstOrDefault();
  359.  
  360.         }
  361.  
  362.         private IEnumerable<WoWPlayer> GetResurrectTargets()
  363.         {
  364.             return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(false, false)
  365.                     orderby unit.Distance ascending
  366.                     where unit.Dead
  367.                     where unit.IsInMyPartyOrRaid
  368.                     where !unit.IsGhost
  369.                     where unit.Distance < 100
  370.                     select unit);
  371.         }
  372.  
  373.         private bool Resurrecting()
  374.         {
  375.             foreach (WoWPlayer p in GetResurrectTargets())
  376.             {
  377.                 if (Blacklist.Contains(p.Guid, true))
  378.                 {
  379.                     continue;
  380.                 }
  381.                 else
  382.                 {
  383.                     if (p.Distance > 40 || !p.InLineOfSight)
  384.                     {
  385.                         Logging.Write("moving to res " + p);
  386.                         MoveTo(p);
  387.                         return true;
  388.                     }
  389.                     else if (CC("Revive", p) && C("Revive", p))
  390.                     {
  391.                         Logging.Write("added " + p + " to res blacklist for 15s");
  392.                         Blacklist.Add(p, new TimeSpan(0, 0, 15));
  393.                         return true;
  394.                     }
  395.                     else
  396.                     {
  397.                         return false;
  398.                     }
  399.                 }
  400.             }
  401.             return false;
  402.         }
  403.  
  404.         private bool Buff()
  405.         {
  406.             if (Resurrecting())
  407.             {
  408.                 return true;
  409.             }
  410.             if (!isAuraActive("Mark of the Wild"))
  411.             {
  412.                 C("Mark of the Wild");
  413.                 return true;
  414.             }
  415.             foreach (WoWPlayer p in Me.PartyMembers)
  416.             {
  417.                 if (p.Distance > 40 || p.Dead || p.IsGhost)
  418.                     continue;
  419.                 else if (!isAuraActive("Blessing of Kings", p) && !isAuraActive("Mark of the Wild", p))
  420.                 {
  421.                     C("Mark of the Wild", p);
  422.                     return true;
  423.                 }
  424.             }
  425.             return false;
  426.         }
  427.  
  428.         private bool isAuraActive(string name)
  429.         {
  430.             return isAuraActive(name, Me);
  431.         }
  432.  
  433.         private bool isAuraActive(string name, WoWUnit u)
  434.         {
  435.             return u.ActiveAuras.ContainsKey(name);
  436.         }
  437.  
  438.         public override sealed string Name { get { return "Druidhealz"; } }
  439.  
  440.         public override WoWClass Class { get { return WoWClass.Druid; } }
  441.  
  442.         private static LocalPlayer Me { get { return ObjectManager.Me; } }
  443.  
  444.            public override bool NeedRest
  445.         {
  446.             get
  447.             {
  448.  
  449.                 if (Me.ManaPercent < 30 &&
  450.                     !Me.Auras.ContainsKey("Drink")) //To prevent food spam.
  451.                 {
  452.                     Logging.Write("Need Drink");
  453.                     return true;
  454.                 }
  455.  
  456.                 return false;
  457.             }
  458.         }
  459.  
  460.         public override void Rest()
  461.         {
  462.             // this ought never get run over level 3
  463.             if (Me.ManaPercent < 50)
  464.             {
  465.                 Styx.Logic.Common.Rest.Feed(); //these arent needed.
  466.             }
  467.  
  468.         }
  469.  
  470.         public override bool NeedPullBuffs { get { Pulse(); return false; } }
  471.  
  472.         public override bool NeedCombatBuffs { get { Pulse(); return false; } }
  473.  
  474.         public override bool NeedPreCombatBuffs { get { Pulse(); return false; } }
  475.  
  476.     }
  477. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement