package me.hammerle.supersnuvi.tiles;

import java.util.HashSet;
import me.hammerle.supersnuvi.javafx.Image;
import me.hammerle.supersnuvi.entity.Entity;
import me.hammerle.supersnuvi.entity.Hero;
import me.hammerle.supersnuvi.gamelogic.StateRenderer;
import me.hammerle.supersnuvi.util.CollisionBox;
import me.hammerle.supersnuvi.util.Face;
import me.hammerle.supersnuvi.util.SoundUtils;
import me.hammerle.supersnuvi.util.Utils;

public class BottledSoulTile extends Tile
{
    public static final int ID = 32;
    public static final Image IMAGE = Utils.getTileImage("bottled_soul/bottled_soul");;
    
    private final HashSet<Long> states;
    
    public BottledSoulTile()
    {
        states = new HashSet<>();
        super.setCollisionBox(CollisionBox.createScaledBox(0.2, 0.2, 0.8, 0.8));
    }

    @Override
    public void onEntityCollide(Entity ent, int x, int y, Face face) 
    {
        if(ent instanceof Hero)
        {
            if(states.add(getKey(x, y)))
            {
                SoundUtils.playSound(SoundUtils.Sound.COLLECT);
                ent.getLevel().increaseSouls();
                ent.addHealthPercent(0.2);
            }
        }
    }
    
    @Override
    public Image getImage(int x, int y) 
    {
        if(states.contains(getKey(x, y)))
        {
            return StateRenderer.FALLBACK_TILE.getImage(x, y);
        }
        return IMAGE;
    }
    
    @Override
    public void reset() 
    {
        states.clear();
    } 
}
