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

import com.zivilon.cinder_loe.CinderLoE;

import lotr.common.entity.npc.LOTRTradeEntries;
import lotr.common.entity.npc.LOTRTradeEntries.TradeType;
import lotr.common.entity.npc.LOTRTradeable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import lotr.common.LOTRMod;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import lotr.common.entity.npc.LOTRTradeEntry;
import net.minecraft.init.Items;
import net.minecraft.entity.EntityLivingBase;
import lotr.common.LOTRLevelData;
import lotr.common.entity.npc.LOTREntityDwarf;
import net.minecraft.util.MovingObjectPosition;


public class RedDwarfSmith extends LOTREntityDwarf implements LOTRTradeable.Smith {
    public static LOTRTradeEntries RED_DWARF_SMITH_BUY;
    public static LOTRTradeEntries RED_DWARF_SMITH_SELL;

    public RedDwarfSmith(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 RED_DWARF_SMITH_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return RED_DWARF_SMITH_SELL;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

    protected void dropFewItems(boolean flag, int i) {
        super.dropFewItems(flag, i);
        dropItem(getDwarfSteelDrop(), 1 + rand.nextInt(3) + rand.nextInt(i + 1));
    }

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

    static {
        RED_DWARF_SMITH_BUY = new LOTRTradeEntries(TradeType.BUY,
            new LOTRTradeEntry[] {
                new LOTRTradeEntry(new ItemStack(LOTRMod.dwarvenTable), 100),
                new LOTRTradeEntry(new ItemStack(LOTRMod.blacksmithHammer), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.dwarvenRing), 20),
                new LOTRTradeEntry(new ItemStack(CinderLoE.swordRedDwarf), 16),
                new LOTRTradeEntry(new ItemStack(CinderLoE.spearRedDwarf), 18),
                new LOTRTradeEntry(new ItemStack(CinderLoE.battleaxeRedDwarf), 18),
                new LOTRTradeEntry(new ItemStack(CinderLoE.hammerRedDwarf), 18),
                new LOTRTradeEntry(new ItemStack(CinderLoE.pikeRedDwarf), 18),
                new LOTRTradeEntry(new ItemStack(CinderLoE.daggerRedDwarf), 13),
                new LOTRTradeEntry(new ItemStack(CinderLoE.crossbowRedDwarf), 15),
                new LOTRTradeEntry(new ItemStack(CinderLoE.helmetRedDwarf), 25),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bodyRedDwarf), 36),
                new LOTRTradeEntry(new ItemStack(CinderLoE.legsRedDwarf), 30),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bootsRedDwarf), 22),
                new LOTRTradeEntry(new ItemStack(CinderLoE.boarArmorRedDwarf), 25),
                new LOTRTradeEntry(new ItemStack(CinderLoE.spicedHam, 1), 6),
                new LOTRTradeEntry(new ItemStack(CinderLoE.barsRedDwarf, 8), 20),
                new LOTRTradeEntry(new ItemStack(CinderLoE.forgingKit, 1, 1), 200),
                new LOTRTradeEntry(new ItemStack(CinderLoE.forgingKit, 1, 0), 200),
            }
        );

        RED_DWARF_SMITH_SELL = new LOTRTradeEntries(TradeType.SELL,
            new LOTRTradeEntry[] {
                new LOTRTradeEntry(new ItemStack(Items.iron_ingot), 3),
                new LOTRTradeEntry(new ItemStack(CinderLoE.redDwarfSteel), 3),
                new LOTRTradeEntry(new ItemStack(Items.coal, 2, 32767), 1),
                new LOTRTradeEntry(new ItemStack(Items.gold_ingot), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.copper), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.tin), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bronze), 3),
                new LOTRTradeEntry(new ItemStack(Items.string, 3), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.diamond), 25),
                new LOTRTradeEntry(new ItemStack(LOTRMod.emerald), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.sapphire), 12),
                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.amethyst), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.topaz), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pearl), 25),
                new LOTRTradeEntry(new ItemStack(Items.cooked_beef), 3),
                new LOTRTradeEntry(new ItemStack(Items.cooked_porkchop), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.muttonCooked), 3),
                new LOTRTradeEntry(new ItemStack(Items.cooked_chicken), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.gammon), 3),
                new LOTRTradeEntry(new ItemStack(Items.cooked_fished), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.rabbitCooked), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.deerCooked), 3),
                new LOTRTradeEntry(new ItemStack(Items.bread), 2),
                new LOTRTradeEntry(new ItemStack(Items.lava_bucket), 16)

            }
        );
    }

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

    @Override
    public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_) {
    }

    @Override
    protected Item getDwarfSteelDrop() {
        return CinderLoE.redDwarfSteel;
    }
    @Override
    public ItemStack getPickedResult(MovingObjectPosition target) {
        return new ItemStack(CinderLoE.spawnEgg, 1, 34);
    }
}
