public static void MoveCharacter(int characterId, MapPosition destination)
    {
        Character   current          = CharacterManager.ActiveCharacters[characterId];
        MapPosition previousPosition = current.Position;

        RawMapManager.Map[current.Position.Z][current.Position.X].CharacterId = -1;
        RawMapManager.Map[destination.Z][destination.X].CharacterId           = characterId;
        CharacterManager.ActiveCharacters[characterId].Position = destination;
        CharacterManager.ActiveCharacters[characterId].Parent.transform.position = new Vector3(destination.X, 0, destination.Z);

        CharacterManager.ActiveCharacters[characterId].CurrentEnergy -=
            MapAlgorithms.ManhattanDistance(previousPosition, destination);
    }
    IEnumerator DisplayPositionUi()
    {
        int       currentId = TurnManager.ProgressQueue.Peek().CharacterId;
        Character current   = CharacterManager.ActiveCharacters[currentId];

        List <AlgorithmTile> possiblePositions;

        if (currentPosSubstate == (int)PosSubstate.Attack)
        {
            possiblePositions = MapAlgorithms.ResultMapToAlgorithmTileList(
                MapAlgorithms.BfsReturnRange(RawMapManager.Map, current.Position, 1, false, true)
                );
        }
        else
        {
            possiblePositions = MapAlgorithms.ResultMapToAlgorithmTileList(
                MapAlgorithms.BfsReturnRange(RawMapManager.Map, current.Position, Math.Min(current.Movement, current.CurrentEnergy), true, true)
                );
        }


        positionButtons = new List <GameObject>();

        for (int i = 0; i < possiblePositions.Count; i++)
        {
            GameObject newButton = Instantiate(tileButton);
            newButton.transform.SetParent(worldCanvas.transform, false);
            RectTransform buttonRectTransform = newButton.GetComponent <RectTransform>();
            buttonRectTransform.anchorMax        = buttonRectTransform.anchorMin = buttonRectTransform.pivot = Vector2.zero;
            buttonRectTransform.anchoredPosition = new Vector2(possiblePositions[i].Position.X, possiblePositions[i].Position.Z);

            newButton.GetComponent <ButtonHandler>().id = i;
            positionButtons.Add(newButton);
        }

        hasSelectedPosition = false;
        selectedPositionId  = -1;
        confirmButton.SetActive(true);
        yield return(new WaitUntil(() => hasSelectedPosition));

        hasFinishedControlling = true;
    }
    private static void Move(int characterId)
    {
        // Find spot to move to that is open and doesn't have anybody else.
        Character current = CharacterManager.ActiveCharacters[characterId];

        List <AlgorithmTile> possiblePositions = MapAlgorithms.ResultMapToAlgorithmTileList(
            MapAlgorithms.BfsReturnRange(RawMapManager.Map, current.Position, Math.Min(current.Movement, current.CurrentEnergy), true, true)
            );

        // Randomize list
        for (int i = possiblePositions.Count - 1; i >= 1; i--)
        {
            int           swap = Random.Range(0, i);
            AlgorithmTile tmp  = possiblePositions[i];
            possiblePositions[i]    = possiblePositions[swap];
            possiblePositions[swap] = tmp;
        }

        MapPosition newPosition = current.Position;

        for (int i = 0; i < possiblePositions.Count; i++)
        {
            if (RawMapManager.Map[possiblePositions[i].Position.Z][possiblePositions[i].Position.X].TileId == 0 &&
                RawMapManager.Map[possiblePositions[i].Position.Z][possiblePositions[i].Position.X].CharacterId == -1)
            {
                newPosition = possiblePositions[i].Position;
                break;
            }
        }

/*	    string message = current.Position.ToString();
 *          message += Environment.NewLine;
 *          foreach (var i in possiblePositions) {
 *                  message += $", {i}";
 *          }
 *          print(message);*/

        ActionManager.MoveCharacter(characterId, newPosition);
    }
    public static List <AlgorithmTile> GetPossiblePositions(int characterId)
    {
        Character current = CharacterManager.ActiveCharacters[characterId];

        if (UiManager.selectedAbilityId == -1)   // Move
        {
            return(MapAlgorithms.ResultMapToAlgorithmTileList(
                       MapAlgorithms.BfsReturnRange(RawMapManager.Map, current.Position, Math.Min(current.Movement, current.CurrentEnergy), true, true)
                       ));
        }
        else if (UiManager.selectedAbilityId == 0)
        {
            return(MapAlgorithms.ResultMapToAlgorithmTileList(
                       MapAlgorithms.BfsReturnRange(RawMapManager.Map, current.Position, 1, false, true)
                       ));
        }
        else
        {
            return(MapAlgorithms.ResultMapToAlgorithmTileList(
                       MapAlgorithms.BfsReturnRange(RawMapManager.Map, current.Position, 2, false, true)
                       ));
        }
    }