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

public class AngmarOrcSmith extends LOTREntityAngmarOrc implements LOTRTradeable.Smith {
    public static LOTRTradeEntries ANGMAR_SMITH_BUY;
    public static LOTRTradeEntries ANGMAR_SMITH_SELL;

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

    public LOTRTradeEntries getBuyPool() {
        return ANGMAR_SMITH_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return ANGMAR_SMITH_SELL;
    }

    public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) {
        data = super.onSpawnWithEgg(data);
        this.npcItemsInv.setMeleeWeapon(new ItemStack(LOTRMod.blacksmithHammer));
        this.npcItemsInv.setIdleItem(this.npcItemsInv.getMeleeWeapon());
        this.setCurrentItemOrArmor(1, new ItemStack(LOTRMod.bootsFur));
        this.setCurrentItemOrArmor(2, new ItemStack(LOTRMod.legsFur));
        this.setCurrentItemOrArmor(3, new ItemStack(LOTRMod.bodyBone));
        this.setCurrentItemOrArmor(4, new ItemStack(LOTRMod.helmetAngmar));
        return data;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

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


    static {
        ANGMAR_SMITH_BUY = new LOTRTradeEntries(TradeType.BUY,
                new LOTRTradeEntry(new ItemStack(CinderLoE.helmetRhudaur), 22),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bodyRhudaur), 32),
                new LOTRTradeEntry(new ItemStack(CinderLoE.legsRhudaur), 28),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bootsRhudaur), 20),
                new LOTRTradeEntry(new ItemStack(CinderLoE.forgingKit, 1, 1), 200),
                new LOTRTradeEntry(new ItemStack(CinderLoE.forgingKit, 1, 0), 200),
                new LOTRTradeEntry(new ItemStack(LOTRMod.blacksmithHammer), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.helmetAngmar), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bodyAngmar), 30),
                new LOTRTradeEntry(new ItemStack(LOTRMod.legsAngmar), 26),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bootsAngmar), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.swordAngmar), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.spearAngmar), 15),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerAngmar), 8),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerAngmarPoisoned), 10),
                new LOTRTradeEntry(new ItemStack(LOTRMod.battleaxeAngmar), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.polearmAngmar), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.orcBow), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pickaxeAngmar), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.axeAngmar), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.hammerAngmar), 16),
                new LOTRTradeEntry(new ItemStack(Items.arrow, 4), 3),
                new LOTRTradeEntry(new ItemStack(LOTRMod.wargArmorAngmar), 25));

        ANGMAR_SMITH_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(LOTRMod.orcSteel), 3),
                new LOTRTradeEntry(new ItemStack(Items.string, 3), 1),
                new LOTRTradeEntry(new ItemStack(Items.iron_ingot), 3),
                new LOTRTradeEntry(new ItemStack(Items.leather), 2),
                new LOTRTradeEntry(new ItemStack(Items.coal, 2), 1),
                new LOTRTradeEntry(new ItemStack(CinderLoE.leatherBundle), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.oreMorgulIron), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.guldurilCrystal), 8),
                new LOTRTradeEntry(new ItemStack(Blocks.iron_ore), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.oreCopper), 5),
                new LOTRTradeEntry(new ItemStack(LOTRMod.oreTin), 5),
                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";
    }

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

}
