예제 #1
0
        public static bool CreateSellOrder(string module, int duration, bool corp)
        {
            if (DateTime.UtcNow.Subtract(_lastExecute).TotalSeconds < Time.Instance.Marketsellorderdelay_seconds)
            {
                return(false);
            }
            _lastExecute = DateTime.UtcNow;

            DirectItem directItem = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.ItemId == _currentItem.Id);

            if (directItem == null)
            {
                Logging.Log(module, "Item " + _currentItem.Name + " no longer exists in the hanger", Logging.White);
                return(false);
            }

            DirectMarketWindow marketWindow = Cache.Instance.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            if (marketWindow == null)
            {
                Cache.Instance.OpenMarket(module);
                return(false);
            }

            if (!marketWindow.IsReady)
            {
                return(false);
            }

            if (marketWindow.DetailTypeId != directItem.TypeId)
            {
                marketWindow.LoadTypeId(directItem.TypeId);
                return(false);
            }

            DirectOrder competitor = marketWindow.SellOrders.Where(i => i.StationId == Cache.Instance.DirectEve.Session.StationId).OrderBy(i => i.Price).FirstOrDefault();

            if (competitor != null)
            {
                double newprice = competitor.Price - 0.01;

                if (Cache.Instance.DirectEve.Session.StationId != null)
                {
                    Cache.Instance.DirectEve.Sell(directItem, (int)Cache.Instance.DirectEve.Session.StationId, directItem.Quantity, newprice, duration, corp);
                }
            }

            return(true);
        }
예제 #2
0
        public static bool BuySkill(int skillID)
        {
            if (!Cache.Instance.InStation)
            {
                return(false);
            }
            if (DateTime.UtcNow < _nextSkillTrainingAction)
            {
                if (Settings.Instance.DebugSkillTraining)
                {
                    Logging.Log("SkillPlan.buySkill:", "Next Skill Training Action is set to continue in [" + Math.Round(_nextSkillTrainingAction.Subtract(DateTime.UtcNow).TotalSeconds, 0) + "] seconds", Logging.White);
                }
                return(false);
            }

            if (buyingSkill == true && buyingSkillTypeID != 0)
            {
                buyingIterator++;

                if (buyingIterator > 20)
                {
                    Logging.Log("buySkill", "buying iterator < 20 with SkillID" + skillID, Logging.White);
                    buyingSkill       = false;
                    buyingSkillTypeID = 0;
                    buyingIterator    = 0;
                    return(true);
                }
                // only buy if we do not have it already in our itemhangar
                if (DoWeHaveThisSkillAlreadyInOurItemHangar(skillID))
                {
                    Logging.Log("buySkill", "We already purchased this skill" + skillID, Logging.White);
                    buyingSkill       = false;
                    buyingSkillTypeID = 0;
                    buyingIterator    = 0;
                    return(true);
                }

                DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();
                if (Cache.Instance.DirectEve.HasSupportInstances())
                {
                    if (marketWindow == null)
                    {
                        _nextSkillTrainingAction = DateTime.UtcNow.AddSeconds(10);

                        Logging.Log("buySkill", "Opening market window", Logging.White);

                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                        return(false);
                    }
                    if (!marketWindow.IsReady)
                    {
                        _nextSkillTrainingAction = DateTime.UtcNow.AddSeconds(3);
                        return(false);
                    }

                    if (marketWindow.DetailTypeId != skillID)
                    {
                        // No, load the right order
                        marketWindow.LoadTypeId(skillID);
                        Logging.Log("buySkill", "Loading market with right typeid ", Logging.White);
                        _nextSkillTrainingAction = DateTime.UtcNow.AddSeconds(6);
                        return(false);
                    }

                    // Get the median sell price
                    InvType type     = Cache.Instance.InvTypesById[skillID];
                    double? maxPrice = type.MedianSell * 10;
                    Logging.Log("buySkill", "maxPrice " + maxPrice.ToString(), Logging.White);

                    // Do we have orders?
                    IEnumerable <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId && o.Price < maxPrice).ToList();
                    if (orders.Any())
                    {
                        DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault();
                        if (order != null)
                        {
                            order.Buy(1, DirectOrderRange.Station);
                        }
                        Logging.Log("buySkill", "Buying skill with typeid & waiting 20 seconds ( to ensure we don't buy the skills twice ) " + skillID, Logging.White);
                        buyingSkill       = false;
                        buyingSkillTypeID = 0;
                        buyingIterator    = 0;
                        // Wait for the order to go through
                        _nextRetrieveCharactersheetInfoAction = DateTime.MinValue;                         // ensure we get the character sheet update
                        _nextSkillTrainingAction = DateTime.UtcNow.AddSeconds(20);
                        return(true);
                    }
                    else
                    {
                        Logging.Log("buySkill", "No skill could be found with median price ", Logging.White);
                        buyingSkill       = false;
                        buyingSkillTypeID = 0;
                        buyingIterator    = 0;
                        return(false);
                    }
                }
            }
            return(false);
        }
