package com.zivilon.cinder_loe.entity.npc.evil_human;

import com.zivilon.cinder_loe.CinderLoE;

import lotr.common.LOTRMod;
import lotr.common.entity.ai.LOTREntityAIRangedAttack;
import lotr.common.entity.projectile.LOTREntityDart;
import lotr.common.item.LOTRItemBlowgun;
import lotr.common.item.LOTRItemDart;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;


public class LimwaithBlowgunner extends Limwaith {
    public LimwaithBlowgunner(World world) {
        super(world);
    }

    public EntityAIBase createHaradrimAttackAI() {
        return (EntityAIBase)new LOTREntityAIRangedAttack(this, 1.5D, 10, 30, 16.0F);
    }

    protected void applyEntityAttributes() {
        super.applyEntityAttributes();
        getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(24.0D);
    }

    public IEntityLivingData onSpawnWithEgg(IEntityLivingData data) {
        data = super.onSpawnWithEgg(data);

        this.npcItemsInv.setMeleeWeapon(new ItemStack(CinderLoE.blowgunLimwaith));
        this.npcItemsInv.setIdleItem(this.npcItemsInv.getMeleeWeapon()); 

        this.npcItemsInv.setIdleItem(this.npcItemsInv.getMeleeWeapon());
        setCurrentItemOrArmor(1, new ItemStack(CinderLoE.bootsLimwaith));
        setCurrentItemOrArmor(2, new ItemStack(CinderLoE.legsLimwaith));
        setCurrentItemOrArmor(3, new ItemStack(CinderLoE.bodyLimwaith));
        return data;
    }

    public void attackEntityWithRangedAttack(EntityLivingBase target, float f) {
        ItemStack heldItem = getHeldItem();
        float str = 1.0F + getDistanceToEntity((Entity)target) / 16.0F * 0.015F;
        str *= LOTRItemBlowgun.getBlowgunLaunchSpeedFactor(heldItem);
        LOTREntityDart dart = ((LOTRItemDart)LOTRMod.tauredainDart).createDart(((Entity)this).worldObj, (EntityLivingBase)this, target, new ItemStack(LOTRMod.tauredainDart), str, 1.0F);
        if (heldItem != null)
            LOTRItemBlowgun.applyBlowgunModifiers(dart, heldItem); 
        playSound("lotr:item.dart", 1.0F, 1.0F / (rand.nextFloat() * 0.4F + 1.2F) + 0.5F);
        ((Entity)this).worldObj.spawnEntityInWorld((Entity)dart);
    }
    protected void dropFewItems(boolean flag, int i) {
        super.dropFewItems(flag, i);
        dropNPCAmmo(LOTRMod.tauredainDart, i);
    }
    @Override
    public ItemStack getPickedResult(MovingObjectPosition target) {
        return new ItemStack(CinderLoE.spawnEgg, 1, 7);
    }

}
