package xyz.luxnk.mxmmod.characters;

import basemod.abstracts.CustomPlayer;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.math.MathUtils;
import com.esotericsoftware.spine.AnimationState;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.red.Strike_Red;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.EnergyManager;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.events.beyond.SpireHeart;
import com.megacrit.cardcrawl.events.city.Vampires;
import com.megacrit.cardcrawl.helpers.FontHelper;
import com.megacrit.cardcrawl.helpers.ScreenShake;
import com.megacrit.cardcrawl.screens.CharSelectInfo;
import com.megacrit.cardcrawl.unlock.UnlockTracker;
import xyz.luxnk.mxmmod.MxmMod;
import xyz.luxnk.mxmmod.patches.AbstractCardEnum;
import xyz.luxnk.mxmmod.patches.MxmModClassEnum;

import java.util.ArrayList;

public class Mxm extends CustomPlayer {

    private static final int ENERGY_PER_TURN = 3; // how much energy you get every turn
    private static final String MXM_SHOULDER_2 = "img/char/shoulder2.png"; // campfire pose
    private static final String MXM_SHOULDER_1 = "img/char/shoulder1.png"; // another campfire pose
    private static final String MXM_CORPSE = "img/char/corpse.png"; // dead corpse
    private static final String MXM_SKELETON_ATLAS = "img/char/skeleton.atlas"; // spine animation atlas
    private static final String MXM_SKELETON_JSON = "img/char/skeleton.json"; // spine animation json
    private static final String MXM_ANIMATION = "Idle";

    private static final String[] ORB_TEXTURES = {
            "img/UI/EPanel/layer5.png",
            "img/UI/EPanel/layer4.png",
            "img/UI/EPanel/layer3.png",
            "img/UI/EPanel/layer2.png",
            "img/UI/EPanel/layer1.png",
            "img/UI/EPanel/layer0.png",
            "img/UI/EPanel/layer5d.png",
            "img/UI/EPanel/layer4d.png",
            "img/UI/EPanel/layer3d.png",
            "img/UI/EPanel/layer2d.png",
            "img/UI/EPanel/layer1d.png"
    };
    private static final String ORB_VFX = "img/UI/energyBlueVFX.png";
    private static final float[] LAYER_SPEED =
            {-40.0F, -32.0F, 20.0F, -20.0F, 0.0F, -10.0F, -8.0F, 5.0F, -5.0F, 0.0F};

    public Mxm(String name) {
        super(name, MxmModClassEnum.MXM, ORB_TEXTURES, ORB_VFX, LAYER_SPEED, null, null);

        this.dialogX = (this.drawX + 0.0F * Settings.scale); // set location for text bubbles
        this.dialogY = (this.drawY + 220.0F * Settings.scale); // you can just copy these values

        initializeClass(null, MXM_SHOULDER_2, // required call to load textures and setup energy/loadout
                MXM_SHOULDER_1,
                MXM_CORPSE,
                getLoadout(), 20.0F, -10.0F, 220.0F, 290.0F, new EnergyManager(ENERGY_PER_TURN));

        loadAnimation(MXM_SKELETON_ATLAS, MXM_SKELETON_JSON, 1.0F);
        // if you're using modified versions of base game animations or made animations in spine make sure to include this bit and the following lines
        /*AnimationState.TrackEntry e = this.state.setAnimation(0, MXM_ANIMATION, true);
        e.setTime(e.getEndTime() * MathUtils.random());
        this.stateData.setMix("Hit", "Idle", 0.1F);
        e.setTimeScale(1.0F);*/

    }

    @Override
    public ArrayList<String> getStartingDeck() {
        ArrayList<String> retVal = new ArrayList();
        retVal.add("Strike_MXM");
        retVal.add("Strike_MXM");
        retVal.add("Strike_MXM");
        retVal.add("Strike_MXM");
        retVal.add("QuickStrike_MXM");
        retVal.add("TwinStrike_MXM");
        retVal.add("Defend_MXM");
        retVal.add("Defend_MXM");
        retVal.add("Defend_MXM");
        retVal.add("Defend_MXM");
        retVal.add("SpeedUp_MXM");
        retVal.add("SadCat_MXM");
        retVal.add("LuckyCat_MXM");
        return retVal;
    }

    @Override
    public ArrayList<String> getStartingRelics() {
        ArrayList<String> retVal = new ArrayList<>();
        retVal.add("Hamakagami");
        UnlockTracker.markRelicAsSeen("Hamakagami");
        return retVal;
    }

    public static final int STARTING_HP = 70;
    public static final int MAX_HP = 70;
    public static final int STARTING_GOLO = 30; // 猫小咪小姐比较贫穷
    public static final int HAND_SIZE = 5;


    @Override
    public CharSelectInfo getLoadout() {
        return new CharSelectInfo("猫小咪",
                "来自另一个世界的千年猫妖， NL 因为好奇和追求挑战而来到尖塔冒险。",
                STARTING_HP, MAX_HP, 0, STARTING_GOLO, HAND_SIZE, this,
                getStartingRelics(),
                getStartingDeck(),
                false);
    }

    @Override
    public String getTitle(PlayerClass playerClass) {
        return "千年猫妖";
    }

    @Override
    public AbstractCard.CardColor getCardColor() {
        return AbstractCardEnum.MXM_COLOR;
    }

    @Override
    public Color getCardRenderColor() {
        return MxmMod.CYAN;
    }

    @Override
    public AbstractCard getStartCardForEvent() {
        return new Strike_Red();
    }

    @Override
    public Color getCardTrailColor() {
        return MxmMod.CYAN;
    }

    @Override
    public int getAscensionMaxHPLoss() {
        return 5;
    }

    @Override
    public BitmapFont getEnergyNumFont() {
        return FontHelper.energyNumFontBlue;
    }

    @Override
    public void doCharSelectScreenSelectEffect() {
        CardCrawlGame.sound.playA("ATTACK_HEAVY", MathUtils.random(-0.2F, 0.2F));
        CardCrawlGame.screenShake.shake(ScreenShake.ShakeIntensity.MED, ScreenShake.ShakeDur.SHORT, true);
    }

    @Override
    public String getCustomModeCharacterButtonSoundKey() {
        return "ATTACK_HEAVY";
    }

    @Override
    public String getLocalizedCharacterName() {
        return "猫小咪";
    }

    @Override
    public AbstractPlayer newInstance() {
        return new Mxm(this.name);
    }

    @Override
    public String getSpireHeartText() {
        return SpireHeart.DESCRIPTIONS[8];
    }

    @Override
    public Color getSlashAttackColor() {
        return MxmMod.CYAN;
    }

    @Override
    public AbstractGameAction.AttackEffect[] getSpireHeartSlashEffect() {
        return new AbstractGameAction.AttackEffect[0];
    }

    @Override
    public String getVampireText() {
        return Vampires.DESCRIPTIONS[0];
    }
}
