Exemplo n.º 1
0
        public void OnFrame(object sender, EventArgs e)
        {
            if (!DirectEve.Instance.Session.IsReady)
            {
                return;
            }

            InitializeTraveler();

            if (lpstoreRe)
            {
                ResfreshLPI();
            }

            if (RequiredCom)
            {
                Required();
            }

            Text = "Questor Manager [" + DirectEve.Instance.Me.Name + "]";


            if (Paused)
            {
                return;
            }

            switch (State)
            {
            case State.Idle:

                if (Start)
                {
                    Logging.Log("Traveler: Start");
                    State = State.NextAction;
                }

                break;

            case State.NextAction:

                if (DateTime.Now.Subtract(_lastAction).TotalSeconds < 3)
                {
                    break;
                }

                if (LstTask.Items.Count <= 0)
                {
                    Logging.Log("Traveler: Finish");
                    LblStatus.Text = "Finish";
                    BttnStart.Text = "Start";
                    State          = State.Idle;
                    Start          = false;
                    break;
                }


                if ("Traveler" == LstTask.Items[0].Text)
                {
                    _destination = LstTask.Items[0].Tag;
                    State        = State.Traveler;
                    break;
                }

                if ("CmdLine" == LstTask.Items[0].Text)
                {
                    LblStatus.Text = LstTask.Items[0].Text + ":-:" + LstTask.Items[0].SubItems[1].Text;
                    State          = State.CmdLine;
                    break;
                }

                if ("BuyLPI" == LstTask.Items[0].Text)
                {
                    LblStatus.Text = LstTask.Items[0].Text + ":-:" + LstTask.Items[0].SubItems[1].Text;
                    State          = State.BuyLPI;
                    break;
                }

                if ("ValueDump" == LstTask.Items[0].Text)
                {
                    LblStatus.Text = LstTask.Items[0].Text + ":-:" + LstTask.Items[0].SubItems[1].Text;
                    State          = State.ValueDump;
                    break;
                }

                if ("MakeShip" == LstTask.Items[0].Text)
                {
                    LblStatus.Text = LstTask.Items[0].Text + ":-:" + LstTask.Items[0].SubItems[1].Text;
                    State          = State.MakeShip;
                    break;
                }

                if ("Drop" == LstTask.Items[0].Text)
                {
                    LblStatus.Text = LstTask.Items[0].Text + ":-:" + LstTask.Items[0].SubItems[1].Text;
                    State          = State.Drop;
                    break;
                }

                if ("Grab" == LstTask.Items[0].Text)
                {
                    LblStatus.Text = LstTask.Items[0].Text + ":-:" + LstTask.Items[0].SubItems[1].Text;
                    State          = State.Grab;
                    break;
                }

                if ("Buy" == LstTask.Items[0].Text)
                {
                    LblStatus.Text = LstTask.Items[0].Text + ":-:" + LstTask.Items[0].SubItems[1].Text;
                    State          = State.Buy;
                    break;
                }

                if ("Sell" == LstTask.Items[0].Text)
                {
                    LblStatus.Text = LstTask.Items[0].Text + ":-:" + LstTask.Items[0].SubItems[1].Text;
                    State          = State.Sell;
                    break;
                }

                break;


            case State.CmdLine:

                Logging.Log("CmdLine: " + LstTask.Items[0].SubItems[1].Text);
                LavishScript.ExecuteCommand(LstTask.Items[0].SubItems[1].Text);
                LstTask.Items.Remove(LstTask.Items[0]);
                _lastAction = DateTime.Now;
                State       = State.NextAction;

                break;


            case State.BuyLPI:


                if (_buylpi.State == StateBuyLPI.Idle)
                {
                    _buylpi.Item = Convert.ToInt32(LstTask.Items[0].Tag);
                    _buylpi.Unit = Convert.ToInt32(LstTask.Items[0].SubItems[2].Text);
                    Logging.Log("BuyLPI: Begin");
                    _buylpi.State = StateBuyLPI.Begin;
                }


                _buylpi.ProcessState();


                if (_buylpi.State == StateBuyLPI.Done)
                {
                    Logging.Log("BuyLPI: Done");
                    _buylpi.State = StateBuyLPI.Idle;
                    LstTask.Items.Remove(LstTask.Items[0]);
                    _lastAction = DateTime.Now;
                    State       = State.NextAction;
                }

                break;


            case State.ValueDump:


                if (chkUpdateMineral.Checked)
                {
                    chkUpdateMineral.Checked = false;
                    _valuedump.State         = ValueDumpState.CheckMineralPrices;
                }


                if (_valuedump.State == ValueDumpState.Idle)
                {
                    Logging.Log("ValueDump: Begin");
                    _valuedump.State = ValueDumpState.Begin;
                }


                _valuedump.ProcessState();


                if (_valuedump.State == ValueDumpState.Done)
                {
                    Logging.Log("ValueDump: Done");
                    _valuedump.State = ValueDumpState.Idle;
                    ProcessItems();
                    LstTask.Items.Remove(LstTask.Items[0]);
                    _lastAction = DateTime.Now;
                    State       = State.NextAction;
                }

                break;

            case State.MakeShip:

                var shipHangar = DirectEve.Instance.GetShipHangar();
                if (shipHangar.Window == null)
                {
                    // No, command it to open
                    DirectEve.Instance.ExecuteCommand(DirectCmd.OpenShipHangar);
                    break;
                }

                if (!shipHangar.IsReady)
                {
                    break;
                }

                var ships = DirectEve.Instance.GetShipHangar().Items;
                foreach (var ship in ships.Where(ship => ship.GivenName == txtNameShip.Text))
                {
                    Logging.Log("MakeShip: Making [" + ship.GivenName + "] active");

                    ship.ActivateShip();
                    LstTask.Items.Remove(LstTask.Items[0]);
                    _lastAction = DateTime.Now;
                    State       = State.NextAction;
                    break;
                }


                break;


            case State.Buy:


                if (_buy.State == StateBuy.Idle)
                {
                    _buy.Item = Convert.ToInt32(LstTask.Items[0].Tag);
                    _buy.Unit = Convert.ToInt32(LstTask.Items[0].SubItems[2].Text);
                    Logging.Log("Buy: Begin");
                    _buy.State = StateBuy.Begin;
                }


                _buy.ProcessState();


                if (_buy.State == StateBuy.Done)
                {
                    Logging.Log("Buy: Done");
                    _buy.State = StateBuy.Idle;
                    LstTask.Items.Remove(LstTask.Items[0]);
                    _lastAction = DateTime.Now;
                    State       = State.NextAction;
                }

                break;

            case State.Sell:

                _sell.Item = Convert.ToInt32(LstTask.Items[0].Tag);
                _sell.Unit = Convert.ToInt32(LstTask.Items[0].SubItems[2].Text);

                if (_sell.State == StateSell.Idle)
                {
                    Logging.Log("Sell: Begin");
                    _sell.State = StateSell.Begin;
                }

                _sell.ProcessState();


                if (_sell.State == StateSell.Done)
                {
                    Logging.Log("Sell: Done");
                    _sell.State = StateSell.Idle;
                    LstTask.Items.Remove(LstTask.Items[0]);
                    _lastAction = DateTime.Now;
                    State       = State.NextAction;
                }
                break;

            case State.Drop:

                _drop.Item   = Convert.ToInt32(LstTask.Items[0].Tag);
                _drop.Unit   = Convert.ToInt32(LstTask.Items[0].SubItems[2].Text);
                _drop.Hangar = LstTask.Items[0].SubItems[3].Text;

                if (_drop.State == StateDrop.Idle)
                {
                    Logging.Log("Drop: Begin");
                    _drop.State = StateDrop.Begin;
                }

                _drop.ProcessState();


                if (_drop.State == StateDrop.Done)
                {
                    Logging.Log("Drop: Done");
                    _drop.State = StateDrop.Idle;
                    LstTask.Items.Remove(LstTask.Items[0]);
                    _lastAction = DateTime.Now;
                    State       = State.NextAction;
                }


                break;

            case State.Grab:

                _grab.Item   = Convert.ToInt32(LstTask.Items[0].Tag);
                _grab.Unit   = Convert.ToInt32(LstTask.Items[0].SubItems[2].Text);
                _grab.Hangar = LstTask.Items[0].SubItems[3].Text;


                if (_grab.State == StateGrab.Idle)
                {
                    Logging.Log("Grab: Begin");
                    _grab.State = StateGrab.Begin;
                }

                _grab.ProcessState();


                if (_grab.State == StateGrab.Done)
                {
                    Logging.Log("Grab: Done");
                    _grab.State = StateGrab.Idle;
                    LstTask.Items.Remove(LstTask.Items[0]);
                    _lastAction = DateTime.Now;
                    State       = State.NextAction;
                }

                break;

            case State.Traveler:


                // We are warping
                if (DirectEve.Instance.Session.IsInSpace && DirectEve.Instance.ActiveShip.Entity != null && DirectEve.Instance.ActiveShip.Entity.IsWarping)
                {
                    return;
                }

                var travelerDestination = _traveler.Destination;
                if (_destination == null)
                {
                    travelerDestination = null;
                }

                if (_destination is DirectBookmark)
                {
                    if (!(travelerDestination is BookmarkDestination) || (travelerDestination as BookmarkDestination).BookmarkId != (_destination as DirectBookmark).BookmarkId)
                    {
                        travelerDestination = new BookmarkDestination(_destination as DirectBookmark);
                    }
                }

                if (_destination is DirectSolarSystem)
                {
                    if (!(travelerDestination is SolarSystemDestination) || (travelerDestination as SolarSystemDestination).SolarSystemId != (_destination as DirectSolarSystem).Id)
                    {
                        travelerDestination = new SolarSystemDestination((_destination as DirectSolarSystem).Id);
                    }
                }

                if (_destination is DirectStation)
                {
                    if (!(travelerDestination is StationDestination) || (travelerDestination as StationDestination).StationId != (_destination as DirectStation).Id)
                    {
                        travelerDestination = new StationDestination((_destination as DirectStation).Id);
                    }
                }

                // Check to see if destination changed, since changing it will set the traveler to Idle
                if (_traveler.Destination != travelerDestination)
                {
                    _traveler.Destination = travelerDestination;
                }

                _traveler.ProcessState();

                // Record number of jumps
                _jumps = DirectEve.Instance.Navigation.GetDestinationPath().Count;

                // Arrived at destination
                if (_destination != null && _traveler.State == TravelerState.AtDestination)
                {
                    Logging.Log("Arived at destination");

                    _traveler.Destination = null;
                    _destination          = null;
                    LstTask.Items.Remove(LstTask.Items[0]);
                    _lastAction = DateTime.Now;
                    State       = State.NextAction;
                }

                // An error occured, reset traveler
                if (_traveler.State == TravelerState.Error)
                {
                    if (_traveler.Destination != null)
                    {
                        Logging.Log("Stopped traveling, Traveler threw an error...");
                    }

                    _destination          = null;
                    _traveler.Destination = null;
                    Start = false;
                    State = State.Idle;
                }
                break;
            }
        }