Example #1
0
    public IEnumerator Push(WorldUtils.Direction direction, int distance)
    {
        TilemapNavigator navigator = TilemapNavigator.Instance;
        Vector3Int       step      = new Dictionary <WorldUtils.Direction, Vector3Int> {
            { WorldUtils.Direction.Up, Vector3Int.up },
            { WorldUtils.Direction.Down, Vector3Int.down },
            { WorldUtils.Direction.Left, Vector3Int.left },
            { WorldUtils.Direction.Right, Vector3Int.right },
        }[direction];

        Vector3Int?positionAfterPush = null;

        for (int i = 1; i <= distance; i++)
        {
            Vector3Int testedSpot = CellPosition + step * i;
            if (navigator.IsTileWalkable(testedSpot) && !navigator.IsTileTaken(testedSpot))
            {
                positionAfterPush = testedSpot;
            }
            else
            {
                break;
            }
        }

        if (positionAfterPush.HasValue)
        {
            yield return(StartCoroutine(Move(positionAfterPush.Value, 15, true)));
        }
    }
Example #2
0
    private SerializableDictionary <Vector3Int, AttackPatternField> CalculateStraightRange(SkillConfig config)
    {
        TilemapNavigator navigator = TilemapNavigator.Instance;

        List <Vector3Int> directions = new List <Vector3Int>()
        {
            Vector3Int.up,
            Vector3Int.down,
            Vector3Int.left,
            Vector3Int.right,
        };

        SerializableDictionary <Vector3Int, AttackPatternField> resultPattern =
            new SerializableDictionary <Vector3Int, AttackPatternField>()
        {
            { attackerUnit.CellPosition, AttackPatternField.Player }
        };

        foreach (Vector3Int direction in directions)
        {
            for (int step = 1; step <= config.straightRange; step++)
            {
                Vector3Int cellPos = attackerUnit.CellPosition + direction * step;

                if (!navigator.IsTileWalkable(cellPos))
                {
                    break;
                }
                if (navigator.IsTileTaken(cellPos))
                {
                    resultPattern.Add(cellPos, AttackPatternField.On);
                    break;
                }
                resultPattern.Add(cellPos, AttackPatternField.On);
            }
        }

        return(resultPattern);
    }