Exemplo n.º 1
0
        /// <summary>
        ///	Moves to a Waypoint until within distance
        /// </summary>
        /// <param name="distance">stop/return if within distance</param>
        /// <param name="stoprunning">before exiting, stop running</param>
        /// <param name="stopondamage">stop running when the player is damaged</param>
        public void MoveTo(float distance, bool stoprunning, bool stopondamage)
        {
            if (_ak.ZDistance(_ak.gPlayerXCoord, _ak.gPlayerYCoord, _ak.gPlayerZCoord, _mX, _mY, _mZ) > distance)
            {
                _ak.StartRunning();
            }
            int lasthealth = _ak.PlayerHealth;

            while (_ak.ZDistance(_ak.gPlayerXCoord, _ak.gPlayerYCoord, _ak.gPlayerZCoord, _mX, _mY, _mZ) > distance)
            {
                if (stopondamage && _ak.PlayerHealth < lasthealth)
                {
                    _ak.StopRunning();
                    return;
                }
                lasthealth = _ak.PlayerHealth;

                //on slow machines (mine!) turnToHeading this often is bad, so lets only turn if we
                // are really facing the wrong way - more than 15 degrees off of correct heading
                if (Math.Abs(_ak.FindHeading(_ak.gPlayerXCoord, _ak.gPlayerYCoord, _mX, _mY) - _ak.PlayerDir) > 5)
                {
                    _ak.TurnToHeading(_ak.FindHeading(_ak.gPlayerXCoord, _ak.gPlayerYCoord, _mX, _mY));
                }

                //Give the game process a chance at the cpu so it can respond
                System.Threading.Thread.Sleep(150);
            }

            if (stoprunning)
            {
                _ak.StopRunning();
            }
        }
Exemplo n.º 2
0
        private void btnStart_Click(object sender, System.EventArgs e)
        {
            if (cbxPatrolAreas.SelectedIndex == -1)
            {
                return;
            }

            PatrolArea patrolarea;

            try
            {
                patrolarea = _patrolareas.GetPatrolArea(cbxPatrolAreas.SelectedItem.ToString());
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message, "Load Area Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // make sure this travel list has waypoints defined
            if (patrolarea.NumWaypoints < 1)
            {
                MessageBox.Show("There are no waypoints defined for this Travel Path / Patrol Area", "No Waypoints Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // make sure the user selected a destination
            if (cbxDestinations.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a Destination!", "No Destination Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //lets see if the user is far away from the selected path/area and warn them
            Waypoint wpt  = patrolarea.FindClosest(FindDirection());            //also sets next point in waypoint internal list iterations
            double   dist = _ak.ZDistance(_ak.gPlayerXCoord, _ak.gPlayerYCoord, _ak.gPlayerZCoord, wpt.X, wpt.Y, wpt.Z);

            if (dist > 5000)
            {
                if (MessageBox.Show("You are far away from this Waypoint Path / Patrol Area, are you sure you want to run to this location?", "Distance Warning",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }

            Interaction.AppActivate(_ak.GameProcess);
            Thread.Sleep(750);

            //tell movement thread to run
            _bKeepRunning = true;
        }
Exemplo n.º 3
0
        private void btnAddWaypoint_Click(object sender, System.EventArgs e)
        {
            if (cbxPatrolAreas.SelectedIndex == -1)
            {
                MessageBox.Show("Please select the Patrol Area first.", "Add Waypoint Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            PatrolArea patrolarea;

            try
            {
                patrolarea = _patrolareas.GetPatrolArea(cbxPatrolAreas.SelectedItem.ToString());
            }
            catch (Exception E)
            {
                MessageBox.Show(E.Message, "Load Area Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (_ak.GameProcess == 0)
            {
                return;
            }

            //generate default waypoint name
            string itemName = "no name";

            if (sender == null)            //auto add
            {
                itemName = "auto add";
            }

            // add the current players location to the patrol area waypoint list
            patrolarea.AddWaypoint(_ak.gPlayerXCoord, _ak.gPlayerYCoord, _ak.gPlayerZCoord, itemName);

            //create a new waypoint object for storing in the ListViewItem
            Waypoint wpt = new Waypoint(_ak, patrolarea.GetNewestWaypoint());

            //create a ListViewItem, set its display strings, and attach the waypoint object
            ListViewItem lvi = new ListViewItem(itemName, 0);

            lvi.SubItems.Add(_ak.gPlayerXCoord.ToString("N"));
            lvi.SubItems.Add(_ak.gPlayerYCoord.ToString("N"));
            if (_lastAddedX != 0)
            {
                lvi.SubItems.Add(_ak.ZDistance(_ak.gPlayerXCoord, _ak.gPlayerYCoord, _ak.gPlayerZCoord, _lastAddedX, _lastAddedY, _lastAddedZ).ToString());
            }
            lvi.Tag = wpt;

            //add the ListViewItem to our listview
            lvwPatrolArea.Items.Add(lvi);

            //store this location for Dist calc next time


            //if not auto add, put new item in edit mode so user sees they can name it
            if (sender != null)
            {
                lvi.BeginEdit();
            }
        }