예제 #3
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnCancelOrderFinished != null)
                {
                    OnCancelOrderFinished(OrderId);
                }
                break;

            case State.Begin:

                // Don't close the market window if its already up
                if (marketWindow != null)
                {
                    Logging.Log("CancelOrder:Process", "Market already open no need to open the market", Logging.White);
                }
                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    Logging.Log("CancelOrder:Process", "Opening Market", Logging.White);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    break;
                }

                _state = State.LoadOrders;
                break;

            case State.LoadOrders:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    Logging.Log("CancelOrder:Process", "Load orders", Logging.White);

                    if (marketWindow.LoadOrders() == true)
                    {
                        _state = State.Cancel;
                    }

                    break;
                }
                else
                {
                    Logging.Log("CancelOrder:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.Cancel:

                // We keep getting the popup saying we can't modify many orders in a minute, so this needs to be at 6 or higher, probably higher
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                if (marketWindow != null)
                {
                    try
                    {
                        _lastAction = DateTime.UtcNow;

                        List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList();
                        DirectOrder        order  = orders.FirstOrDefault(o => o.OrderId == OrderId);

                        if (order != null)
                        {
                            Logging.Log("CancelOrder:Process", "Loaded order, OrderId - " + order.OrderId, Logging.White);

                            bool success = order.CancelOrder();

                            if (success)
                            {
                                Logging.Log("CancelOrder:Process", "Canceling order successful", Logging.White);
                            }
                            else
                            {
                                Logging.Log("CancelOrder:Process", "Canceling order failure", Logging.White);
                            }
                        }
                        else
                        {
                            Logging.Log("CancelOrder:Process", "Order no longer exists, exiting modify action", Logging.White);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Log("CancelOrder:Process", "Exception [" + ex + "] - Ending modify order script", Logging.Debug);
                    }

                    _state = State.Done;
                }
                else
                {
                    _state = State.OpenMarket;
                }

                break;
            }
        }
예제 #4
0
파일: BuyLPI.cs 프로젝트: seb1707/Questor
        public void ProcessState()
        {
            if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1)
            {
                return;
            }
            _lastAction = DateTime.UtcNow;

            if (Cache.Instance.ItemHangar == null)
            {
                return;
            }
            DirectMarketWindow marketWindow = Cache.Instance.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_States.CurrentBuyLPIState)
            {
            case BuyLPIState.Idle:
            case BuyLPIState.Done:
                break;

            case BuyLPIState.Begin:

                /*
                 * if(marketWindow != null)
                 *  marketWindow.Close();
                 *
                 * if(lpstore != null)
                 *  lpstore.Close();*/

                _States.CurrentBuyLPIState = BuyLPIState.ReadyItemhangar;
                break;

            case BuyLPIState.ReadyItemhangar:

                if (Cache.Instance.ItemHangar == null)
                {
                    return;
                }
                if (!Cache.Instance.OpenShipsHangar("BuyLPI"))
                {
                    return;
                }

                _States.CurrentBuyLPIState = BuyLPIState.OpenLpStore;
                break;

            case BuyLPIState.OpenLpStore:

                if (Cache.Instance.LPStore == null)
                {
                    return;
                }
                _States.CurrentBuyLPIState = BuyLPIState.FindOffer;
                break;

            case BuyLPIState.FindOffer:

                if (Cache.Instance.LPStore != null)
                {
                    BuyLPI._offer = Cache.Instance.LPStore.Offers.FirstOrDefault(o => o.TypeId == Item);

                    // Wait for the amount of LP to change
                    if (_lastLoyaltyPoints == Cache.Instance.LPStore.LoyaltyPoints)
                    {
                        break;
                    }

                    // Do not expect it to be 0 (probably means its reloading)
                    if (Cache.Instance.LPStore.LoyaltyPoints == 0)
                    {
                        if (_loyaltyPointTimeout < DateTime.UtcNow)
                        {
                            Logging.Log("BuyLPI", "It seems we have no loyalty points left", Logging.White);
                            _States.CurrentBuyLPIState = BuyLPIState.Done;
                            break;
                        }
                        break;
                    }

                    _lastLoyaltyPoints = Cache.Instance.LPStore.LoyaltyPoints;

                    // Find the offer
                    if (_offer == null)
                    {
                        Logging.Log("BuyLPI", "Can't find offer with type name/id: " + Item + "!", Logging.White);
                        _States.CurrentBuyLPIState = BuyLPIState.Done;
                        break;
                    }
                    _States.CurrentBuyLPIState = BuyLPIState.CheckPetition;
                }
                _States.CurrentBuyLPIState = BuyLPIState.OpenLpStore;
                break;

            case BuyLPIState.CheckPetition:

                if (Cache.Instance.LPStore != null)
                {
                    // Check LP
                    if (_lastLoyaltyPoints < _offer.LoyaltyPointCost)
                    {
                        Logging.Log("BuyLPI", "Not enough loyalty points left", Logging.White);

                        _States.CurrentBuyLPIState = BuyLPIState.Done;
                        break;
                    }

                    // Check ISK
                    if (Cache.Instance.DirectEve.Me.Wealth < _offer.IskCost)
                    {
                        Logging.Log("BuyLPI", "Not enough ISK left", Logging.White);

                        _States.CurrentBuyLPIState = BuyLPIState.Done;
                        break;
                    }

                    // Check items
                    foreach (DirectLoyaltyPointOfferRequiredItem requiredItem in _offer.RequiredItems)
                    {
                        DirectItem ship = Cache.Instance.ShipHangar.Items.FirstOrDefault(i => i.TypeId == requiredItem.TypeId);
                        DirectItem item = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.TypeId == requiredItem.TypeId);
                        if (item == null || item.Quantity < requiredItem.Quantity)
                        {
                            if (ship == null || ship.Quantity < requiredItem.Quantity)
                            {
                                Logging.Log("BuyLPI", "Missing [" + requiredItem.Quantity + "] x [" +
                                            requiredItem.TypeName + "]", Logging.White);

                                //if(!_form.chkBuyItems.Checked)
                                //{
                                //    Logging.Log("BuyLPI","Done, do not buy item");
                                //    States.CurrentBuyLPIState = BuyLPIState.Done;
                                //    break;
                                //}

                                Logging.Log("BuyLPI", "Are buying the item [" + requiredItem.TypeName + "]",
                                            Logging.White);
                                _requiredUnit              = Convert.ToInt32(requiredItem.Quantity);
                                _requiredItemId            = requiredItem.TypeId;
                                _States.CurrentBuyLPIState = BuyLPIState.OpenMarket;
                                return;
                            }
                        }
                        _States.CurrentBuyLPIState = BuyLPIState.AcceptOffer;
                    }
                    _States.CurrentBuyLPIState = BuyLPIState.OpenLpStore;
                }
                break;

            case BuyLPIState.OpenMarket:

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    break;
                }

                _States.CurrentBuyLPIState = BuyLPIState.BuyItems;
                break;

            case BuyLPIState.BuyItems:

                Logging.Log("BuyLPI", "Opening Market", Logging.White);

                if (marketWindow != null && marketWindow.DetailTypeId != _requiredItemId)
                {
                    marketWindow.LoadTypeId(_requiredItemId);
                    break;
                }

                if (marketWindow != null)
                {
                    IEnumerable <DirectOrder> orders =
                        marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId);

                    DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault();

                    if (order == null)
                    {
                        Logging.Log("BuyLPI", "No orders", Logging.White);
                        _States.CurrentBuyLPIState = BuyLPIState.Done;
                        break;
                    }

                    order.Buy(_requiredUnit, DirectOrderRange.Station);
                }

                Logging.Log("BuyLPI", "Buy Item", Logging.White);

                _States.CurrentBuyLPIState = BuyLPIState.CheckPetition;

                break;

            case BuyLPIState.AcceptOffer:

                if (Cache.Instance.LPStore != null)
                {
                    DirectLoyaltyPointOffer offer2 = Cache.Instance.LPStore.Offers.FirstOrDefault(o => o.TypeId == Item);

                    if (offer2 != null)
                    {
                        Logging.Log("BuyLPI", "Accepting [" + offer2.TypeName + "]", Logging.White);
                        offer2.AcceptOfferFromWindow();
                    }
                }
                _States.CurrentBuyLPIState = BuyLPIState.Quantity;
                break;

            case BuyLPIState.Quantity:

                _loyaltyPointTimeout = DateTime.UtcNow.AddSeconds(1);

                Unit = Unit - 1;
                if (Unit <= 0)
                {
                    Logging.Log("BuyLPI", "Quantity limit reached", Logging.White);

                    _States.CurrentBuyLPIState = BuyLPIState.Done;
                    break;
                }

                _States.CurrentBuyLPIState = BuyLPIState.Begin;

                break;
            }
        }
