Exemplo n.º 1
0
    public List <Vector2Int> BoundedLine(Vector2Int src, Vector2Int tgt)
    {
        var rangeLine = BresenhamUtils.CalculateLine(src, tgt);
        int firstIdx  = 0;
        int distance  = 0;

        if (rangeLine.Count < 2)
        {
            return(rangeLine);
        }

        firstIdx = 0;
        distance = _mapController.Distance(src, rangeLine[firstIdx]);
        while (firstIdx < rangeLine.Count && distance < _rangeData.MinRange)
        {
            firstIdx++;
            if (firstIdx < rangeLine.Count)
            {
                distance = _mapController.Distance(src, rangeLine[firstIdx]);
            }
        }

        int lastIdx = rangeLine.Count - 1;

        while (lastIdx > firstIdx && distance > _rangeData.MaxRange)
        {
            lastIdx--;
            distance = _mapController.Distance(src, rangeLine[lastIdx]);
        }
        return(rangeLine.GetRange(firstIdx, lastIdx - firstIdx + 1));
    }
Exemplo n.º 2
0
    public void RefreshTargetView(MoveDirection dir)
    {
        var offset = MapController.CalculateMoveOffset(dir, Target);

        Target += offset;

        if (MapController.ValidCoords(new Vector3Int(Target.x, Target.y, 0)))
        {
            var targets = BresenhamUtils.CalculateLine(EntityController.Player.Coords, Target);
            EntityController.Player.BattleTrait.GetReachableStateForCoords(targets, out List <bool> targetOccluded);
            var targetPositions = targets.ConvertAll(x => MapController.WorldFromCoords(x));

            _viewInstance.RefreshLine(targetPositions, targetOccluded);
        }
        else
        {
            Target -= offset;
        }
    }