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

import com.zivilon.cinder_loe.CinderLoE;

import lotr.common.LOTRLevelData;
import lotr.common.LOTRMod;
import lotr.common.entity.npc.*;
import lotr.common.entity.npc.LOTRTradeEntries.TradeType;
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 BladorthinSmith extends LOTREntityDorwinionElf implements LOTRTradeable.Smith {
    public static LOTRTradeEntries BLADORTHIN_SMITH_BUY;
    public static LOTRTradeEntries BLADORTHIN_SMITH_SELL;

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

    public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) {
        data = super.onSpawnWithEgg(data);
        this.npcItemsInv.setMeleeWeapon(new ItemStack(LOTRMod.blacksmithHammer));
        this.npcItemsInv.setIdleItem(this.npcItemsInv.getMeleeWeapon());
        return data;
    }

    public LOTRTradeEntries getBuyPool() {
        return BLADORTHIN_SMITH_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return BLADORTHIN_SMITH_SELL;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

    protected void dropFewItems(boolean flag, int i) {
        super.dropFewItems(flag, i);
    }

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

    static {
        BLADORTHIN_SMITH_BUY = new LOTRTradeEntries(TradeType.BUY,
            new LOTRTradeEntry[] {
                new LOTRTradeEntry(new ItemStack(LOTRMod.dorwinionTable), 100),
                new LOTRTradeEntry(new ItemStack(LOTRMod.swordDorwinionElf), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerDorwinionElf), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.spearBladorthin), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.helmetDorwinionElf), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bodyDorwinionElf), 25),
                new LOTRTradeEntry(new ItemStack(LOTRMod.legsDorwinionElf), 22),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bootsDorwinionElf), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.dorwinionElfBow), 15),
                new LOTRTradeEntry(new ItemStack(Items.arrow, 4), 3),
                new LOTRTradeEntry(new ItemStack(CinderLoE.helmetDorwinionElite), 100),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bodyDorwinionElite), 100),
                new LOTRTradeEntry(new ItemStack(CinderLoE.legsDorwinionElite), 100),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bootsDorwinionElite), 100),
                new LOTRTradeEntry(new ItemStack(CinderLoE.forgingKit, 1, 1), 200), new LOTRTradeEntry(new ItemStack(CinderLoE.forgingKit, 1, 0), 200)
            }
        );

        BLADORTHIN_SMITH_SELL = new LOTRTradeEntries(TradeType.SELL,
            new LOTRTradeEntry[] {
                new LOTRTradeEntry(new ItemStack(Blocks.iron_ore), 5),
                new LOTRTradeEntry(new ItemStack(Blocks.gold_ore), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.oreCopper), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.oreTin), 5),
                new LOTRTradeEntry(new ItemStack(Items.iron_ingot), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.elfSteel), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bronze), 3),
                new LOTRTradeEntry(new ItemStack(Items.gold_ingot), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.diamond), 25),
                new LOTRTradeEntry(new ItemStack(LOTRMod.emerald), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.ruby), 12),
                new LOTRTradeEntry(new ItemStack(LOTRMod.opal), 10),
                new LOTRTradeEntry(new ItemStack(LOTRMod.amber), 10),
                new LOTRTradeEntry(new ItemStack(LOTRMod.topaz), 8),
                new LOTRTradeEntry(new ItemStack(Items.coal, 2, Short.MAX_VALUE), 1),
                new LOTRTradeEntry(new ItemStack(Items.lava_bucket), 16),
                new LOTRTradeEntry(new ItemStack(Items.stick, 8), 1),
                new LOTRTradeEntry(new ItemStack(Items.string, 3), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mithrilNugget), 35)
            }
        );
    }

    @Override
    public void onPlayerTrade(EntityPlayer entityplayer, TradeType type, ItemStack itemstack) {
    }

    @Override
    public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_) {
    }
    @Override
    public ItemStack getPickedResult(MovingObjectPosition target) {
        return new ItemStack(CinderLoE.spawnEgg, 1, 31);
    }
}
