Beispiel #1
0
        internal void PathfindTo(int roomid)
        {
            if (Location == null || roomid == Location.Id || roomid < 0)
            {
                return;
            }

            CoreUI.Instance.LogPanel.Log("Constructing path for " + Account.Name + " to " + roomid);

            List <int> nodes = new List <int>();

            nodes = Pathfinder.BFS(Location.Id, roomid);

            if (nodes == null)
            {
                if (CoreUI.Instance.Settings.AutoTeleport ||
                    MessageBox.Show("The program cannot build a path from your current area to your chosen location.  Do you want to teleport to the nearest bar and try again?  Recommended 'Yes' unless you are in a separated area such as Stoneraven.\n\n(this option can be automatically enabled under the Attack tab)", "Pathfinding Error", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                    == DialogResult.Yes)
                {
                    CoreUI.Instance.LogPanel.Log(Account.Name + " teleporting...");

                    Account.Socket.Get("world.php?teleport=1");
                    RefreshRoom();
                    nodes = Pathfinder.BFS(Location.Id, roomid);
                }
                else
                {
                    CoreUI.Instance.StopAttacking(true);
                    return;
                }
                //DCErrorReport.Report(this, "Null nodes path (unfamiliar location); teleport attempt possible");
            }

            FollowPath(nodes);
        }
Beispiel #2
0
    private void Update()
    {
        if (canSetWalls == true)
        {
            SetBlocks();
        }
        else
        {
            GetNeighbors();
        }

        if (canSetStartAndGoal == true)
        {
            SetStartAndGoal();
        }

        if (startPathfinder == true)
        {
            if (pathfinder.pathfinderMode == Mode.BreadthFirstSearch)
            {
                StartCoroutine(pathfinder.BFS(nodes[yStart, xStart], nodes[yGoal, xGoal]));
            }
            else if (pathfinder.pathfinderMode == Mode.Dijkstra)
            {
                StartCoroutine(pathfinder.Dijkstra(nodes[yStart, xStart], nodes[yGoal, xGoal]));
            }
            else if (pathfinder.pathfinderMode == Mode.AStar)
            {
                StartCoroutine(pathfinder.AStar(nodes[yStart, xStart], nodes[yGoal, xGoal]));
            }
            startPathfinder = false;
        }
    }
Beispiel #3
0
        internal void Train()
        {
            if (!Account.NeedsLevel)
            {
                CoreUI.Instance.LogPanel.Log(Account.Name + " doesn't need leveling");
                return;
            }

            CoreUI.Instance.LogPanel.Log("Starting leveling for " + Account.Name);
            CoreUI.Instance.LogPanel.Log("Loading all possible bars...");

            mTrainRoomStart = Location.Id;

            List <List <int> > paths = new List <List <int> >();

            paths.Add(Pathfinder.BFS(Location.Id, 258)); // dustglass
            paths.Add(Pathfinder.BFS(Location.Id, 241)); // drunkenclam
            paths.Add(Pathfinder.BFS(Location.Id, 403)); //hardiron
            paths.Add(Pathfinder.BFS(Location.Id, 299)); //chuggers

            bool tmp = CoreUI.Instance.Settings.AutoTrain;

            CoreUI.Instance.Settings.AutoTrain = true;

            int shortest = 0;

            for (int i = 1; i < paths.Count; i++)
            {
                List <int> path = paths[i];
                if (path != null && path.Count < paths[shortest].Count)
                {
                    shortest = i;
                }
            }

            FollowPath(paths[shortest]);

            CoreUI.Instance.Settings.AutoTrain = tmp;
            Location.Train();

            if (Location.Trained)
            {
                CoreUI.Instance.LogPanel.Log(Account.Name + " has been leveled");
            }
            else
            {
                CoreUI.Instance.LogPanel.Log(Account.Name + " not leveled - can't find bartender");
            }
        }
Beispiel #4
0
    IEnumerator Think()
    {
        Node target = null;

        while (true)
        {
            // Refresh nodes (main building or "raft")
            var nodes = nodeAt.module.owner != null ? nodeAt.module.owner.allNodes : nodeAt.module.innerNodes;

            //Change need outside working loop...
            if (maxNeed != currentNeed)
            {
                Debug.Log($"Need changed from {currentNeed} to {maxNeed} for {this}");
                currentNeed = maxNeed;
                target      = null;
                path        = null;
            }

            //If we have a target and we are at it.
            if (target == nodeAt)
            {
                if (currentNeed != NeedType.None && currentNeed == nodeAt.needType)
                {
                    //If empty (free to use), occupy it and set relevant flags.
                    if (nodeAt.inUseBy == null)
                    {
                        bool blocksModule = _cfg.needDict[currentNeed].blocksModule;
                        if (blocksModule)
                        {
                            nodeAt.module.blocked = true;
                        }

                        nodeAt.inUseBy = this;                                                  //USE IT
                        float needValue;
                        while (needs.TryGetValue(currentNeed, out needValue) && needValue > 0f) //TODO: Or sleep interrupt
                        {
                            _coroutineStatus = "working";
                            yield return(null);                             //Wait (decrease in Update)
                        }
                        nodeAt.inUseBy = null;

                        if (blocksModule)
                        {
                            nodeAt.module.blocked = false;
                        }
                    }
                    else                        //If in use, cool down and recalc path
                    {
                        nodeCooldownSecs[nodeAt] = _cfg.beingUsedCooldownHours * Time.deltaTime / _cfg.secondsPerGameHour;
                        path   = null;
                        target = null;
                    }
                }
                else                    //Was idle walking, reset target
                {
                    path   = null;
                    target = null;
                }
            }

            // If has target and not a path, rebuild path and walk it
            // (until reach or path set to null from Update)
            if (target != null && path == null)
            {
                if (path == null)
                {
                    path = Pathfinder.BFS(nodeAt, target, IsNodeWalkable)
                           .Cast <Node>().ToList();
                    pathIndex = 0;

                    if (path.Count == 0)
                    {
                        path             = null;
                        _coroutineStatus = "Path error";
                        //Error? This shouldn't happen. At least should find nodeAt.
                    }
                    else
                    {
                        _coroutineStatus = "Path found";
                    }

                    yield return(null);

                    continue;
                }
            }

            if (target != null && path != null)
            {
                // Interpolate position until reached
                var delta = Vector3.zero;
                do
                {
                    var nextPosMain = path[pathIndex].mainPos;
                    var nextPos     = nodeAt.module.ownerLocalToWorld.MultiplyPoint(nextPosMain);
                    delta   = nextPos - this.transform.position;
                    delta.z = 0f;

                    if (delta.sqrMagnitude > _speed * _speed * Time.deltaTime * Time.deltaTime)
                    {
                        delta.Normalize();
                    }

                    transform.rotation  = Utils.RotationFromNormalizedDir(delta);
                    transform.position += delta * _speed * Time.deltaTime;
                    yield return(null);
                }while(path != null && delta.sqrMagnitude > 0.005f);

                // Remember node we reached
                if (path != null)
                {
                    SetNodeAt(path[pathIndex]);
                    pathIndex++;
                    if (pathIndex == path.Count)
                    {
                        path = null;                            //No more path.
                    }
                }
            }

            // If without target, find a target
            if (target == null)
            {
                if (currentNeed != nodeAt.needType)
                {
                    target = nodes
                             .Where(n => n.needType == currentNeed)
                             //TODO: Filter by cooldown? or IsWalkable??
                             .OrderBy(n => (n.mainPos - (Vector2)transform.localPosition).sqrMagnitude)
                             .FirstOrDefault()
                    ;

                    _coroutineStatus = "Walk purpose";
                }
                //If still null, find any node to walk to.
                if (target == null)
                {
                    target           = nodes.Choice();
                    _coroutineStatus = "Walk idle";
                }
            }

            yield return(null);
        }
    }