package se.urmo.game.entities.ghost.mode;

import lombok.extern.slf4j.Slf4j;
import se.urmo.game.entities.ghost.Ghost;
import se.urmo.game.entities.ghost.strategy.EatenStrategy;
import se.urmo.game.entities.pacman.PacMan;
import se.urmo.game.graphics.SpriteLocation;
import se.urmo.game.graphics.SpriteSheetManager;
import se.urmo.game.map.GameMap;

import java.awt.image.BufferedImage;

@Slf4j
public class EatenGhostMode extends AbstractGhostModeImpl {
    // Eaten mode specific constants
    private static final BufferedImage[] EATEN_ANIMATION = SpriteSheetManager.get(SpriteLocation.GHOST).getAnimation(9);
    private static final double EATEN_SPEED = 1.0; // Faster when eaten

    public EatenGhostMode(Ghost ghost) {
        super(ghost, new EatenStrategy(), ghost.getLevelManager(), 9);
    }

    @Override
    public void update(Ghost ghost, PacMan pacman, GameMap map) {
        if (getPosition().asPoint().distance(Ghost.getHouseEntrance().asPoint()) < 10) {
            log.debug("Ghost reached home, returning to chase mode");
            ghost.requestModeChange(GhostMode.CHASE);
            return;
        }

        updatePosition(ghost, pacman, map);
    }

    @Override
    public BufferedImage[] getAnimation() {
        return EATEN_ANIMATION;
    }

    @Override
    public double getSpeed() {
        return EATEN_SPEED;
    }
}