package hemomancer.orbs;

import basemod.abstracts.CustomOrb;
import com.megacrit.cardcrawl.actions.animations.VFXAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.OrbStrings;
import com.megacrit.cardcrawl.orbs.AbstractOrb;
import com.megacrit.cardcrawl.vfx.combat.OrbFlareEffect;
import hemomancer.HemomancerMod;

import java.util.Iterator;

public class BloodMistOrb extends CustomOrb {
    public static final String BLOODMIST_ID = HemomancerMod.makeID("BloodMistOrb");
    private static final OrbStrings orbString = CardCrawlGame.languagePack.getOrbString(BLOODMIST_ID);
    public static final String[] DESC = orbString.DESCRIPTION;

    public BloodMistOrb() {
        super(
                BLOODMIST_ID,
                orbString.NAME,
                0,
                0,
                DESC[0],
                DESC[1],
                HemomancerMod.makeOrbPath("default_orb.png")
        );
    }

    @Override
    public void onEvoke() {
        AbstractDungeon.player.heal(evokeAmount);
    }

    @Override
    public void updateDescription() {
        this.description = "Supplies " + this.evokeAmount + " maximum hit points for the purpose of sanguine cards.";

    }

    public void pump(int pumpAmount) {
        float speedTime = 0.25F;
        AbstractDungeon.actionManager.addToBottom(new VFXAction(new OrbFlareEffect(this, OrbFlareEffect.OrbFlareColor.DARK), speedTime));
        this.evokeAmount += pumpAmount;
        this.passiveAmount += pumpAmount;
        this.updateDescription();
    }

    public void consume(AbstractPlayer player, int x) {
        int diff = this.evokeAmount - x;
        this.evokeAmount = Math.max(0, diff);
        this.passiveAmount = Math.max(0, diff);
        if (diff < 0) {
            player.decreaseMaxHealth(-diff);
        }
    }

    @Override
    public AbstractOrb makeCopy() {
        return new BloodMistOrb();
    }

    @Override
    public void playChannelSFX() {
        CardCrawlGame.sound.play("STS_SFX_VampireBite_v2", 0.1f);
    }

    public static int getBloodMistStacks(AbstractPlayer player) {
        BloodMistOrb orb = getBloodMistOrb(player);
        if (orb == null) {
            return 0;
        } else {
            return orb.evokeAmount;
        }
    }

    public static BloodMistOrb getBloodMistOrb(AbstractPlayer player) {
        Iterator<AbstractOrb> orbs = player.orbs.iterator();
        BloodMistOrb orb = null;
        while (orbs.hasNext()) {
            AbstractOrb rawOrb = orbs.next();
            if (rawOrb instanceof BloodMistOrb) {
                orb = (BloodMistOrb) rawOrb;
                break;
            }
        }
        return orb;
    }
}