예제 #5
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnMarketInfoFinished != null)
                {
                    OnMarketInfoFinished(_marketItem);
                }
                break;

            case State.Begin:

                // Don't close the market window if its already up
                if (marketWindow != null)
                {
                    Logging.Log("MarketItemInfo:Process", "Market already open no need to open the market", Logging.White);
                }

                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    Logging.Log("MarketItemInfo:Process", "Opening Market", Logging.White);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    Logging.Log("MarketItemInfo:Process", "Market window is not ready", Logging.White);
                    break;
                }

                _state = State.LoadItem;
                break;

            case State.LoadItem:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    Logging.Log("MarketItemInfo:Process", "Load orders for TypeId - " + TypeId.ToString(), Logging.White);

                    if (marketWindow.DetailTypeId != TypeId)
                    {
                        if (marketWindow.LoadTypeId(TypeId) == true)
                        {
                            _state = State.CacheInfo;
                        }
                    }

                    break;
                }
                else
                {
                    Logging.Log("MarketItemInfo:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.CacheInfo:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        Logging.Log("MarketItemInfo:Process", "Market window is not ready", Logging.White);
                        break;
                    }

                    if (marketWindow.DetailTypeId != TypeId)
                    {
                        _state = State.LoadItem;
                    }

                    Logging.Log("MarketItemInfo:Process", "Get list of orders for Item - " + TypeId.ToString(), Logging.White);

                    _marketItem = new MarketItem();

                    if (_marketItem != null)
                    {
                        Logging.Log("MarketItemInfo:Process", "Get list of orders successful", Logging.White);

                        _marketItem.SellOrders = marketWindow.SellOrders;
                        _marketItem.BuyOrders  = marketWindow.BuyOrders;
                        _marketItem.TypeId     = TypeId;

                        Cache.Instance.SetMarketItem(TypeId, _marketItem);

                        _state = State.Done;
                    }
                }
                else
                {
                    _state = State.OpenMarket;
                }
                break;
            }
        }
