package net.cobem.grizzly.habbohotel.games.battleball;

import gnu.trove.map.hash.THashMap;
import net.cobem.grizzly.habbohotel.rooms.Room;
import net.cobem.grizzly.habbohotel.rooms.items.FloorItem;
import net.cobem.grizzly.habbohotel.sessions.Session;

public class BattleBall_GameLogic {
    private Room Room;

    private BattleBall_TeamLogic RedTeam;
    private BattleBall_TeamLogic BlueTeam;
    private BattleBall_TeamLogic GreenTeam;
    private BattleBall_TeamLogic YellowTeam;

    private THashMap<Integer, FloorItem> Tiles = new THashMap<>();

    private BattleBall_TeamLogic[] TileOwners;

    private BattleBall_TeamLogic[] ColorCodes;

    public BattleBall_GameLogic(Room Room) {
        this.Room = Room;

        RedTeam = new BattleBall_TeamLogic(BattleBall_TeamType.Red);
        BlueTeam = new BattleBall_TeamLogic(BattleBall_TeamType.Blue);
        GreenTeam = new BattleBall_TeamLogic(BattleBall_TeamType.Green);
        YellowTeam = new BattleBall_TeamLogic(BattleBall_TeamType.Yellow);

        ColorCodes[0] = null;
        ColorCodes[1] = null;
        ColorCodes[2] = null;
        ColorCodes[3] = null;
        ColorCodes[4] = null;
    }

    private boolean initTiles() {
        for (FloorItem Item : this.Room.getFloors().values()) {
            if (Item.getBase().Interaction.equals("bb_patch")) {
                Tiles.put(Item.ID, Item);
            }
        }

        return true;
    }

    public boolean ownOrUpdateTile(Session Player, int ItemID) {
        FloorItem Tile = Tiles.get(ItemID);

        if (Tile == null) {
            return false;
        }

        if (TileOwners[ItemID] != null) //A team already owns this.
        {
            if (getPlayersTeam(Player) == TileOwners[ItemID]) //We're upgrading the tile!
            {
                if (Tile.ExtraData.equals("3")) {
                    return false;
                } else {

                }

            }
        } else {
            TileOwners[ItemID] = getPlayersTeam(Player);

        }

        return true;
    }

    public BattleBall_TeamLogic getPlayersTeam(Session Player) {
        if (RedTeam.hasPlayer(Player)) {
            return RedTeam;
        }

        if (BlueTeam.hasPlayer(Player)) {
            return BlueTeam;
        }

        if (GreenTeam.hasPlayer(Player)) {
            return GreenTeam;
        }

        if (YellowTeam.hasPlayer(Player)) {
            return YellowTeam;
        }

        return null;
    }
}
