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

import com.zivilon.cinder_loe.CinderLoE;
import lotr.common.LOTRAchievement;
import lotr.common.LOTRLevelData;
import lotr.common.LOTRMod;
import lotr.common.entity.npc.LOTREntityGundabadUruk;
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.SharedMonsterAttributes;
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 GundabadOrcSmith extends LOTREntityGundabadUruk implements LOTRTradeable.Smith {
    public static LOTRTradeEntries GUNDABAD_SMITH_BUY;
    public static LOTRTradeEntries GUNDABAD_SMITH_SELL;

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

    public LOTRTradeEntries getBuyPool() {
        return GUNDABAD_SMITH_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return GUNDABAD_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.bodyBone));
        this.setCurrentItemOrArmor(4, new ItemStack(LOTRMod.helmetBronze));
        return data;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

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


    static {
        GUNDABAD_SMITH_BUY = new LOTRTradeEntries(TradeType.BUY,
                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.helmetGundabadUruk), 24),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bodyGundabadUruk), 36),
                new LOTRTradeEntry(new ItemStack(LOTRMod.legsGundabadUruk), 30),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bootsGundabadUruk), 22),
                new LOTRTradeEntry(new ItemStack(LOTRMod.swordGundabadUruk), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.spearGundabadUruk), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerGundabadUruk), 9),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerGundabadUrukPoisoned), 11),
                new LOTRTradeEntry(new ItemStack(LOTRMod.battleaxeGundabadUruk), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.hammerGundabadUruk), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pikeGundabadUruk), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.orcBow), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bronzeCrossbow), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.ironCrossbow), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pickaxeBronze), 12),
                new LOTRTradeEntry(new ItemStack(Items.iron_pickaxe), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.axeBronze), 12),
                new LOTRTradeEntry(new ItemStack(Items.arrow, 4), 3),
                new LOTRTradeEntry(new ItemStack(Items.iron_axe), 14));

        GUNDABAD_SMITH_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(LOTRMod.bronze), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.orcSteel), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.urukSteel), 3),
                new LOTRTradeEntry(new ItemStack(Items.iron_ingot), 3),
                new LOTRTradeEntry(new ItemStack(Items.string, 3), 1),
                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.dwarfBone, 2), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.amber), 11),
                new LOTRTradeEntry(new ItemStack(Blocks.iron_ore), 5),
                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 String getSpeechBank(EntityPlayer entityplayer) {
        if (this.isFriendlyAndAligned(entityplayer)) {
            if (this.canTradeWith(entityplayer)) {
                return "gundabad/trader/friendly";
            }
            return "gundabad/trader/neutral";
        }
        return "gundabad/orc/hostile";
    }

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