package xyz.luxnk.mxmmod.power;

import com.badlogic.gdx.graphics.Texture;
import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.actions.common.RemoveSpecificPowerAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
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 SpeedUpPower extends AbstractPower {

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

    public SpeedUpPower(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");
        this.isTurnBased = true;
    }

    @Override
    public float atDamageReceive(float damage, DamageInfo.DamageType damageType) {
        int count = this.amount;
        if (count > 10) {
            count = 10;
        }
        System.out.println("伤害为" + damage);
        if (damageType == DamageInfo.DamageType.NORMAL) {
            damage = damage * (1F - 0.1F * count);
        }
        return damage;
    }

    @Override
    public float atDamageFinalReceive(float damage, DamageInfo.DamageType type) {
        System.out.println("实际受到了" + damage + "点伤害");

        /*if (damage > 0 && this.amount > 0) {
            AbstractDungeon.actionManager.addToBottom(new ReducePowerAction(this.owner, this.owner, "SpeedUpPower", 1));
        }*/

        return super.atDamageFinalReceive(damage, type);
    }

    @Override
    public int onAttacked(DamageInfo info, int damageAmount) {
        if (info.type != DamageInfo.DamageType.THORNS && info.type != DamageInfo.DamageType.HP_LOSS && info.owner != null && info.owner != this.owner && damageAmount > 0) {
            if (this.amount == 0) {
                AbstractDungeon.actionManager.addToBottom(new RemoveSpecificPowerAction(this.owner, this.owner, "SpeedUpPower"));
            } else {
                AbstractDungeon.actionManager.addToBottom(new ReducePowerAction(this.owner, this.owner, "SpeedUpPower", 1));
            }
        }
        return damageAmount;
    }

    @Override
    public void updateDescription() {
        int count = this.amount;
        if (count > 10) {
            count = 10;
        }
        this.description = DESCRIPTIONS[0] + count + "0%" + DESCRIPTIONS[1];
    }

    @Override
    public void atEndOfRound() {
        this.flash();
        if (this.amount == 0) {
            AbstractDungeon.actionManager.addToBottom(new RemoveSpecificPowerAction(this.owner, this.owner, "SpeedUpPower"));
        } else {
            AbstractDungeon.actionManager.addToBottom(new ReducePowerAction(this.owner, this.owner, "SpeedUpPower", 1));
        }
    }
}
