Hey, I cleaned up your method and make it look a little cleaner. when i get a chance i will do some editing and see what i can do to help you improve it.
public class Moonglade
{
static Moonglade()
{
Npc npc = new Npc
{
Type = NpcType.DruidTrainer,
Name = "Loganaar",
Entry = 12042,
Position = new Vector3(7867.13, -2593.73, 486.8367),
ContinentId = wManager.Wow.Enums.ContinentId.Kalimdor,
Faction = Npc.FactionType.Neutral,
CanFlyTo = true
};
NpcDB.AddNpc(npc, true, true);
Logging.Write($"[Moonglade]: Trainer {npc.Name} Was Added to Npc Database");
}
internal static void Start()
{
FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState += OnRunState;
FiniteStateMachineEvents.OnRunState += OnRunState;
FiniteStateMachineEvents.OnAfterRunState += OnAfterRunState;
}
internal static void Dispose()
{
FiniteStateMachineEvents.OnRunState -= OnRunState;
FiniteStateMachineEvents.OnBeforeCheckIfNeedToRunState -= OnRunState;
FiniteStateMachineEvents.OnAfterRunState -= OnAfterRunState;
}
private static void OnRunState(Engine Engine, State state, CancelEventArgs cancelable)
{
if (state.GetType() != typeof(Trainers)) return;
if (CurrentLevel % 2 != 0 || !CanTravel || !wManager.wManagerSetting.CurrentSetting.TrainNewSkills) return;
if (!MapName.Contains("Moonglade"))
{
cancelable.Cancel = true;
MovementManager.StopMoveTo(true, Random);
Lua.RunMacroText("/cast Teleport: Moonglade");
Usefuls.WaitIsCasting();
Thread.Sleep(Random);
}
}
private static void OnAfterRunState(Engine Engine, State state)
{
if (state.GetType() != typeof(Trainers) || !CanTravel) return;
if (MapName.Contains("Moonglade"))
{
ItemsManager.UseItem(6948);
Usefuls.WaitIsCasting();
Thread.Sleep(5000);
ToTown.ForceToTown = true;
}
}
private static bool CanTravel
{
get
{
return SpellManager.KnowSpell(18960) && GetItemCoolDown(6948) == 0;
}
}
private static String MapName => Usefuls.MapZoneName;
private static Int32 Random = Others.Random(4000, 7000);
private static ulong CurrentLevel => ObjectManager.Me.Level;
private static Int32 GetItemCoolDown(Int32 ItemID)
{
return Lua.LuaDoString<Int32>($@"local startTime, duration, _ = GetItemCooldown({ItemID});
return duration - (GetTime() - startTime);");
}
}