package cz.jzitnik.game.mobs.services.zombie;

import cz.jzitnik.game.Game;
import cz.jzitnik.game.core.CustomMobFallingAfterMineLogicHandler;
import cz.jzitnik.game.entities.items.registry.mobs.Zombie;
import lombok.extern.slf4j.Slf4j;

// I know this code is shit, but I don't want to deal with it
@Slf4j
public class ZombieFallingAfterMineLogic implements CustomMobFallingAfterMineLogicHandler {
    @Override
    public void handle(Game game, int x, int y) {
        log.debug("Zombie is falling");

        var world = game.getWorld();

        var mobsTop = world[y - 2][x].stream().filter(block ->
                block.getClass().equals(Zombie.class) && block.getSpriteState().isPresent() &&
                        (block.getSpriteState().get().equals(cz.jzitnik.game.sprites.Zombie.ZombieState.TOP) ||
                                block.getSpriteState().get().equals(cz.jzitnik.game.sprites.Zombie.ZombieState.TOP_HURT))).toList();
        var mobsBottom = world[y - 1][x].stream().filter(block ->
                block.getClass().equals(Zombie.class) && block.getSpriteState().isPresent() &&
                        (block.getSpriteState().get().equals(cz.jzitnik.game.sprites.Zombie.ZombieState.BOTTOM_HURT) ||
                                block.getSpriteState().get().equals(cz.jzitnik.game.sprites.Zombie.ZombieState.BOTTOM))).toList();
        world[y - 2][x].removeAll(mobsTop);
        world[y -1][x].addAll(mobsTop);

        world[y - 1][x].removeAll(mobsBottom);
        world[y][x].addAll(mobsBottom);
    }
}
