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

import com.zivilon.cinder_loe.CinderLoE;
import com.zivilon.cinder_loe.mixins.MixinLOTRTradeEntries;
import lotr.common.LOTRAchievement;
import lotr.common.LOTRFoods;
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.world.World;

public class HalfTrollBrewer extends LOTREntityHalfTroll implements LOTRTradeable {
    public static LOTRTradeEntries HALF_TROLL_BREWER_BUY;
    public static LOTRTradeEntries HALF_TROLL_BREWER_SELL;

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

    public LOTRTradeEntries getBuyPool() {
        return HALF_TROLL_BREWER_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return HALF_TROLL_BREWER_SELL;
    }

    public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) {
        data = super.onSpawnWithEgg(data);
        this.npcItemsInv.setMeleeWeapon(new ItemStack(LOTRMod.daggerHalfTrollPoisoned));
        this.npcItemsInv.setIdleItem(new ItemStack(LOTRMod.mugOrcDraught));
                this.setCurrentItemOrArmor(4, new ItemStack(LOTRMod.helmetHalfTroll));
        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_BREWER_BUY = new LOTRTradeEntries(TradeType.BUY,
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugTorogDraught, 1, 9999), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugTorogDraught, 1, 9999), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugTorogDraught, 1, 9999), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugTorogDraught, 1, 4), 8),
                new LOTRTradeEntryBarrel(new ItemStack(LOTRMod.mugTorogDraught, 1, 3), 180),
                new LOTRTradeEntryBarrel(new ItemStack(LOTRMod.mugTorogDraught, 1, 4), 300),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugOrcDraught, 1, 9999), 8),
                new LOTRTradeEntryBarrel(new ItemStack(LOTRMod.mugOrcDraught, 1, 3), 150),
                new LOTRTradeEntry(new ItemStack(CinderLoE.mugOrcBrew, 1, 9999), 200),
                new LOTRTradeEntry(new ItemStack(CinderLoE.spiceIngredient, 1, 2), 500));
        ((MixinLOTRTradeEntries)HALF_TROLL_BREWER_BUY).vessels(LOTRFoods.HALF_TROLL_DRINK);

        HALF_TROLL_BREWER_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(LOTRMod.mug), 1),
                new LOTRTradeEntry(new ItemStack(Items.rotten_flesh), 2),
                new LOTRTradeEntry(new ItemStack(Items.reeds, 2), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.waterskin), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.barrel), 10),
                new LOTRTradeEntry(new ItemStack(LOTRMod.rhinoHorn), 5),
                new LOTRTradeEntry(new ItemStack(Blocks.dirt, 8), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.morgulFlower), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.dwarfBone), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.hobbitBone), 1),
                new LOTRTradeEntry(new ItemStack(Items.bone), 1),
                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 "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);
    }

}
