package xyz.luxnk.mxmmod.power;

import com.badlogic.gdx.graphics.Texture;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.utility.UseCardAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.powers.AbstractPower;

public class BeSeriousPower extends AbstractPower {

    public static final String POWER_ID = "BeSeriousPower";
    private static final PowerStrings powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    public static final String NAME = powerStrings.NAME;
    public static final String[] DESCRIPTIONS = powerStrings.DESCRIPTIONS;

    private int count = 0;

    public BeSeriousPower(AbstractCreature owner, int amount) {
        this.name = NAME;
        this.ID = POWER_ID;
        this.owner = owner;
        this.amount = amount;
        this.type = PowerType.BUFF;
        updateDescription();
        this.img = new Texture("img/powers/generator.png");
    }

    @Override
    public void onUseCard(AbstractCard card, UseCardAction action) {
        if (card.type == AbstractCard.CardType.SKILL) {
            count++;
            if (count == 3) {
                AbstractDungeon.actionManager.addToBottom(
                        new ApplyPowerAction(
                                AbstractDungeon.player,
                                AbstractDungeon.player,
                                new SpeedUpPower(AbstractDungeon.player, this.amount),
                                this.amount)
                );
                this.flash();
                count = 0;
            }
            updateDescription();
        }
    }

    @Override
    public void updateDescription() {
        int needCardCount = 3 - count;
        this.description = DESCRIPTIONS[0] + this.amount + DESCRIPTIONS[1] + needCardCount + DESCRIPTIONS[2];
    }

    @Override
    public void atEndOfRound() {
        count = 0;
        updateDescription();
    }
}
