public static bool InteractAndSell(uint unitID, SellItemActionType SellItemType, uint OptionalItemEntry, uint Count) 
                                                                            // Count - for "SellItemActionType.Specific"
        {
//                  while (!Me.Combat && )
//                  Thread.Sleep(100);
            if (!IsDone)
            {
                if (MerchantFrame.Instance == null || !MerchantFrame.Instance.IsVisible)
                {
                    WoWPoint movetoPoint = Me.Location;
                    WoWUnit unit = null;
                    unit = ObjectManager.GetObjectsOfType<WoWUnit>().Where(o => o.Entry == unitID).
                        OrderBy(o => o.Distance).FirstOrDefault();
                    if (unit != null)
                        movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, unit.Location, 3);
                    else if (movetoPoint == WoWPoint.Zero)
                        movetoPoint = GetLocationFromDB(MoveToType.NpcByID, unitID);
                    if (movetoPoint != WoWPoint.Zero && ObjectManager.Me.Location.Distance(movetoPoint) > 4.5)
                    {
                        Navigator.MoveTo(movetoPoint);
                        // Util.MoveTo(movetoPoint);
                    }
                    else if (unit != null)
                    {
                        // open selling interface:
                        unit.Target();
                        unit.Interact();
                    }
                    if (GossipFrame.Instance != null && GossipFrame.Instance.IsVisible)
                    {
                        foreach (GossipEntry ge in GossipFrame.Instance.GossipOptionEntries)
                        {
                            if (ge.Type == GossipEntry.GossipEntryType.Vendor)
                            {
                                GossipFrame.Instance.SelectGossipOption(ge.Index);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (SellItemType == SellItemActionType.Specific)
                    {
                        List<WoWItem> itemList = ObjectManager.Me.BagItems.Where(u => u.Entry == OptionalItemEntry).Take((int)Count).ToList();
                        if (itemList != null)
                        {
                            using (new FrameLock())
                            {
                                foreach (WoWItem item in itemList)
                                    item.UseContainerItem();
                            }
                        }
                    }
                    else
                    {
                        List<WoWItem> itemList = null;
                        IEnumerable<WoWItem> itemQuery = from item in Me.BagItems
                                                         where !ProtectedItems.Contains(item.Entry)
                                                         select item;
                        switch (SellItemType)
                        {
                            case SellItemActionType.Greys:
                                itemList = itemQuery.Where(i => i!=null && i.IsValid && (i.Quality == WoWItemQuality.Poor)).ToList();
                                break;
                            case SellItemActionType.Whites:
                                itemList = itemQuery.Where(i => i!=null && i.IsValid && (i.Quality == WoWItemQuality.Common || i.Quality == WoWItemQuality.Poor)).ToList();
                                break;
                            case SellItemActionType.Greens:
                                itemList = itemQuery.Where(i => i!=null && i.IsValid && ( i.Quality == WoWItemQuality.Uncommon || i.Quality == WoWItemQuality.Common || i.Quality == WoWItemQuality.Poor)).ToList();
                                break;
                        }
                        if (itemList != null)
                        {
                            using (new FrameLock())
                            {
                                foreach (WoWItem item in itemList)
                                {
                                    item.UseContainerItem();
                                }
                            }
                        }
                    }
                    Logging.Write("SellItemAction Completed ");
                    IsDone = true;
                    return true;
                }
                if (IsDone)
                    Lua.DoString("CloseMerchant()");
                else 
                    return false;
            }
            return false;

        }
        public static bool InteractAndSell(uint unitID, SellItemActionType SellItemType, uint OptionalItemEntry, uint Count)
        // Count - for "SellItemActionType.Specific"
        {
//                  while (!Me.Combat && )
//                  Thread.Sleep(100);
            if (!IsDone)
            {
                if (MerchantFrame.Instance == null || !MerchantFrame.Instance.IsVisible)
                {
                    WoWPoint movetoPoint = Me.Location;
                    WoWUnit  unit        = null;
                    unit = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.Entry == unitID).
                           OrderBy(o => o.Distance).FirstOrDefault();
                    if (unit != null)
                    {
                        movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, unit.Location, 3);
                    }
                    else if (movetoPoint == WoWPoint.Zero)
                    {
                        movetoPoint = GetLocationFromDB(MoveToType.NpcByID, unitID);
                    }
                    if (movetoPoint != WoWPoint.Zero && ObjectManager.Me.Location.Distance(movetoPoint) > 4.5)
                    {
                        Navigator.MoveTo(movetoPoint);
                        // Util.MoveTo(movetoPoint);
                    }
                    else if (unit != null)
                    {
                        // open selling interface:
                        unit.Target();
                        unit.Interact();
                    }
                    if (GossipFrame.Instance != null && GossipFrame.Instance.IsVisible)
                    {
                        foreach (GossipEntry ge in GossipFrame.Instance.GossipOptionEntries)
                        {
                            if (ge.Type == GossipEntry.GossipEntryType.Vendor)
                            {
                                GossipFrame.Instance.SelectGossipOption(ge.Index);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (SellItemType == SellItemActionType.Specific)
                    {
                        List <WoWItem> itemList = ObjectManager.Me.BagItems.Where(u => u.Entry == OptionalItemEntry).Take((int)Count).ToList();
                        if (itemList != null)
                        {
                            using (new FrameLock())
                            {
                                foreach (WoWItem item in itemList)
                                {
                                    item.UseContainerItem();
                                }
                            }
                        }
                    }
                    else
                    {
                        List <WoWItem>        itemList  = null;
                        IEnumerable <WoWItem> itemQuery = from item in Me.BagItems
                                                          where !ProtectedItems.Contains(item.Entry)
                                                          select item;
                        switch (SellItemType)
                        {
                        case SellItemActionType.Greys:
                            itemList = itemQuery.Where(i => i != null && i.IsValid && (i.Quality == WoWItemQuality.Poor)).ToList();
                            break;

                        case SellItemActionType.Whites:
                            itemList = itemQuery.Where(i => i != null && i.IsValid && (i.Quality == WoWItemQuality.Common || i.Quality == WoWItemQuality.Poor)).ToList();
                            break;

                        case SellItemActionType.Greens:
                            itemList = itemQuery.Where(i => i != null && i.IsValid && (i.Quality == WoWItemQuality.Uncommon || i.Quality == WoWItemQuality.Common || i.Quality == WoWItemQuality.Poor)).ToList();
                            break;
                        }
                        if (itemList != null)
                        {
                            using (new FrameLock())
                            {
                                foreach (WoWItem item in itemList)
                                {
                                    item.UseContainerItem();
                                }
                            }
                        }
                    }
                    Logging.Write("SellItemAction Completed ");
                    IsDone = true;
                    return(true);
                }
                if (IsDone)
                {
                    Lua.DoString("CloseMerchant()");
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }