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.LOTREntityDolGuldurOrc;
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.util.MovingObjectPosition;
import net.minecraft.world.World;

public class DolGuldurOrcSmith extends LOTREntityDolGuldurOrc implements LOTRTradeable.Smith {
    public static LOTRTradeEntries DOLGULDUR_SMITH_BUY;
    public static LOTRTradeEntries DOLGULDUR_SMITH_SELL;

    public DolGuldurOrcSmith(World world) {
        super(world);
    }


    public LOTRTradeEntries getBuyPool() {
        return DOLGULDUR_SMITH_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return DOLGULDUR_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.helmetDolGuldur));
        return data;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

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


    static {
        DOLGULDUR_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.helmetDolGuldur), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bodyDolGuldur), 30),
                new LOTRTradeEntry(new ItemStack(LOTRMod.legsDolGuldur), 26),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bootsDolGuldur), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.swordDolGuldur), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.spearDolGuldur), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerDolGuldur), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerDolGuldurPoisoned), 10),
                new LOTRTradeEntry(new ItemStack(LOTRMod.battleaxeDolGuldur), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pikeDolGuldur), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.orcBow), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pickaxeDolGuldur), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.axeDolGuldur), 14),
                new LOTRTradeEntry(new ItemStack(Items.arrow, 4), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.hammerDolGuldur), 16));

        DOLGULDUR_SMITH_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(LOTRMod.orcSteel), 3),
                new LOTRTradeEntry(new ItemStack(Items.leather), 2),
                new LOTRTradeEntry(new ItemStack(Items.string, 3), 1),
                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.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 "dolGuldur/trader/friendly";
            }
            return "dolGuldur/trader/neutral";
        }
        return "dolGuldur/orc/hostile";
    }

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

}
