public override async Task <bool> IsActive(GameManager gameManager, PathManager pathManager, AutoControllerState state)
    {
        GameManager closestGameManager = ClientManager.GetCurrentGameManager();
        int         minDistance        = Int32.MaxValue;
        bool        regroupRequired    = false;
        bool        allWithinRange     = true;
        MapTile     start = GetPlayerPosition(gameManager);

        foreach (GameManager manager in ClientManager.GetAllGameManagers())
        {
            if (!manager.Equals(gameManager))
            {
                MapTile goal = GetPlayerPosition(manager);
                Tuple <LinkedList <MapTile>, WarpDevice, int> mapPathInfo = await pathManager.GetMapPath(gameManager, start, goal);

                int  distance = mapPathInfo.Item3;
                bool sameArea = await pathManager.IsSameArea(gameManager, start, goal);

                if (distance > REGROUP_REQUIRED_DISTANCE)
                {
                    if (distance < minDistance)
                    {
                        minDistance        = distance;
                        closestGameManager = manager;
                    }
                    allWithinRange = false;
                }
                if (distance > REGROUP_REQUIRED_DISTANCE || !sameArea)
                {
                    regroupRequired = true;
                }
            }
        }
        if (closestGameManager != null)
        {
            PlayerManager player = closestGameManager.GetMainPlayerManager();
            state.SetTargetTile(GetPlayerPosition(closestGameManager, player));
            state.SetTarget(player);
        }
        if (regroupRequired && !allWithinRange)
        {
            MapTile safePoint = pathManager.GetSafePoint();
            Tuple <LinkedList <MapTile>, WarpDevice, int> mapPathInfo = await pathManager.GetMapPath(gameManager, start, safePoint);

            int distance = mapPathInfo.Item3;
            if (distance < minDistance)
            {
                state.SetTargetTile(safePoint);
                state.SetTarget(null);
            }
        }
        return(regroupRequired);
    }
    public override async Task <bool> IsActive(GameManager gameManager, PathManager pathManager, AutoControllerState state)
    {
        MapTile start = GetPlayerPosition(gameManager);
        int     map = start.Item1, minDistance = Int32.MaxValue;
        bool    targetFound = false;

        // TODO Sort players based on DistanceHeuristic first and loop through until the heuristic distance is more than the min actual distance.
        foreach (PlayerManager player in gameManager.GetAllPlayerManagers())
        {
            if (player.IsPlayerMob())
            {
                MapTile goal           = GetPlayerPosition(gameManager, player);
                int     simpleDistance = PathManager.DistanceHeuristic(start, goal);
                if (simpleDistance < minDistance)
                {
                    LinkedList <MapTile> walkPath = null;
                    if (await pathManager.TryGetWalkPath(gameManager, start, goal, player, value => walkPath = value))
                    {
                        int distance = walkPath.Count;
                        if (distance < minDistance)
                        {
                            minDistance = distance;
                            state.SetTargetTile(goal);
                            state.SetTarget(player);
                            targetFound = true;
                        }
                    }
                }
            }
        }
        return(targetFound);
    }
Beispiel #3
0
    public async override Task <bool> IsActive(GameManager gameManager, PathManager pathManager, AutoControllerState state)
    {
        await Task.Yield();

        GameManager currentManager = ClientManager.GetCurrentGameManager();

        if (!currentManager.Equals(gameManager))
        {
            PlayerManager player = currentManager.GetMainPlayerManager();
            state.SetTarget(player);
            state.SetTargetTile(GetPlayerPosition(currentManager, player));
            return(true);
        }
        return(false);
    }