using Styx;using Styx.Common;
using Styx.CommonBot;
using Styx.Plugins;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Linq;
namespace DruidHarvestAssist
{
public class DruidHarvestAssist : HBPlugin
{
private static bool Harvesting;
private static bool Initialize;
private bool On;
public LocalPlayer Me { get { return StyxWoW.Me; } }
public static WoWGameObject HerbWithinInteractRange
{
get
{
ObjectManager.Update();
IOrderedEnumerable<WoWGameObject> tars =
(from o in ObjectManager.GetObjectsOfType<WoWGameObject>(false, false)
where
o.IsHerb && o.WithinInteractRange &&
o.RequiredSkill <= StyxWoW.Me.GetSkill("Herbalism").CurrentValue
orderby o.DistanceSqr ascending
select o);
return tars.Count() > 0 ? tars.First() : null;
}
}
public static WoWGameObject Herb
{
get
{
ObjectManager.Update();
IOrderedEnumerable<WoWGameObject> tars =
(from o in ObjectManager.GetObjectsOfType<WoWGameObject>(false, false)
where o.IsHerb && o.RequiredSkill <= StyxWoW.Me.GetSkill("Herbalism").CurrentValue
orderby o.DistanceSqr ascending
select o);
return tars.Count() > 0 ? tars.First() : null;
}
}
private static string Left(string s, int c)
{
return String.IsNullOrEmpty(s) ? s : s.Substring(0, Math.Min(c, s.Length));
}
public override string Author
{
get { return "donnamonna & the community"; }
}
public override string Name
{
get { return "Druid Harvest Assist"; }
}
public override Version Version
{
get { return new Version(0, 4); }
}
public override bool WantButton
{
get { return false; }
}
public override void Pulse()
{
if (!Initialize)
{
Harvesting = TreeRoot.Current != null &&
"GATHERBUDDY2" == Left(TreeRoot.Current.Name, 12).ToUpper();
if (Harvesting)
{
Logging.Write(System.Windows.Media.Colors.Aqua, "Druid Harvest Assist enabled");
}
On = false;
Initialize = true;
}
SupressFormSwitch();
Harvest();
LeaveCombatHerb();
LeaveCombatNoHerb();
}
private void Harvest()
{
if (!Me.IsValid || !StyxWoW.IsInGame || !StyxWoW.IsInWorld)
return;
if (Me.Combat && HerbWithinInteractRange != null && !Me.IsMoving)
{
try
{
ObjectManager.Update();
Herb.Interact();
Logging.Write(System.Windows.Media.Colors.LightGreen, "<DHA> Forcing Herb Collection");
}
catch (Exception e)
{
Logging.WriteException(e);
throw;
}
}
}
private void LeaveCombatNoHerb()
{
if (!Me.IsValid || !StyxWoW.IsInGame || !StyxWoW.IsInWorld)
return;
if (Me.Combat && !Me.IsMoving && HerbWithinInteractRange == null)
{
WoWMovement.Move(WoWMovement.MovementDirection.JumpAscend, TimeSpan.FromMilliseconds(200));
Logging.Write(System.Windows.Media.Colors.Pink, "<DHA> Exit Combat");
}
}
private void SupressFormSwitch()
{
if (!Me.IsValid || !StyxWoW.IsInGame || !StyxWoW.IsInWorld)
return;
if (!Me.Combat)
{
if (!On)
{
Lua.DoString("oldDismount = Dismount; Dismount = function() end");
On = true;
Logging.Write(System.Windows.Media.Colors.Aqua, "<DHA> SupressDismount disabled");
}
}
else if (Me.Combat && On)
{
Lua.DoString("Dismount = oldDismount;");
On = false;
Logging.Write(System.Windows.Media.Colors.Aqua, "<DHA> SupressDismount enabled");
}
}
private void LeaveCombatHerb()
{
if (!Me.IsValid || !StyxWoW.IsInGame || !StyxWoW.IsInWorld)
return;
if (Me.Combat && Me.HealthPercent < 90)
{
WoWMovement.Move(WoWMovement.MovementDirection.JumpAscend, TimeSpan.FromMilliseconds(200));
Logging.Write(System.Windows.Media.Colors.Pink, "<DHA> Exit Combat");
}
}
}
}