예제 #6
0
        /// <summary>
        /// Check if we have kernite in station
        /// </summary>
        /// <returns></returns>
        public StorylineState PreAcceptMission(Storyline storyline)
        {
            DirectEve directEve = Cache.Instance.DirectEve;

            if (_nextAction > DateTime.UtcNow)
            {
                return(StorylineState.PreAcceptMission);
            }

            // the ore and ore quantity can be stored in the characters settings xml this is to facility mission levels other than 4.
            //The defaults are for level 4 so it will not break for those people that do not include these in their settings file
            //  Level 1         <MaterialsForWarOreID>1230</MaterialsForWarOreID>
            //                  <MaterialsForWarOreQty>999</MaterialsForWarOreQty>
            //  Level 4         <MaterialsForWarOreID>20</MaterialsForWarOreID>
            //                  <MaterialsForWarOreQty>8000</MaterialsForWarOreQty>

            int oreid       = Settings.Instance.MaterialsForWarOreID;  //1230;
            int orequantity = Settings.Instance.MaterialsForWarOreQty; //999

            // Open the item hangar
            if (Cache.Instance.ItemHangar == null)
            {
                return(StorylineState.PreAcceptMission);
            }

            //if (Cache.Instance.ItemHangar.Window == null)
            //{
            //    Logging.Log("MaterialsForWar", "PreAcceptMission: ItemHangar is null", Logging.Orange);
            //    if (!Cache.Instance.ReadyItemsHangar("MaterialsForWarPreparation")) return StorylineState.PreAcceptMission;
            //    return StorylineState.PreAcceptMission;
            //}

            // Is there a market window?
            DirectMarketWindow marketWindow = directEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            // Do we have the ore we need in the Item Hangar?.

            if (Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity) >= orequantity)
            {
                DirectItem thisOreInhangar = Cache.Instance.ItemHangar.Items.FirstOrDefault(i => i.TypeId == oreid);
                if (thisOreInhangar != null)
                {
                    Logging.Log("MaterialsForWarPreparation", "We have [" + Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity).ToString(CultureInfo.InvariantCulture) + "] " + thisOreInhangar.TypeName + " in the item hangar accepting mission", Logging.White);
                }

                // Close the market window if there is one
                if (marketWindow != null)
                {
                    marketWindow.Close();
                }

                return(StorylineState.AcceptMission);
            }

            if (Cache.Instance.CurrentShipsCargo == null)
            {
                return(StorylineState.PreAcceptMission);
            }

            if (Cache.Instance.CurrentShipsCargo.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity) >= orequantity)
            {
                DirectItem thisOreInhangar = Cache.Instance.CurrentShipsCargo.Items.FirstOrDefault(i => i.TypeId == oreid);
                if (thisOreInhangar != null)
                {
                    Logging.Log("MaterialsForWarPreparation", "We have [" + Cache.Instance.CurrentShipsCargo.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity).ToString(CultureInfo.InvariantCulture) + "] " + thisOreInhangar.TypeName + " in the CargoHold accepting mission", Logging.White);
                }

                // Close the market window if there is one
                if (marketWindow != null)
                {
                    marketWindow.Close();
                }

                return(StorylineState.AcceptMission);
            }

            if (Cache.Instance.DirectEve.HasSupportInstances())
            {
                // We do not have enough ore, open the market window
                if (marketWindow == null)
                {
                    _nextAction = DateTime.UtcNow.AddSeconds(10);

                    Logging.Log("MaterialsForWarPreparation", "Opening market window", Logging.White);

                    directEve.ExecuteCommand(DirectCmd.OpenMarket);
                    return(StorylineState.PreAcceptMission);
                }

                // Wait for the window to become ready (this includes loading the ore info)
                if (!marketWindow.IsReady)
                {
                    return(StorylineState.PreAcceptMission);
                }

                // Are we currently viewing ore orders?
                if (marketWindow.DetailTypeId != oreid)
                {
                    // No, load the ore orders
                    marketWindow.LoadTypeId(oreid);

                    Logging.Log("MaterialsForWarPreparation", "Loading market window", Logging.White);

                    _nextAction = DateTime.UtcNow.AddSeconds(5);
                    return(StorylineState.PreAcceptMission);
                }

                // Get the median sell price
                InvType type     = Cache.Instance.InvTypesById[20];
                double? maxPrice = type.MedianSell * 4;

                // Do we have orders that sell enough ore for the mission?
                IEnumerable <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == directEve.Session.StationId && o.Price < maxPrice).ToList();
                if (!orders.Any() || orders.Sum(o => o.VolumeRemaining) < orequantity)
                {
                    Logging.Log("MaterialsForWarPreparation", "Not enough (reasonably priced) ore available! Blacklisting agent for this Questor session!", Logging.Orange);

                    // Close the market window
                    marketWindow.Close();

                    // No, black list the agent in this Questor session (note we will never decline storylines!)
                    return(StorylineState.BlacklistAgent);
                }

                // How much ore do we still need?
                int neededQuantity = orequantity - Cache.Instance.ItemHangar.Items.Where(i => i.TypeId == oreid).Sum(i => i.Quantity);
                if (neededQuantity > 0)
                {
                    // Get the first order
                    DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault();
                    if (order != null)
                    {
                        // Calculate how much ore we still need
                        int remaining = Math.Min(neededQuantity, order.VolumeRemaining);
                        order.Buy(remaining, DirectOrderRange.Station);

                        Logging.Log("MaterialsForWarPreparation", "Buying [" + remaining + "] ore", Logging.White);

                        // Wait for the order to go through
                        _nextAction = DateTime.UtcNow.AddSeconds(10);
                    }
                }
                return(StorylineState.PreAcceptMission);
            }

            Logging.Log("MaterialsForWarPreparation", "No DirectEVE Instances Available: free version detected. Buy/Sell support not available. Blacklisting agent for this Questor session!", Logging.Orange);

            // Close the market window
            if (marketWindow != null)
            {
                marketWindow.Close();
            }
            // No, black list the agent in this Questor session (note we will never decline storylines!)
            return(StorylineState.BlacklistAgent);
        }
