Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.05 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.                     else if (tar.Guid == tank.Guid && (!tar.ActiveAuras.ContainsKey("Lifebloom") || tar.ActiveAuras["lifebloom"].StackCount < 3 || tar.ActiveAuras["lifebloom"].TimeLeft.Milliseconds <= 1500 ) && Me.CanCast("LifeBloom"))
  184.                     {
  185.                         if(tar.HealthPercent < 50)
  186.  
  187.                                 {
  188.  
  189.                                     Return;
  190.  
  191.                                 }
  192.  
  193.                         else if(tar.HealthPercent > 50)
  194.                         s = "Lifebloom";
  195.                     }
  196.                     if (hp < 90 && !isAuraActive("Rejuvenation", tar))
  197.                     {
  198.                         s = "Rejuvenation";
  199.                     }
  200.                     else if (hp < 80 && !isAuraActive("Wild Growth", tar))
  201.                     {
  202.                         s = "Wild Growth";
  203.                     }
  204.                     else if (hp < 65 && isAuraActive("Rejuvenation", tar))
  205.                     {
  206.                         s = "Swiftmend";
  207.                     }
  208.                     else if (hp < 40)
  209.                     {
  210.                         s = "Nature's Swiftness";
  211.                     }
  212.  
  213.                     else if (Me.IsMoving)
  214.                     {
  215.                         Logging.Write("stopmove");
  216.                         WoWMovement.MoveStop();
  217.                         return true;
  218.                     }
  219.                     else if (isAuraActive("Nature's Swiftness"))
  220.                     {
  221.                         s = "Healing Touch";
  222.                         needCast = true;
  223.                     }
  224.                     else if (hp < 75 && !isAuraActive("Regrowth", tar))
  225.                     {
  226.                         s = "Regrowth";
  227.                         needCast = true;
  228.                     }
  229.  
  230.                     if (s != null && CC(s, tar))
  231.                     {
  232.                         if (!C(s, tar))
  233.                         {
  234.                             Logging.Write("castfail move to " + tar);
  235.                         }
  236.                         if (!needCast)
  237.                         {
  238.                             MoveTo(tar);
  239.                         }
  240.                         return true;
  241.                     }
  242.                     else
  243.                     {
  244.                         MoveTo(tar);
  245.                         return false;
  246.                     }
  247.                 }
  248.             }
  249.             else
  250.             {
  251.                 return false;
  252.             }
  253.         }
  254.  
  255.         private bool CC(string spell, WoWUnit target)
  256.         {
  257.             return SpellManager.CanCast(spell, target);
  258.         }
  259.  
  260.         private bool CC(string spell)
  261.         {
  262.             return SpellManager.CanCast(spell);
  263.         }
  264.  
  265.         private void ChainSpells(params string[] spells)
  266.         {
  267.             string macro = "";
  268.             foreach (string s in spells)
  269.             {
  270.                 macro += "CastSpellByName(\"" + s + "\", true);";
  271.             }
  272.             Lua.DoString(macro);
  273.         }
  274.  
  275.         private bool C(string spell, WoWUnit target)
  276.         {
  277.             if (SpellManager.Cast(spell, target))
  278.             {
  279.                 Logging.Write("cast " + spell + " " + target);
  280.                 lastCast = target;
  281.                 return true;
  282.             }
  283.             else
  284.             {
  285.                 return false;
  286.             }
  287.         }
  288.  
  289.         private bool C(string spell)
  290.         {
  291.             Logging.Write("selfcast " + spell);
  292.             lastCast = null;
  293.             return SpellManager.Cast(spell);
  294.         }
  295.  
  296.  
  297.         private bool Cleansing()
  298.         {
  299.             WoWPlayer p = GetCleanseTarget();
  300.             if (p != null)
  301.             {
  302.                 if (p.Distance > 40 || !p.InLineOfSight)
  303.                 {
  304.                     MoveTo(p);
  305.                     return true;
  306.                 }
  307.                 else if (CC("Remove Corruption", p))
  308.                 {
  309.                     C("Remove Corruption", p);
  310.                     return true;
  311.                 }
  312.                 else
  313.                 {
  314.                     Logging.Write("no Remove Corruption " + p);
  315.                     return false;
  316.                 }
  317.             }
  318.             else
  319.             {
  320.                 return false;
  321.             }
  322.         }
  323.  
  324.         private WoWPlayer GetCleanseTarget()
  325.         {
  326.             return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(true, true)
  327.                     orderby unit.HealthPercent ascending
  328.                     where !unit.Dead
  329.                     where !unit.IsGhost
  330.                     where unit.Distance < 80
  331.                     where NeedsCleanse(unit)
  332.                     select unit).FirstOrDefault();
  333.         }
  334.  
  335.         private bool NeedsCleanse(WoWPlayer p)
  336.         {
  337.             foreach (WoWAura a in p.ActiveAuras.Values)
  338.             {
  339.                 if (a.IsHarmful && Me.ManaPercent > 80)
  340.                 {
  341.                     WoWDispelType t = a.Spell.DispelType;
  342.                     if (t == WoWDispelType.Curse || t == WoWDispelType.Magic || t == WoWDispelType.Poison)
  343.                     {
  344.                         return true;
  345.                     }
  346.                 }
  347.             }
  348.             return false;
  349.         }
  350.  
  351.         private WoWPlayer GetHealTarget()
  352.         {
  353.             return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(true, true)
  354.                     orderby unit.HealthPercent ascending
  355.                     where !unit.Dead
  356.                     where !unit.IsGhost
  357.                     where unit.IsPet
  358.                     where unit.Distance < 80
  359.                     where unit.HealthPercent < 100
  360.                     select unit).FirstOrDefault();
  361.  
  362.         }
  363.  
  364.         private IEnumerable<WoWPlayer> GetResurrectTargets()
  365.         {
  366.             return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(false, false)
  367.                     orderby unit.Distance ascending
  368.                     where unit.Dead
  369.                     where unit.IsInMyPartyOrRaid
  370.                     where !unit.IsGhost
  371.                     where unit.Distance < 100
  372.                     select unit);
  373.         }
  374.  
  375.         private bool Resurrecting()
  376.         {
  377.             foreach (WoWPlayer p in GetResurrectTargets())
  378.             {
  379.                 if (Blacklist.Contains(p.Guid, true))
  380.                 {
  381.                     continue;
  382.                 }
  383.                 else
  384.                 {
  385.                     if (p.Distance > 40 || !p.InLineOfSight)
  386.                     {
  387.                         Logging.Write("moving to res " + p);
  388.                         MoveTo(p);
  389.                         return true;
  390.                     }
  391.                     else if (CC("Revive", p) && C("Revive", p))
  392.                     {
  393.                         Logging.Write("added " + p + " to res blacklist for 15s");
  394.                         Blacklist.Add(p, new TimeSpan(0, 0, 15));
  395.                         return true;
  396.                     }
  397.                     else
  398.                     {
  399.                         return false;
  400.                     }
  401.                 }
  402.             }
  403.             return false;
  404.         }
  405.  
  406.         private bool Buff()
  407.         {
  408.             if (Resurrecting())
  409.             {
  410.                 return true;
  411.             }
  412.             if (!isAuraActive("Mark of the Wild"))
  413.             {
  414.                 C("Mark of the Wild");
  415.                 return true;
  416.             }
  417.             foreach (WoWPlayer p in Me.PartyMembers)
  418.             {
  419.                 if (p.Distance > 40 || p.Dead || p.IsGhost)
  420.                     continue;
  421.                 else if (!isAuraActive("Blessing of Kings", p) && !isAuraActive("Mark of the Wild", p))
  422.                 {
  423.                     C("Mark of the Wild", p);
  424.                     return true;
  425.                 }
  426.             }
  427.             return false;
  428.         }
  429.  
  430.         private bool isAuraActive(string name)
  431.         {
  432.             return isAuraActive(name, Me);
  433.         }
  434.  
  435.         private bool isAuraActive(string name, WoWUnit u)
  436.         {
  437.             return u.ActiveAuras.ContainsKey(name);
  438.         }
  439.  
  440.         public override sealed string Name { get { return "Druidhealz"; } }
  441.  
  442.         public override WoWClass Class { get { return WoWClass.Druid; } }
  443.  
  444.         private static LocalPlayer Me { get { return ObjectManager.Me; } }
  445.  
  446.            public override bool NeedRest
  447.         {
  448.             get
  449.             {
  450.  
  451.                 if (Me.ManaPercent < 30 &&
  452.                     !Me.Auras.ContainsKey("Drink")) //To prevent food spam.
  453.                 {
  454.                     Logging.Write("Need Drink");
  455.                     return true;
  456.                 }
  457.  
  458.                 return false;
  459.             }
  460.         }
  461.  
  462.         public override void Rest()
  463.         {
  464.             // this ought never get run over level 3
  465.             if (Me.ManaPercent < 50)
  466.             {
  467.                 Styx.Logic.Common.Rest.Feed(); //these arent needed.
  468.             }
  469.  
  470.         }
  471.  
  472.         public override bool NeedPullBuffs { get { Pulse(); return false; } }
  473.  
  474.         public override bool NeedCombatBuffs { get { Pulse(); return false; } }
  475.  
  476.         public override bool NeedPreCombatBuffs { get { Pulse(); return false; } }
  477.  
  478.     }
  479. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement