package inf101.v18.rogue101.enemies;

import inf101.v18.grid.ILocation;
import inf101.v18.rogue101.Main;
import inf101.v18.rogue101.game.Game;
import inf101.v18.rogue101.game.IGame;
import inf101.v18.rogue101.items.Backpack;
import inf101.v18.rogue101.items.Sword;
import inf101.v18.rogue101.objects.IItem;
import inf101.v18.rogue101.objects.INonPlayer;
import inf101.v18.rogue101.shared.NPC;
import inf101.v18.rogue101.states.Attack;

public class Boss implements INonPlayer {
    private int hp = getMaxHealth();
    private final Backpack backpack = new Backpack();
    private ILocation loc;

    public Boss() {
        backpack.add(new Sword());
    }

    @Override
    public void doTurn(IGame game) {
        loc = game.getLocation();
        NPC.tryAttack(game, 1, Attack.MELEE);
    }

    @Override
    public int getAttack() {
        return 50;
    }

    @Override
    public int getDamage() {
        return 15;
    }

    @Override
    public IItem getItem(Class<?> type) {
        for (IItem item : backpack.getContent()) {
            if (type.isInstance(item)) {
                return item;
            }
        }
        return null;
    }

    @Override
    public int getCurrentHealth() {
        return hp;
    }

    @Override
    public int getDefence() {
        return 40;
    }

    @Override
    public int getMaxHealth() {
        return 550;
    }

    @Override
    public String getName() {
        return "Lucifer";
    }

    @Override
    public int getSize() {
        return 50;
    }

    @Override
    public String getPrintSymbol() {
        return "\u001b[91m" + "\uD83D\uDE08" + "\u001b[0m";
    }

    @Override
    public String getSymbol() {
        return "B";
    }

    @Override
    public int getVision() {
        return 3;
    }

    @Override
    public int handleDamage(IGame game, IItem source, int amount) {
        hp -= amount;
        if (hp < 0 && backpack.size() > 0) { //Will be useful in a dungeon with several bosses
            boolean dropped = false;
            for (IItem item : backpack.getContent()) {
                if (game.dropAt(loc, item)) {
                    dropped = true;
                }
            }
            if (dropped) {
                game.displayMessage(getName() + " dropped something");
            }
            ((Game)game).win();
        }
        game.getPrinter().printAt(Main.COLUMN_RIGHTSIDE_START, 19, "Boss HP: " + NPC.hpBar(this));
        return amount;
    }
}
