Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Styx.Combat.CombatRoutine;
- using Styx.WoWInternals.WoWObjects;
- using Styx.WoWInternals;
- using Styx.Logic.BehaviorTree;
- using Styx.Logic.Combat;
- using Styx.Helpers;
- using Styx.Logic.Pathing;
- using Styx;
- using Styx.Logic;
- using System.Threading;
- namespace Druidhealz
- {
- class Druidhealz : CombatRoutine
- {
- private WoWUnit lastCast;
- private Random rng;
- private static Thread _HealPulse;
- public override void Combat()
- {
- if (StyxWoW.GlobalCooldown)
- return;
- else if (CancelHeal())
- return;
- else if (Self())
- return;
- else if (Healing())
- return;
- else if (Cleansing())
- return;
- }
- public bool Init = false;
- public override void Pulse()
- {
- if (Me.IsValid)
- {
- if (Init == false)
- {
- _HealPulse = new Thread(HealPulse) { IsBackground = true, Name = "HealBots" };
- _HealPulse.Start();
- Init = true;
- }
- }
- }
- private static void HealPulse()
- {
- while (true)
- {
- if (Me.IsAlive && TreeRoot.IsRunning && Me.IsInInstance && !Me.Combat)
- {
- RoutineManager.Current.Combat();
- }
- }
- }
- private bool MoveTo(WoWUnit u)
- {
- if (!Me.IsMoving && u != null && u.Distance > 10)
- {
- Navigator.MoveTo(NextTo(u));
- return true;
- }
- else
- {
- return false;
- }
- }
- private WoWPoint NextTo(WoWUnit u)
- {
- if (rng == null)
- {
- rng = new Random();
- }
- return WoWMathHelper.CalculatePointAtSide(u.Location, u.Rotation, rng.Next(10), rng.Next(2) == 1);
- }
- private bool CancelHeal()
- {
- //Logging.Write("in CancelHeal");
- if (Me.IsCasting && (lastCast != null && !lastCast.Dead && lastCast.HealthPercent >= 85))
- {
- Logging.Write("Cancelling cast " + lastCast);
- lastCast = null;
- SpellManager.StopCasting();
- return true;
- }
- else if (Me.IsCasting)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private WoWPlayer GetTank()
- {
- foreach (WoWPlayer p in Me.PartyMembers)
- {
- if (IsTank(p))
- {
- return p;
- }
- }
- return null;
- }
- private string DeUnicodify(string s)
- {
- StringBuilder sb = new StringBuilder();
- byte[] bytes = Encoding.UTF8.GetBytes(s);
- foreach (byte b in bytes)
- {
- if (b != 0)
- sb.Append("\\" + b);
- }
- return sb.ToString();
- }
- private bool IsTank(WoWPlayer p)
- {
- return Lua.GetReturnValues("return UnitGroupRolesAssigned('" + DeUnicodify(p.Name) + "')").First() == "TANK";
- }
- private bool Self()
- {
- if (Me.ManaPercent <= 30 && CC("Innervate"))
- {
- C("Innervate");
- return true;
- }
- else
- {
- return false;
- }
- }
- private bool Healing()
- {
- //Logging.Write("in Healing");
- WoWPlayer tar = GetHealTarget();
- if (tar != null)
- {
- if (tar.Distance > 40 || !tar.InLineOfSight)
- {
- Logging.Write("moving to " + tar);
- Navigator.MoveTo(tar.Location);
- return true;
- }
- else
- {
- String s = null;
- bool needCast = false;
- double hp = tar.HealthPercent;
- if (hp < 95 && !isAuraActive("Rejuvenation", tar))
- {
- s = "Rejuvenation";
- needCast = false;
- }
- else if (hp < 80 && !isAuraActive("Wild Growth", tar))
- {
- s = "Wild Growth";
- needCast = false;
- }
- else if (hp < 70 && isAuraActive("Rejuvenation", tar))
- {
- s = "Swiftmend";
- needCast = false;
- }
- else if (hp < 40)
- {
- s = "Nature's Swiftness";
- needCast = false;
- }
- else if (Me.IsMoving)
- {
- Logging.Write("stopmove");
- WoWMovement.MoveStop();
- return true;
- }
- else if (hp < 65 && !isAuraActive("Regrowth", tar))
- {
- s = "Regrowth";
- needCast = true;
- }
- else if (hp < 39)
- {
- s = "Healing Touch";
- needCast = true;
- }
- if (s != null && CC(s, tar))
- {
- if (!C(s, tar))
- {
- Logging.Write("castfail move to " + tar);
- }
- if (!needCast)
- {
- MoveTo(tar);
- }
- return true;
- }
- else
- {
- MoveTo(tar);
- return false;
- }
- }
- }
- else
- {
- return false;
- }
- }
- private bool CC(string spell, WoWUnit target)
- {
- return SpellManager.CanCast(spell, target);
- }
- private bool CC(string spell)
- {
- return SpellManager.CanCast(spell);
- }
- private void ChainSpells(params string[] spells)
- {
- string macro = "";
- foreach (string s in spells)
- {
- macro += "CastSpellByName(\"" + s + "\", true);";
- }
- Lua.DoString(macro);
- }
- private bool C(string spell, WoWUnit target)
- {
- if (SpellManager.Cast(spell, target))
- {
- Logging.Write("cast " + spell + " " + target);
- lastCast = target;
- return true;
- }
- else
- {
- return false;
- }
- }
- private bool C(string spell)
- {
- Logging.Write("selfcast " + spell);
- lastCast = null;
- return SpellManager.Cast(spell);
- }
- private bool Cleansing()
- {
- //Logging.Write("in Cleansing");
- WoWPlayer p = GetCleanseTarget();
- if (p != null)
- {
- if (p.Distance > 40 || !p.InLineOfSight)
- {
- Navigator.MoveTo(p.Location);
- return true;
- }
- else if (CC("Remove Corruption", p))
- {
- C("Remove Corruption", p);
- return true;
- }
- else
- {
- Logging.Write("no Cleanse " + p);
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- private WoWPlayer GetCleanseTarget()
- {
- return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(true, true)
- orderby unit.HealthPercent ascending
- where !unit.Dead
- where !unit.IsGhost
- where unit.Distance < 80
- where NeedsCleanse(unit)
- select unit).FirstOrDefault();
- }
- private bool NeedsCleanse(WoWPlayer p)
- {
- foreach (WoWAura a in p.ActiveAuras.Values)
- {
- if (a.IsHarmful)
- {
- WoWDispelType t = a.Spell.DispelType;
- if (t == WoWDispelType.Curse || t == WoWDispelType.Poison)
- {
- return true;
- }
- }
- }
- return false;
- }
- private WoWPlayer GetHealTarget()
- {
- return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(true, true)
- orderby unit.HealthPercent ascending
- where !unit.Dead
- where !unit.IsGhost
- where unit.Distance < 80
- where unit.HealthPercent < 100
- select unit).FirstOrDefault();
- }
- private IEnumerable<WoWPlayer> GetResurrectTargets()
- {
- return (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(false, false)
- orderby unit.Distance ascending
- where unit.Dead
- where unit.IsInMyPartyOrRaid
- where !unit.IsGhost
- where unit.Distance < 100
- select unit);
- }
- public override void PreCombatBuff()
- {
- if (!isAuraActive("Mark of the Wild"))
- {
- C("Mark of the Wild");
- return;
- }
- foreach (WoWPlayer p in Me.PartyMembers)
- {
- if (p.Distance > 40 || p.Dead || p.IsGhost)
- continue;
- else if (!isAuraActive("Blessing of Kings", p) && !isAuraActive("Mark of the Wild", p))
- {
- C("Mark of the Wild", p);
- return;
- }
- }
- }
- private bool Resurrecting()
- {
- foreach (WoWPlayer p in GetResurrectTargets())
- {
- if (Blacklist.Contains(p.Guid, true))
- {
- continue;
- }
- else
- {
- if (p.Distance > 40 || !p.InLineOfSight)
- {
- Logging.Write("moving to res " + p);
- Navigator.MoveTo(p.Location);
- return true;
- }
- else if (CC("Revive", p) && C("Revive", p))
- {
- Logging.Write("added " + p + " to res blacklist for 15s");
- Blacklist.Add(p, new TimeSpan(0, 0, 15));
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- return false;
- }
- public override bool NeedPreCombatBuffs
- {
- get
- {
- if (Resurrecting())
- {
- return true;
- }
- else if (!isAuraActive("Mark of the Wild"))
- {
- return true;
- }
- else
- {
- foreach (WoWPlayer p in Me.PartyMembers)
- {
- if (p.Distance > 40 || p.Dead || p.IsGhost)
- continue;
- if ((!isAuraActive("Blessing of Kings", p) && !isAuraActive("Mark of the Wild", p)) ||
- (!isAuraActive("Blessing of Might", p) && isAuraActive("Mark of the Wild", p)))
- {
- return true;
- }
- }
- }
- return false;
- }
- }
- private bool isAuraActive(string name)
- {
- return isAuraActive(name, Me);
- }
- private bool isAuraActive(string name, WoWUnit u)
- {
- return u.ActiveAuras.ContainsKey(name);
- }
- public override sealed string Name { get { return "Druidhealz"; } }
- public override WoWClass Class { get { return WoWClass.Druid; } }
- private static LocalPlayer Me { get { return ObjectManager.Me; } }
- public override bool NeedRest
- {
- get
- {
- if (Me.HealthPercent < 50 &&
- !Me.Auras.ContainsKey("Food")) //To prevent food spam.
- {
- Logging.Write("Need food");
- return true;
- }
- return false;
- }
- }
- public override void Rest()
- {
- // this ought never get run over level 3
- if (Me.HealthPercent < 50)
- {
- Styx.Logic.Common.Rest.Feed(); //these arent needed.
- }
- }
- public override bool NeedHeal
- {
- get
- {
- if (GetHealTarget() != null)
- {
- return true;
- }
- return false;
- }
- }
- public override void Heal()
- {
- if (StyxWoW.GlobalCooldown)
- return;
- else if (CancelHeal())
- return;
- else if (Self())
- return;
- else if (Healing())
- return;
- else if (Cleansing())
- return;
- }
- public override bool NeedPullBuffs { get { return false; } }
- public override bool NeedCombatBuffs { get { return false; } }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement