using System;
using System.Threading;
using robotManager.Helpful;
using robotManager.Products;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;
using System.IO;
using System.Linq;
using wManager.Wow.Class;
using System.Collections.Generic;

static class Routine
{

    public static bool _init = false;

    private static bool _launched;
    public static void Pulse()
    {

        _launched = true;
        while (_launched)
        {
            try
            {

                if (!Products.InPause && ObjectManager.Me.IsAlive)
                {
                    try
                    {
                        var t = ObjectManager.GetWoWUnitLootable().Where(p => p.IsLootable && p.GetDistance2D <= 10).OrderBy(p => p.GetDistance2D).FirstOrDefault();
                        if (t != null)
                        {
                            WoWUnit lootUnit = new WoWUnit(t.GetBaseAddress);
                            Interact.InteractGameObject(lootUnit.GetBaseAddress);
                        }
                    }
                    catch { }
                }
                Thread.Sleep(10);
            }
            catch (Exception e)
            {
                ObjectManager.Me.ForceIsCast = false;
                Logging.WriteError("Combatlooter.Routine.Pulse(): " + e);
            }
        }
    }

    public static void checkLootables()
    {

    }

    public static void Dispose()
    {
        _launched = false;
    }
}