예제 #7
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnUpdateOrderFinished != null)
                {
                    OnUpdateOrderFinished(OrderId);
                }
                break;

            case State.Begin:

                // Don't close the market window if its already up
                if (marketWindow != null)
                {
                    Logging.Log("UpdateOrder:Process", "Market already open no need to open the market", Logging.White);
                }
                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    Logging.Log("UpdateOrder:Process", "Opening Market", Logging.White);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    break;
                }

                _state = State.LoadOrders;
                break;

            case State.LoadOrders:

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        break;
                    }

                    Logging.Log("UpdateOrder:Process", "Load orders", Logging.White);

                    if (marketWindow.LoadOrders() == true)
                    {
                        _state = State.MarketInfo;
                    }

                    break;
                }
                else
                {
                    Logging.Log("UpdateOrder:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.MarketInfo:
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        break;
                    }

                    List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList();

                    if (orders == null)
                    {
                        Logging.Log("UpdateOrder:Process", "Something is wrong, order list is empty, ending update order action", Logging.White);
                        _state = State.Done;
                    }

                    DirectOrder order = orders.FirstOrDefault(o => o.OrderId == OrderId);

                    if (order == null)
                    {
                        Logging.Log("UpdateOrder:Process", "Order doesn't exist, ending update order action OrderId - " + OrderId, Logging.White);
                        _state = State.Done;
                        break;
                    }

                    Logging.Log("UpdateOrder:Process", "Load orders for TypeId - " + order.TypeId.ToString(), Logging.White);

                    if (marketWindow.DetailTypeId != order.TypeId)
                    {
                        if (marketWindow.LoadTypeId(order.TypeId) == true)
                        {
                            _state = State.Update;
                        }
                    }
                    else
                    {
                        _state = State.Update;
                    }

                    break;
                }
                else
                {
                    Logging.Log("MarketItemInfo:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.Update:

                // We keep getting the popup saying we can't modify many orders in a minute, so this needs to be at 6 or higher, probably higher
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1)
                {
                    break;
                }

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        break;
                    }

                    try
                    {
                        _lastAction = DateTime.UtcNow;

                        List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList();
                        DirectOrder        order  = orders.FirstOrDefault(o => o.OrderId == OrderId);

                        if (order != null)
                        {
                            Logging.Log("UpdateOrder:Process", "Loaded order, OrderId - " + order.OrderId + " OrderPrice - " + order.Price, Logging.White);

                            if (IsBid)
                            {
                                UpdateBuyOrder(order, marketWindow.SellOrders, marketWindow.BuyOrders);
                            }
                            else
                            {
                                UpdateSellOrder(order, marketWindow.SellOrders, marketWindow.BuyOrders);
                            }
                        }
                        else
                        {
                            Logging.Log("UpdateOrder:Process", "Order no longer exists, exiting modify action", Logging.White);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Log("UpdateOrder:Process", "Exception [" + ex + "] - Ending modify order script", Logging.Debug);
                    }

                    _state = State.Done;
                }
                else
                {
                    _state = State.OpenMarket;
                }

                break;
            }
        }
