package com.zivilon.cinder_loe.entity;

import java.util.UUID;

import lotr.common.entity.ai.LOTREntityAIAttackOnCollide;
import lotr.common.entity.npc.LOTREntityNPC;
import lotr.common.fac.LOTRFaction;

import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;

import com.zivilon.cinder_loe.CinderLoE;

public class Nex extends LOTREntityNPC {
    public AxisAlignedBB collisionBox;
    public AxisAlignedBB hitbox;
    public int phase = 1;
    public ChunkCoordinates currentFlightTarget;
    public EntityPlayer playerTarget;

    public Nex(World world) {
        super(world);
        setSize(1.5F, 3.0F);
        ((EntityLiving) this).tasks.addTask(2, (EntityAIBase) new LOTREntityAIAttackOnCollide(this, 1.3D, false));
        ((EntityLiving) this).tasks.addTask(5, (EntityAIBase) new EntityAIWander(this, 1.0D));
        ((EntityLiving) this).tasks.addTask(9, (EntityAIBase) new EntityAILookIdle((EntityLiving) this));
        addTargetTasks(true);
    }

    protected void entityInit() {
        super.entityInit();
        this.dataWatcher.addObject(31, Integer.valueOf(0));
    }

    protected void applyEntityAttributes() {
        super.applyEntityAttributes();
        getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(1000.0D);
        getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.2D);
    }

    public int getPhase() {
        return this.dataWatcher.getWatchableObjectInt(31);
    }
    public void setPhase(int i) {
        this.dataWatcher.updateObject(31, Integer.valueOf(i));
    }

    public LOTRFaction getFaction() {
        return LOTRFaction.UTUMNO;
    }

    public void writeEntityToNBT(NBTTagCompound nbt) {
        super.writeEntityToNBT(nbt);
        nbt.setInteger("NexPhase", getPhase());
    }

    public void readEntityFromNBT(NBTTagCompound nbt) {
        super.readEntityFromNBT(nbt);
        setPhase(nbt.getInteger("NexPhase"));
    }

    public boolean canBePushed() {
        return false;
    }

    protected void fall(float f) {}

    protected void updateFallState(double d, boolean flag) {}

    protected boolean canDespawn() {
        return false;
    }

    public void onLivingUpdate() {
        super.onLivingUpdate();
        if (rand.nextBoolean())
            ((Entity)this).worldObj.spawnParticle("chill", ((Entity)this).posX + (rand.nextDouble() - 0.5D) * ((Entity)this).width, ((Entity)this).posY + rand.nextDouble() * ((Entity)this).height, ((Entity)this).posZ + (rand.nextDouble() - 0.5D) * ((Entity)this).width, 0.0D, 0.0D, 0.0D);
    }

    protected void dropFewItems(boolean flag, int i) {
        return;
    }

    protected String getHurtSound() {
        return "lotr:wight.hurt";
    }

    protected String getDeathSound() {
        return "lotr:wight.death";
    }

    public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor) {
        // Do nothing
    }

    @Override
    public ItemStack getPickedResult(MovingObjectPosition target) {
        return null;
    }
}
