package org.project.item.weapons;

import org.project.entity.Entity;
import java.util.ArrayList;
import java.io.Serializable;

public class Sword extends Weapon implements Serializable
{

    private static final long serialVersionUID = 1L;

    private int abilityCharge;
    private static final int MAX_CHARGE = 10;
    private static final int REQUIRED_CHARGE = 5;

    public Sword()
    {
        super("Knight Sword", 20, 0);
        this.abilityCharge = 0;
    }

    @Override
    public void uniqueAbility(ArrayList<Entity> targets)
    {
        if (abilityCharge < REQUIRED_CHARGE)
        {
            System.out.println("⚠️ Not enough charge for special ability! (" + abilityCharge + "/" + REQUIRED_CHARGE + ")");
            return;
        }

        if (isBroken)
        {
            System.out.println("⚠️ " + name + " is broken and can't use its special ability!");
            return;
        }

        System.out.println("⚔️ " + name + " special ability: Cleave!");
        for (Entity target : targets)
        {
            if (target != null && target.isAlive())
            {
                target.takeDamage((int) (getDamage() * 1.5));
            }
        }

        abilityCharge = 0;
        reduceDurability(5);
    }

    public void addCharge(int amount)
    {
        this.abilityCharge = Math.min(this.abilityCharge + amount, MAX_CHARGE);
    }

    public int getAbilityCharge()
    {
        return abilityCharge;
    }

    public int getMaxCharge()
    {
        return MAX_CHARGE;
    }
}