Advertisement
Guest User

Untitled

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