package pathgame.tilemap;

import pathgame.gameplay.PlayerAbilities;

public class Tiles
{

    public final static Tile GRASS = buildGrass();
    public final static Tile GRASS_WITH_STONE = buildGrass();
    public final static Tile GRASS_WITH_6_BUSHES = buildGrass();
    public final static Tile GRASS_WITH_3_BUSHES = buildGrass();
    public final static Tile GRASS_WITH_FLOWERS_1 = buildGrass();
    public final static Tile GRASS_WITH_FLOWERS_2 = buildGrass();
    public final static Tile GRASS_WITH_FLOWERS_3 = buildGrass();
    public final static Tile GRASS_WITH_FLOWERS_4 = buildGrass();
    public final static Tile GRASS_WITH_HILL = buildGrass();
    public final static Tile GRASS_WITH_EARTH = buildGrass();

    public final static Tile[] GRASS_VARIANTS = new Tile[]
    {
        GRASS, GRASS_WITH_STONE, GRASS_WITH_6_BUSHES, GRASS_WITH_3_BUSHES,
        GRASS_WITH_FLOWERS_1, GRASS_WITH_FLOWERS_2, GRASS_WITH_FLOWERS_3,
        GRASS_WITH_FLOWERS_4, GRASS_WITH_HILL, GRASS_WITH_EARTH
    };

    public final static Tile FOREST = Tile.TileBuilder.create()
            .setEnergyCost(4)
            .setForestReplaceChance(0.0f)
            .setSpeedUp((p) -> p.getAbilities().getFasterForest())
            .pathHost()
            .build();
    public final static Tile SWAMP = buildSwamp();
    public final static Tile SWAMP_DECO = buildSwamp();
    public final static Tile SWAMP_TREE = buildSwamp();
    public final static Tile SHALLOW_WATER = Tile.TileBuilder.create()
            .setEnergyCost(6)
            .setForestReplaceChance(0.0f)
            .setSpeedUp((p) ->
            {
                int speedUp = p.getAbilities().getFasterShallowWater();
                if(p.isSailing())
                {
                    speedUp += 4;
                    if(p.getAbilities() == PlayerAbilities.SAILOR)
                    {
                        speedUp++;
                    }
                }
                return speedUp;
            })
            .noTown()
            .setRenderType(TileRenderType.WATER)
            .setType(TileType.SHALLOW_WATER)
            .build();
    public final static Tile DEEP_WATER = Tile.TileBuilder.create()
            .setEnergyCost(2)
            .setForestReplaceChance(0.0f)
            .setSpeedUp((p) -> p.getAbilities().getFasterDeepWater())
            .noTown()
            .setRenderType(TileRenderType.WATER)
            .setType(TileType.DEEP_WATER)
            .build();
    public final static Tile HILL = Tile.TileBuilder.create()
            .setEnergyCost(6)
            .setForestReplaceChance(0.5f)
            .setSpeedUp((p) -> p.getAbilities().getFasterHill())
            .pathHost()
            .build();
    public final static Tile MOUNTAIN = Tile.TileBuilder.create()
            .setEnergyCost(9)
            .setForestReplaceChance(0.0f)
            .setSpeedUp((p) -> p.getAbilities().getFasterMountain())
            .noTown()
            .build();
    public final static Tile TOWN = new TileTown();
    public final static Tile TOWN_BLOCKED_1 = buildBlockedTown();
    public final static Tile TOWN_BLOCKED_2 = buildBlockedTown();
    public final static Tile TOWN_BLOCKED_3 = buildBlockedTown();
    public final static Tile TOWN_BLOCKED_4 = buildBlockedTown();

    public final static Tile[] TOWN_BLOCKED = new Tile[]
    {
        TOWN_BLOCKED_1, TOWN_BLOCKED_2, TOWN_BLOCKED_3, TOWN_BLOCKED_4
    };

    public final static Tile PORT = new TilePort();

    public final static Tile buildGrass()
    {
        return Tile.TileBuilder.create()
                .setSpeedUp((p) -> p.getAbilities().getFasterGrass())
                .pathHost()
                .setEnergyCost(3)
                .build();
    }

    public final static Tile buildSwamp()
    {
        return Tile.TileBuilder.create()
                .setEnergyCost(5)
                .setForestReplaceChance(0.0f)
                .setRenderType(TileRenderType.SWAMP)
                .setSpeedUp((p) -> p.getAbilities().getFasterSwamp())
                .build();
    }

    public final static Tile buildBlockedTown()
    {
        return Tile.TileBuilder.create()
                .setForestReplaceChance(0.0f)
                .noTown()
                .build();
    }

    public final static Tile HOME_TOWN = new TileHomeTown();

    public final static Tile buildPath()
    {
        return Tile.TileBuilder.create()
                .setForestReplaceChance(0.0f)
                .path()
                .build();
    }

    public final static Tile PATH_N_E_S_W = buildPath();
    public final static Tile PATH_N_E_S = buildPath();
    public final static Tile PATH_N_E_W = buildPath();
    public final static Tile PATH_N_E = buildPath();
    public final static Tile PATH_N_S_W = buildPath();
    public final static Tile PATH_N_S = buildPath();
    public final static Tile PATH_N_W = buildPath();
    public final static Tile PATH_N = buildPath();
    public final static Tile PATH_E_S_W = buildPath();
    public final static Tile PATH_E_S = buildPath();
    public final static Tile PATH_E_W = buildPath();
    public final static Tile PATH_E = buildPath();
    public final static Tile PATH_S_W = buildPath();
    public final static Tile PATH_S = buildPath();
    public final static Tile PATH_W = buildPath();

    public final static Tile[] PATH = new Tile[]
    {
        PATH_N_E_S_W, PATH_N_E_S, PATH_N_E_W, PATH_N_E,
        PATH_N_S_W, PATH_N_S, PATH_N_W, PATH_N,
        PATH_E_S_W, PATH_E_S, PATH_E_W, PATH_E,
        PATH_S_W, PATH_S, PATH_W, GRASS
    };

    public static Tile getPath(boolean north, boolean east, boolean south, boolean west)
    {
        return PATH[(north ? 0 : 8) + (east ? 0 : 4) + (south ? 0 : 2) + (west ? 0 : 1)];
    }
}
