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

import com.zivilon.cinder_loe.CinderLoE;

import com.zivilon.cinder_loe.entity.npc.evil_human.Limwaith;
import lotr.common.LOTRLevelData;
import lotr.common.LOTRMod;
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.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.util.MovingObjectPosition;

public class LimwaithShaman extends Limwaith implements LOTRTradeable.Smith {
    public static LOTRTradeEntries LIMWAITH_SHAMAN_BUY;
    public static LOTRTradeEntries LIMWAITH_SHAMAN_SELL;

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

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

    public LOTRTradeEntries getBuyPool() {
        return LIMWAITH_SHAMAN_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return LIMWAITH_SHAMAN_SELL;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

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

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


    static {
        LIMWAITH_SHAMAN_BUY = new LOTRTradeEntries(TradeType.BUY,
                new LOTRTradeEntry(new ItemStack(CinderLoE.daggerLimwaith), 12),
                new LOTRTradeEntry(new ItemStack(CinderLoE.daggerLimwaithPoisoned), 20),
                new LOTRTradeEntry(new ItemStack(CinderLoE.blowgunLimwaith), 25),
                new LOTRTradeEntry(new ItemStack(LOTRMod.tauredainDart, 4), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.tauredainDartPoisoned, 4), 10),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bonemold, 2), 4),
                new LOTRTradeEntry(new ItemStack(Items.bone, 1), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bottlePoison), 10));

        LIMWAITH_SHAMAN_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(Items.gold_nugget), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.emerald), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.amber), 10),
                new LOTRTradeEntry(new ItemStack(Items.glass_bottle), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mug), 1),
                new LOTRTradeEntry(new ItemStack(Items.bone), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.rhinoHorn), 5),
                new LOTRTradeEntry(new ItemStack(Items.dye, 3, 15), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.gemsbokHorn), 4),
                new LOTRTradeEntry(new ItemStack(LOTRMod.doubleFlower, 2, 2), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.doubleFlower, 2, 3), 1),
                new LOTRTradeEntry(new ItemStack(Blocks.red_mushroom, 1, 0), 2),
                new LOTRTradeEntry(new ItemStack(Blocks.brown_mushroom, 1, 0), 2),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bonemold, 2), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mango), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.banana), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.corn, 2), 1));
    }

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

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

    protected Item getLimwaithTraderDrop() {
        return LOTRMod.pearl;
    }

    @Override
    public String getSpeechBank(EntityPlayer entityplayer) {
        if (this.isFriendlyAndAligned(entityplayer)) {
            if (this.canTradeWith(entityplayer)) {
                return "limwaith/shaman/friendly";
            }
            return "limwaith/shaman/neutral";
        }
        return "limwaith/shaman/hostile";
    }
    @Override
    public ItemStack getPickedResult(MovingObjectPosition target) {
        return new ItemStack(CinderLoE.spawnEgg, 1, 33);
    }
}
