package com.zivilon.cinder_loe.entity.npc.orc.trader;

import com.zivilon.cinder_loe.CinderLoE;
import com.zivilon.cinder_loe.mixins.MixinLOTRTradeEntriesOverrides;
import lotr.common.LOTRAchievement;
import lotr.common.LOTRFoods;
import lotr.common.LOTRLevelData;
import lotr.common.LOTRMod;
import lotr.common.entity.npc.LOTREntityBlackUruk;
import lotr.common.entity.npc.LOTRTradeEntries;
import lotr.common.entity.npc.LOTRTradeEntries.TradeType;
import lotr.common.entity.npc.LOTRTradeEntry;
import lotr.common.entity.npc.LOTRTradeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class MordorOrcSmith extends LOTREntityBlackUruk implements LOTRTradeable.Smith {
    public static LOTRTradeEntries MORDOR_SMITH_BUY;
    public static LOTRTradeEntries MORDOR_SMITH_SELL;

    public MordorOrcSmith(World world) {
        super(world);
        this.npcShield = null;
    }

    public LOTRTradeEntries getBuyPool() {
        return MORDOR_SMITH_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return MORDOR_SMITH_SELL;
    }

    public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) {
        data = super.onSpawnWithEgg(data);
        this.npcItemsInv.setMeleeWeapon(new ItemStack(LOTRMod.blacksmithHammer));
        this.npcItemsInv.setIdleItem(this.npcItemsInv.getMeleeWeapon());
        this.setCurrentItemOrArmor(1, new ItemStack(LOTRMod.bootsFur));
        this.setCurrentItemOrArmor(2, new ItemStack(LOTRMod.legsFur));
        this.setCurrentItemOrArmor(3, new ItemStack(LOTRMod.bodyFur));
        this.setCurrentItemOrArmor(4, new ItemStack(LOTRMod.helmetBone));
        return data;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

    public boolean canTradeWith(EntityPlayer entityplayer) {
        return (LOTRLevelData.getData(entityplayer).getAlignment(getFaction()) >= 100.0F && isFriendlyAndAligned(entityplayer));
    }


    static {
        MORDOR_SMITH_BUY = new LOTRTradeEntries(TradeType.BUY,
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugOrcDraught), 24),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bodyBlackUruk), 36),
                new LOTRTradeEntry(new ItemStack(LOTRMod.legsBlackUruk), 30),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bootsBlackUruk), 22),
                new LOTRTradeEntry(new ItemStack(LOTRMod.scimitarBlackUruk), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.spearBlackUruk), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerBlackUruk), 9),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerBlackUrukPoisoned), 11),
                new LOTRTradeEntry(new ItemStack(LOTRMod.battleaxeBlackUruk), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.hammerBlackUruk), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.blackUrukBow), 18),
                new LOTRTradeEntry(new ItemStack(CinderLoE.forgingKit, 1, 1), 200),
                new LOTRTradeEntry(new ItemStack(CinderLoE.forgingKit, 1, 0), 200),
                new LOTRTradeEntry(new ItemStack(LOTRMod.blacksmithHammer), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.helmetOrc), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bodyOrc), 30),
                new LOTRTradeEntry(new ItemStack(LOTRMod.legsOrc), 26),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bootsOrc), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.scimitarOrc), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.spearOrc), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerOrc), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerOrcPoisoned), 10),
                new LOTRTradeEntry(new ItemStack(LOTRMod.battleaxeOrc), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.polearmOrc), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.orcBow), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pickaxeOrc), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.axeOrc), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.hammerOrc), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.wargArmorMordor), 25),
                new LOTRTradeEntry(new ItemStack(Items.arrow, 4), 3));

        MORDOR_SMITH_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(LOTRMod.orcSteel), 3),
                new LOTRTradeEntry(new ItemStack(Items.string, 3), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.blackUrukSteel), 4),
                new LOTRTradeEntry(new ItemStack(Items.leather), 2),
                new LOTRTradeEntry(new ItemStack(Items.coal, 2), 1),
                new LOTRTradeEntry(new ItemStack(CinderLoE.leatherBundle), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.oreMorgulIron), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.guldurilCrystal), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.nauriteGem), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.oreCopper), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.oreTin), 5),
                new LOTRTradeEntry(new ItemStack(CinderLoE.maggotlessbread, 5), 17),
                new LOTRTradeEntry(new ItemStack(LOTRMod.manFlesh), 3));
    }
    @Override
    public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_) {

    }

    @Override
    public void onPlayerTrade(EntityPlayer entityplayer, LOTRTradeEntries.TradeType type, ItemStack itemstack) {
        LOTRLevelData.getData(entityplayer).addAchievement(LOTRAchievement.tradeOrcTrader);
    }

    @Override
    public String getSpeechBank(EntityPlayer entityplayer) {
        if (this.isFriendlyAndAligned(entityplayer)) {
            if (this.canTradeWith(entityplayer)) {
                return "mordor/trader/friendly";
            }
            return "mordor/trader/neutral";
        }
        return "mordor/orc/hostile";
    }
}
