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

import com.zivilon.cinder_loe.CinderLoE;
import com.zivilon.cinder_loe.mixins.MixinLOTRTradeEntries;
import com.zivilon.cinder_loe.mixins.MixinLOTRTradeEntriesOverrides;
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 lotr.common.item.LOTRItemMug;
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 AngmarOrcBrewer extends LOTREntityAngmarOrc implements LOTRTradeable {
    public static LOTRTradeEntries ANGMAR_BREWER_BUY;
    public static LOTRTradeEntries ANGMAR_BREWER_SELL;

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

    public LOTRTradeEntries getBuyPool() {
        return ANGMAR_BREWER_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return ANGMAR_BREWER_SELL;
    }



    public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) {
        data = super.onSpawnWithEgg(data);
        this.npcItemsInv.setMeleeWeapon(new ItemStack(LOTRMod.daggerAngmarPoisoned));
        this.npcItemsInv.setIdleItem(new ItemStack(LOTRMod.mugOrcDraught));
        this.setCurrentItemOrArmor(1, new ItemStack(LOTRMod.bootsFur));
        this.setCurrentItemOrArmor(2, new ItemStack(LOTRMod.legsAngmar));
        this.setCurrentItemOrArmor(3, new ItemStack(LOTRMod.bodyFur));
        this.setCurrentItemOrArmor(4, new ItemStack(LOTRMod.helmetFur));
        return data;
    }


    static {
        ANGMAR_BREWER_BUY = new LOTRTradeEntries(TradeType.BUY,
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugOrcDraught, 1, 9999), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugOrcDraught, 1, 9999), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugOrcDraught, 1, 9999), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugOrcDraught, 1, 9999), 8),
                new LOTRTradeEntryBarrel(new ItemStack(LOTRMod.mugOrcDraught, 1, 3), 180),
                new LOTRTradeEntryBarrel(new ItemStack(LOTRMod.mugOrcDraught, 1, 4), 300),
                new LOTRTradeEntry(new ItemStack(LOTRMod.mugMorgulDraught, 1, 9999), 8),
                new LOTRTradeEntryBarrel(new ItemStack(LOTRMod.mugMorgulDraught, 1, 3), 150),
                new LOTRTradeEntry(new ItemStack(CinderLoE.mugOrcBrew, 1, 9999), 200),
                new LOTRTradeEntry(new ItemStack(CinderLoE.spiceIngredient, 1, 2), 500));
        ((MixinLOTRTradeEntries)ANGMAR_BREWER_BUY).vessels(LOTRFoods.ORC_DRINK);

        ANGMAR_BREWER_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(LOTRMod.mug), 1),
                new LOTRTradeEntry(new ItemStack(LOTRMod.waterskin), 2),
                new LOTRTradeEntry(new ItemStack(LOTRMod.barrel), 10),
                new LOTRTradeEntry(new ItemStack(LOTRMod.morgulShroom), 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 "angmar/trader/friendly";
            }
            return "angmar/trader/neutral";
        }
        return "angmar/orc/hostile";
    }
    public boolean canTradeWith(EntityPlayer entityplayer) {
        return (LOTRLevelData.getData(entityplayer).getAlignment(getFaction()) >= 100.0F && isFriendlyAndAligned(entityplayer));
    }

    @Override
    public void onPlayerTrade(EntityPlayer entityplayer, LOTRTradeEntries.TradeType type, ItemStack itemstack) {
        LOTRLevelData.getData(entityplayer).addAchievement(LOTRAchievement.tradeAngmarTrader);
    }
}
