package xyz.luxnk.mxmmod.cards;

import basemod.abstracts.CustomCard;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.RemoveSpecificPowerAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.DexterityPower;
import com.megacrit.cardcrawl.powers.StrengthPower;
import xyz.luxnk.mxmmod.patches.AbstractCardEnum;

public class TacticalTrans_MXM extends CustomCard {

    public static final String ID = "TacticalTrans_MXM";
    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "img/cards/skill/poor_wine.png";
    private static final int COST = 1;

    public TacticalTrans_MXM() {
        super(
                ID,
                NAME,
                IMG_PATH,
                COST,
                DESCRIPTION,
                CardType.SKILL,
                AbstractCardEnum.MXM_COLOR,
                CardRarity.UNCOMMON,
                CardTarget.SELF
        );
    }

    @Override
    public void use(AbstractPlayer abstractPlayer, AbstractMonster abstractMonster) {

        int oldStr = 0;
        int oldDex = 0;
        if (abstractPlayer.hasPower("Strength")) {
            oldStr = abstractPlayer.getPower("Strength").amount;
            AbstractDungeon.actionManager.addToBottom(
                    new RemoveSpecificPowerAction(abstractPlayer, abstractPlayer, "Strength"));
        }
        if (abstractPlayer.hasPower("Dexterity")) {
            oldDex = abstractPlayer.getPower("Dexterity").amount;
            AbstractDungeon.actionManager.addToBottom(
                    new RemoveSpecificPowerAction(abstractPlayer, abstractPlayer, "Dexterity"));
        }
        if (oldStr != 0) {
            AbstractDungeon.actionManager.addToBottom(
                    new ApplyPowerAction(
                            abstractPlayer,
                            abstractPlayer,
                            new DexterityPower(abstractPlayer, oldStr),
                            this.magicNumber));
        }
        if (oldDex != 0) {
            AbstractDungeon.actionManager.addToBottom(
                    new ApplyPowerAction(
                            abstractPlayer,
                            abstractPlayer,
                            new StrengthPower(abstractPlayer, oldDex),
                            this.magicNumber));
        }
    }

    @Override
    public AbstractCard makeCopy() {
        return new TacticalTrans_MXM();
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            upgradeName();
            upgradeBaseCost(0);
        }
    }
}
