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.*;
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.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class HalfTrollButcher extends LOTREntityHalfTroll implements LOTRTradeable {
    public static LOTRTradeEntries HALF_TROLL_BUTCHER_BUY;
    public static LOTRTradeEntries HALF_TROLL_BUTCHER_SELL;

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

    public LOTRTradeEntries getBuyPool() {
        return HALF_TROLL_BUTCHER_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return HALF_TROLL_BUTCHER_SELL;
    }

    public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) {
        data = super.onSpawnWithEgg(data);
        this.npcItemsInv.setMeleeWeapon(new ItemStack(LOTRMod.battleaxeHalfTroll));
        this.npcItemsInv.setIdleItem(this.npcItemsInv.getMeleeWeapon());
        this.setCurrentItemOrArmor(3, new ItemStack(LOTRMod.bodyHalfTroll));
        return data;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

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


    static {
        HALF_TROLL_BUTCHER_BUY = new LOTRTradeEntries(TradeType.BUY,
                new LOTRTradeEntry(new ItemStack(CinderLoE.flatbread), 2),
                new LOTRTradeEntry(new ItemStack(CinderLoE.maggotlessbread), 3),
                new LOTRTradeEntry(new ItemStack(CinderLoE.spiceIngredient, 1, 0), 500),
                new LOTRTradeEntry(new ItemStack(Items.bread), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.battleaxeHalfTroll), 10),
                new LOTRTradeEntry(new ItemStack(Items.flint, 3), 8),
                new LOTRTradeEntry(new ItemStack(Items.cooked_fished), 4),
                new LOTRTradeEntry(new ItemStack(Items.cooked_fished, 1), 4),
                new LOTRTradeEntry(new ItemStack(LOTRMod.zebraCooked), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.lionCooked), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.rhinoCooked), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.manFlesh), 5));

        HALF_TROLL_BUTCHER_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(Items.string, 3), 1),
                new LOTRTradeEntry(new ItemStack(Items.feather, 1), 2),
                new LOTRTradeEntry(new ItemStack(Items.wheat, 2), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.elfBone), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.dwarfBone), 1),
                new LOTRTradeEntry(new ItemStack(Items.bone), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.hobbitBone), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.maggotyBread, 2), 2),
                new LOTRTradeEntry(new ItemStack(Items.bread, 1), 2),
                new LOTRTradeEntry(new ItemStack(Items.rotten_flesh), 2),
                new LOTRTradeEntry(new ItemStack(Items.fish), 2),
                new LOTRTradeEntry(new ItemStack(Items.fish, 1), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.zebraRaw), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.lionRaw), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.rhinoRaw), 3),
                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 "halfTroll/scavenger/friendly";
            }
            return "halfTroll/scavenger/neutral";
        }
        return "halfTroll/halfTroll/hostile";
    }

    @Override
    public void onPlayerTrade(EntityPlayer entityplayer, LOTRTradeEntries.TradeType type, ItemStack itemstack) {
        LOTRLevelData.getData(entityplayer).addAchievement(LOTRAchievement.tradeHalfTrollScavenger);
    }
    @Override
    public ItemStack getPickedResult(MovingObjectPosition target) {
        return null;
    }
}