예제 #8
0
        public void ProcessState()
        {
            if (!Cache.Instance.InStation)
            {
                return;
            }

            if (Cache.Instance.InSpace)
            {
                return;
            }

            if (DateTime.UtcNow < Cache.Instance.LastInSpace.AddSeconds(20)) // we wait 20 seconds after we last thought we were in space before trying to do anything in station
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_States.CurrentBuyState)
            {
            case BuyState.Idle:
            case BuyState.Done:
                break;

            case BuyState.Begin:

                // Close the market window if there is one
                if (marketWindow != null)
                {
                    marketWindow.Close();
                }
                _States.CurrentBuyState = BuyState.OpenMarket;
                break;

            case BuyState.OpenMarket:
                // Close the market window if there is one
                //if (marketWindow != null)
                //    marketWindow.Close();

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    break;
                }

                Logging.Log("Buy", "Opening Market", Logging.White);
                _States.CurrentBuyState = BuyState.LoadItem;

                break;

            case BuyState.LoadItem:

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null && marketWindow.DetailTypeId != Item)
                {
                    marketWindow.LoadTypeId(Item);
                    if (useOrders)
                    {
                        _States.CurrentBuyState = BuyState.CreateOrder;
                    }
                    else
                    {
                        _States.CurrentBuyState = BuyState.BuyItem;
                    }

                    break;
                }

                break;

            case BuyState.CreateOrder:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    IEnumerable <DirectOrder> orders = marketWindow.BuyOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId);

                    DirectOrder order = orders.OrderByDescending(o => o.Price).FirstOrDefault();
                    if (order != null)
                    {
                        double price = order.Price + 0.01;
                        if (Cache.Instance.DirectEve.Session.StationId != null)
                        {
                            Cache.Instance.DirectEve.Buy((int)Cache.Instance.DirectEve.Session.StationId, Item, price, Unit, DirectOrderRange.Station, 1, 30);
                        }
                    }
                    useOrders = false;
                    _States.CurrentBuyState = BuyState.Done;
                }

                break;

            case BuyState.BuyItem:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5)
                {
                    break;
                }

                if (marketWindow != null)
                {
                    IEnumerable <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId);

                    DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault();
                    if (order != null)
                    {
                        // Calculate how much we still need
                        if (order.VolumeEntered >= Unit)
                        {
                            order.Buy(Unit, DirectOrderRange.Station);
                            _States.CurrentBuyState = BuyState.WaitForItems;
                        }
                        else
                        {
                            order.Buy(Unit, DirectOrderRange.Station);
                            Unit = Unit - order.VolumeEntered;
                            Logging.Log("Buy", "Missing " + Convert.ToString(Unit) + " units", Logging.White);
                            _returnBuy = true;
                            _States.CurrentBuyState = BuyState.WaitForItems;
                        }
                    }
                }

                break;

            case BuyState.WaitForItems:
                // Wait 5 seconds after moving
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5)
                {
                    break;
                }

                // Close the market window if there is one
                if (marketWindow != null)
                {
                    marketWindow.Close();
                }

                if (_returnBuy)
                {
                    Logging.Log("Buy", "Return Buy", Logging.White);
                    _returnBuy = false;
                    _States.CurrentBuyState = BuyState.OpenMarket;
                    break;
                }

                Logging.Log("Buy", "Done", Logging.White);
                _States.CurrentBuyState = BuyState.Done;

                break;
            }
        }
예제 #9
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnMyOrdersFinished != null)
                {
                    OnMyOrdersFinished(_mySellOrders, _myBuyOrders);
                }
                break;

            case State.Begin:

                // Don't close the market window if its already up
                if (marketWindow != null)
                {
                    Logging.Log("MyOrders:Process", "Market already open no need to open the market", Logging.White);
                }

                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    Logging.Log("MyOrders:Process", "Opening Market", Logging.White);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    Logging.Log("MyOrders:Process", "Market window is not ready", Logging.White);
                    break;
                }

                _state = State.LoadOrders;
                break;

            case State.LoadOrders:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    Logging.Log("MyOrders:Process", "Load orders", Logging.White);

                    if (marketWindow.LoadOrders() == true)
                    {
                        _state = State.CacheOrders;
                    }

                    break;
                }
                else
                {
                    Logging.Log("MyOrders:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.CacheOrders:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                if (marketWindow != null)
                {
                    _lastAction = DateTime.UtcNow;

                    Cache.Instance.OrderCap = Cache.Instance.DirectEve.GetOrderCap();

                    Logging.Log("MyOrders:Process", "Get list of my orders", Logging.White);

                    _myBuyOrders  = marketWindow.GetMyOrders(true).ToList();
                    _mySellOrders = marketWindow.GetMyOrders(false).ToList();

                    if (_mySellOrders != null)
                    {
                        Logging.Log("MyOrders:Process", "Get list of my sell orders successful", Logging.White);
                        Cache.Instance.MySellOrders = _mySellOrders;
                    }

                    if (_myBuyOrders != null)
                    {
                        Logging.Log("MyOrders:Process", "Get list of my buy orders successful", Logging.White);
                        Cache.Instance.MyBuyOrders = _myBuyOrders;
                    }

                    _state = State.Done;
                }
                else
                {
                    _state = State.OpenMarket;
                }
                break;
            }
        }
