示例#1
0
    public static List <BattleUnit> GetUnitsInLocalAreaForActionEffect(int x, int y, Direction direction, ActionAreaType areaType, UnitActionEffect effect, BattleMap map)
    {
        List <BattleUnit> ret = new List <BattleUnit>();

        List <BattleMapTile> tiles = GetTilesInLocalAreaForActionEffect(x, y, direction, areaType, effect, map);

        foreach (var tile in tiles)
        {
            if (tile.unit != null)
            {
                ret.Add(tile.unit);
            }
        }

        return(ret);
    }
示例#2
0
    // Static logic


    public static List <BattleMapTile> GetTilesInLocalAreaForActionEffect(int x, int y, Direction direction, ActionAreaType areaType, UnitActionEffect effect, BattleMap map)
    {
        List <BattleMapTile> ret = new List <BattleMapTile>();

        // Area mask is always thought of as being rotated towards right
        if (direction == Direction.Right)
        {
            int minx = Mathf.Max(0, x - effect.areaCenterX);
            int maxx = Mathf.Min(map.width - 1, minx + effect.areaWidth - 1);
            int miny = Mathf.Max(0, y - effect.areaCenterY);
            int maxy = Mathf.Min(map.height - 1, miny + effect.areaHeight - 1);

            // We have to use these for calculating the correct index for the masks when the unit is too close to the edge od the map
            int minxh = -Mathf.Min(0, x - effect.areaCenterX);
            int minyh = -Mathf.Min(0, y - effect.areaCenterY);

            for (int i = minx; i <= maxx; ++i)
            {
                for (int j = miny; j <= maxy; ++j)
                {
                    if (effect.areaMask[j - miny + minyh][i - minx + minxh] == true)
                    {
                        ret.Add(map.tiles[j][i]);
                    }
                }
            }
        }
        // This is basically a complete 180 degree turn from the previous one
        else if (direction == Direction.Left)
        {
            int minx = Mathf.Max(0, x - (effect.areaWidth - effect.areaCenterX - 1));
            int maxx = Mathf.Min(map.width - 1, x + effect.areaCenterX);
            int miny = Mathf.Max(0, y - (effect.areaHeight - effect.areaCenterY - 1));
            int maxy = Mathf.Min(map.height - 1, y + effect.areaCenterY);

            // We have to use these for calculating the correct index for the masks when the unit is too close to the edge od the map
            int minxh = -Mathf.Min(0, x - (effect.areaWidth - effect.areaCenterX - 1));
            int minyh = -Mathf.Min(0, y - (effect.areaHeight - effect.areaCenterY - 1));

            for (int i = minx; i <= maxx; ++i)
            {
                for (int j = miny; j <= maxy; ++j)
                {
                    if (effect.areaMask[effect.areaHeight - (j - miny + minyh) - 1][effect.areaWidth - (i - minx + minxh) - 1] == true)
                    {
                        ret.Add(map.tiles[j][i]);
                    }
                }
            }
        }
        // This is a 90 degree rotation of the first one
        else if (direction == Direction.Down)
        {
            int minx = Mathf.Max(0, x - (effect.areaHeight - effect.areaCenterY - 1));
            int maxx = Mathf.Min(map.width - 1, x + effect.areaCenterY);
            int miny = Mathf.Max(0, y - effect.areaCenterX);
            int maxy = Mathf.Min(map.height - 1, miny + effect.areaWidth - 1);

            // We have to use these for calculating the correct index for the masks when the unit is too close to the edge od the map
            int minxh = -Mathf.Min(0, x - (effect.areaHeight - effect.areaCenterY - 1));
            int minyh = -Mathf.Min(0, y - effect.areaCenterX);

            for (int i = minx; i <= maxx; ++i)
            {
                for (int j = miny; j <= maxy; ++j)
                {
                    if (effect.areaMask[effect.areaHeight - (i - minx + minxh) - 1][j - miny + minyh] == true)
                    {
                        ret.Add(map.tiles[j][i]);
                    }
                }
            }
        }
        // This is a 270 degree rotation of the first one
        else if (direction == Direction.Up)
        {
            int minx = Mathf.Max(0, x - effect.areaCenterY);
            int maxx = Mathf.Min(map.width - 1, minx + effect.areaHeight - 1);
            int miny = Mathf.Max(0, y - (effect.areaWidth - effect.areaCenterX - 1));
            int maxy = Mathf.Min(map.height - 1, y + effect.areaCenterX);

            // We have to use these for calculating the correct index for the masks when the unit is too close to the edge od the map
            int minxh = -Mathf.Min(0, x - effect.areaCenterY);
            int minyh = -Mathf.Min(0, y - (effect.areaWidth - effect.areaCenterX - 1));

            for (int i = minx; i <= maxx; ++i)
            {
                for (int j = miny; j <= maxy; ++j)
                {
                    if (effect.areaMask[i - minx + minxh][effect.areaWidth - (j - miny + minyh) - 1] == true)
                    {
                        ret.Add(map.tiles[j][i]);
                    }
                }
            }
        }

        return(ret);
    }