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.world.World;

public class IsengardOrcSmith extends LOTREntityUrukHai implements LOTRTradeable.Smith {
    public static LOTRTradeEntries URUK_SMITH_BUY;
    public static LOTRTradeEntries URUK_SMITH_SELL;

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

    public LOTRTradeEntries getBuyPool() {
        return URUK_SMITH_BUY;
    }

    public LOTRTradeEntries getSellPool() {
        return URUK_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(Items.leather_boots));
        this.setCurrentItemOrArmor(2, new ItemStack(LOTRMod.legsBronze));
        this.setCurrentItemOrArmor(3, new ItemStack(LOTRMod.bodyBone));
        this.setCurrentItemOrArmor(4, new ItemStack(LOTRMod.helmetFur));
        return data;
    }

    public float getAlignmentBonus() {
        return 2.0F;
    }

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


    static {
        URUK_SMITH_BUY = new LOTRTradeEntries(TradeType.BUY,
                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.helmetUruk), 24),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bodyUruk), 36),
                new LOTRTradeEntry(new ItemStack(LOTRMod.legsUruk), 30),
                new LOTRTradeEntry(new ItemStack(LOTRMod.bootsUruk), 22),
                new LOTRTradeEntry(new ItemStack(LOTRMod.scimitarUruk), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.spearUruk), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerUruk), 9),
                new LOTRTradeEntry(new ItemStack(LOTRMod.daggerUrukPoisoned), 11),
                new LOTRTradeEntry(new ItemStack(LOTRMod.battleaxeUruk), 20),
                new LOTRTradeEntry(new ItemStack(LOTRMod.hammerUruk), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pikeUruk), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.urukCrossbow), 18),
                new LOTRTradeEntry(new ItemStack(LOTRMod.crossbowBolt, 4), 3),
                new LOTRTradeEntry(new ItemStack(Items.iron_pickaxe), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.axeBronze), 12),
                new LOTRTradeEntry(new ItemStack(Items.iron_axe), 14),
                new LOTRTradeEntry(new ItemStack(LOTRMod.pickaxeUruk), 16),
                new LOTRTradeEntry(new ItemStack(LOTRMod.axeUruk), 16),
                new LOTRTradeEntry(new ItemStack(CinderLoE.helmetOrthancGuard), 100),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bodyOrthancGuard), 100),
                new LOTRTradeEntry(new ItemStack(CinderLoE.legsOrthancGuard), 100),
                new LOTRTradeEntry(new ItemStack(CinderLoE.bootsOrthancGuard), 100),
                new LOTRTradeEntry(new ItemStack(LOTRMod.wargArmorUruk), 25));

        URUK_SMITH_SELL = new LOTRTradeEntries(TradeType.SELL,
                new LOTRTradeEntry(new ItemStack(LOTRMod.bronze), 3),
                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(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 void onPlayerTrade(EntityPlayer entityplayer, LOTRTradeEntries.TradeType type, ItemStack itemstack) {
        LOTRLevelData.getData(entityplayer).addAchievement(LOTRAchievement.tradeUrukTrader);
    }

    @Override
    public String getSpeechBank(EntityPlayer entityplayer) {
        if (this.isFriendlyAndAligned(entityplayer)) {
            if (this.canTradeWith(entityplayer)) {
                return "isengard/trader/friendly";
            }
            return "isengard/trader/neutral";
        }
        return "isengard/orc/hostile";
    }
}
