Advertisement
Guest User

Untitled

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