예제 #10
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow    marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();
            DirectSellMultiWindow sellWindow   = Cache.Instance.DirectEve.Windows.OfType <DirectSellMultiWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnSellItemFinished != null)
                {
                    OnSellItemFinished(_item, _sold);
                }
                break;

            case State.Begin:
                // Close the market window if there is one
                if (marketWindow != null)
                {
                    marketWindow.Close();
                }

                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    _lastAction = DateTime.UtcNow;

                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    Logging.Log("SellItem:Process", "Market window is not ready", Logging.White);
                    break;
                }

                Logging.Log("SellItem:Process", "Opening Market", Logging.White);
                _state = State.LoadItem;

                break;

            case State.LoadItem:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    Logging.Log("SellItem:Process", "Load orders for TypeId - " + _item.TypeId.ToString(), Logging.White);

                    if (marketWindow.DetailTypeId != _item.TypeId)
                    {
                        if (marketWindow.LoadTypeId(_item.TypeId))
                        {
                            _state = State.GetPrice;
                        }
                    }

                    break;
                }
                else
                {
                    Logging.Log("SellItem:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.GetPrice:
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        Logging.Log("SellItem:Process", "Market window is not ready", Logging.White);
                        break;
                    }

                    if (marketWindow.DetailTypeId != _item.TypeId)
                    {
                        _state = State.LoadItem;
                        break;
                    }

                    List <DirectOrder> sellOrders     = marketWindow.SellOrders.OrderBy(o => o.Price).Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList();
                    List <DirectOrder> buyOrders      = marketWindow.BuyOrders.OrderByDescending(o => o.Price).Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList();
                    DirectOrder        firstSellOrder = sellOrders.FirstOrDefault();
                    DirectOrder        firstBuyOrder  = buyOrders.FirstOrDefault();

                    if (firstSellOrder != null)
                    {
                        sellOrders.Remove(firstSellOrder);
                        DirectOrder secondSellOrder = sellOrders.FirstOrDefault();

                        if (secondSellOrder != null)
                        {
                            decimal priceDifference    = decimal.Parse(secondSellOrder.Price.ToString()) - decimal.Parse(firstSellOrder.Price.ToString());
                            decimal priceDifferencePct = priceDifference / decimal.Parse(firstSellOrder.Price.ToString());
                            if (priceDifferencePct > 0.05m || priceDifference > 5000000)
                            {
                                // Check if the first buy order is close enough to the sell order that we no longer want to sell, otherwise the jump between the two sell orders doesn't matter.
                                // If there is no first buy order then create the order anyway
                                if (firstBuyOrder != null && firstSellOrder.Price / firstBuyOrder.Price < 1.5)
                                {
                                    Logging.Log("SellItem:Process", "No sale, price difference between the first two orders is too high Pct - " + priceDifferencePct + " Diff - " + priceDifference, Logging.White);
                                    _state = State.Done;
                                    break;
                                }
                            }
                        }

                        _price = double.Parse((decimal.Parse(firstSellOrder.Price.ToString()) - 0.01m).ToString());
                        _state = State.OpenSellWindow;

                        Logging.Log("SellItem:Process", "Lowest sell price, Name - " + _item.Name + " Price - " + _price, Logging.White);
                    }
                    else
                    {
                        Logging.Log("SellItem:Process", "No current sell orders, can't create lowest order for Name - " + _item.Name, Logging.White);
                        _state = State.Done;
                    }
                }
                else
                {
                    Logging.Log("SellItem:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.OpenSellWindow:

                _sellWindowNotReadyCount = 0;

                if (Cache.Instance.DirectEve.OpenSellItems(_item) == true)
                {
                    Logging.Log("SellItem:Process", "Opening sell window for Name - " + _item.Name, Logging.White);
                    if (_createOrder)
                    {
                        _state = State.SetPrice;
                    }
                    else
                    {
                        _state = State.SellItem;
                    }
                }
                else
                {
                    Logging.Log("SellItem:Process", "Failed to open sell window for Name - " + _item.Name, Logging.White);
                    _state = State.Done;
                }

                break;

            case State.SetPrice:
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (sellWindow != null)
                {
                    if (!sellWindow.IsReady)
                    {
                        _sellWindowNotReadyCount++;
                        Logging.Log("SellItem:Process", "Sell window is not ready", Logging.White);

                        if (_sellWindowNotReadyCount >= 5)
                        {
                            Logging.Log("SellItem:Process", "Something is wrong trying to sell this item, quitting the sell", Logging.White);
                            _state = State.Done;
                        }

                        break;
                    }

                    sellWindow.SetPrice(_item.ItemId, _price);

                    Logging.Log("SellItem:Process", "Sell window setting price to " + _price, Logging.White);
                    _state = State.SellItem;
                }
                else
                {
                    Logging.Log("SellItem:Process", "Sell Window is not open going back to open sell window state", Logging.White);
                    _state = State.OpenSellWindow;
                }

                break;

            case State.SellItem:
                if (sellWindow != null)
                {
                    if (!sellWindow.IsReady)
                    {
                        _sellWindowNotReadyCount++;
                        Logging.Log("SellItem:Process", "Sell window is not ready", Logging.White);

                        if (_sellWindowNotReadyCount >= 5)
                        {
                            _state = State.OpenSellWindow;
                        }

                        break;
                    }

                    sellWindow.SellItems();

                    Logging.Log("SellItem:Process", "Selling item Name - " + _item.Name, Logging.White);

                    _sold = true;

                    _state = State.Done;
                }
                else
                {
                    Logging.Log("SellItem:Process", "Sell Window is not open going back to open sell window state", Logging.White);
                    _state = State.OpenSellWindow;
                }

                break;
            }
        }
