package org.project.entity.enemies;

import org.project.entity.Entity;
import org.project.item.Item;
import org.project.item.Key;
import org.project.item.consumables.Flask;
import org.project.item.weapons.Weapon;

import java.util.Random;

public abstract class Enemy extends Entity {

    protected int xpReward;

    public Enemy(String name, int hp, int mana, Weapon weapon, int xpReward) {

        super(name, hp, mana, weapon);

        this.xpReward = xpReward;
    }

    public int getXpReward() {
        return xpReward;
    }

    public void attack(Entity target) {

        int damage = 0;

        if (weapon != null) {
            damage = weapon.getDamage();
        }

        target.takeDamage(damage);

        System.out.println(name + " attacks " + target.getName());

        target.resetDefending();
    }

    public void defend() {

        setDefending(true);

        System.out.println(name + " is defending.");
    }


    public Item dropLoot() {

        Random random = new Random();

        int chance = random.nextInt(100);

        if (chance < 30) {
            return new Flask();
        }

        if (chance >= 30 && chance < 40) {
            return new Key("Castle Key");
        }

        return null;
    }



    public abstract void specialAbility(Entity target);
}