예제 #11
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnBuyItemFinished != null)
                {
                    OnBuyItemFinished(_typeId, _createOrder);
                }
                break;

            case State.Begin:

                // Close the market window if there is one
                if (marketWindow != null)
                {
                    marketWindow.Close();
                }
                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    _lastAction = DateTime.UtcNow;

                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    Logging.Log("BuyItem:Process", "Market window is not ready", Logging.White);
                    break;
                }

                Logging.Log("BuyItem:Process", "Opening Market", Logging.White);
                _state = State.LoadItem;

                break;

            case State.LoadItem:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    Logging.Log("BuyItem:Process", "Load orders for TypeId - " + _typeId.ToString(), Logging.White);

                    if (marketWindow.DetailTypeId != _typeId)
                    {
                        if (marketWindow.LoadTypeId(_typeId))
                        {
                            if (_createOrder == true)
                            {
                                _state = State.CreateOrder;
                            }
                            else
                            {
                                _state = State.BuyItem;
                            }
                        }
                    }

                    break;
                }
                else
                {
                    Logging.Log("BuyItem:Process", "Market Window is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.CreateOrder:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        Logging.Log("BuyItem:Process", "Market window is not ready", Logging.White);
                        break;
                    }

                    if (marketWindow.DetailTypeId != _typeId)
                    {
                        _state = State.LoadItem;
                        break;
                    }

                    List <DirectOrder> buyOrders  = marketWindow.BuyOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList();
                    List <DirectOrder> sellOrders = marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList();

                    DirectOrder highestBuyOrder = buyOrders.OrderByDescending(o => o.Price).FirstOrDefault();
                    DirectOrder lowestSellOrder = sellOrders.OrderBy(o => o.Price).FirstOrDefault();
                    if (highestBuyOrder != null)
                    {
                        bool createBuyOrder = (lowestSellOrder == null);

                        if (lowestSellOrder != null)
                        {
                            double profit    = lowestSellOrder.Price - highestBuyOrder.Price;
                            double tax       = lowestSellOrder.Price * .01 + highestBuyOrder.Price * 0.015;
                            double profitPct = lowestSellOrder.Price / highestBuyOrder.Price;

                            if ((profit < 10000000 && profitPct > 1.50) || (profit >= 10000000 && tax < profit * 0.25))
                            {
                                createBuyOrder = true;
                            }
                        }

                        if (createBuyOrder == true)
                        {
                            double price = double.Parse((decimal.Parse(highestBuyOrder.Price.ToString()) + 0.01m).ToString());
                            if (Cache.Instance.DirectEve.Session.StationId != null)
                            {
                                Cache.Instance.DirectEve.Buy((int)Cache.Instance.DirectEve.Session.StationId, _typeId, price, _volume, DirectOrderRange.Station, 1, 90);
                            }
                        }
                    }
                    _state = State.Done;
                }

                break;

            case State.BuyItem:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5)
                {
                    break;
                }

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        Logging.Log("BuyItem:Process", "Market window is not ready", Logging.White);
                        break;
                    }

                    if (marketWindow.DetailTypeId != _typeId)
                    {
                        _state = State.LoadItem;
                        break;
                    }

                    List <DirectOrder> orders = marketWindow.SellOrders.Where(o => o.StationId == Cache.Instance.DirectEve.Session.StationId).ToList();

                    DirectOrder order = orders.OrderBy(o => o.Price).FirstOrDefault();
                    if (order != null)
                    {
                        // Calculate how much we still need
                        if (order.VolumeEntered >= _volume)
                        {
                            order.Buy(_volume, DirectOrderRange.Station);
                            _state = State.WaitForItems;
                        }
                        else
                        {
                            order.Buy(_volume, DirectOrderRange.Station);
                            _volume = _volume - order.VolumeEntered;
                            Logging.Log("BuyItem:Process", "Missing " + Convert.ToString(_volume) + " units", Logging.White);
                            _returnBuy = true;
                            _state     = State.WaitForItems;
                        }
                    }
                }

                break;

            case State.WaitForItems:
                // Wait 5 seconds after moving
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 5)
                {
                    break;
                }

                // Close the market window if there is one
                if (marketWindow != null)
                {
                    marketWindow.Close();
                }

                if (_returnBuy)
                {
                    Logging.Log("BuyItem:Process", "Return Buy", Logging.White);
                    _returnBuy = false;
                    _state     = State.OpenMarket;
                    break;
                }

                Logging.Log("BuyItem:Process", "Done", Logging.White);
                _state = State.Done;

                break;
            }
        }