package holo.bolt.entity.hostiles;

import holo.bolt.entity.Entity;
import holo.bolt.entity.EntityHostile;
import holo.bolt.entity.EntityPlayer;
import holo.bolt.entity.IImmobile;
import holo.bolt.render.RenderEntity;
import holo.bolt.world.World;
import holo.bolt.world.map.tile.Tile;

public class EntityBasicRanged extends EntityHostile implements IImmobile
{
	RenderEntity render;
	public int shootTimer;
	
	public EntityBasicRanged(float[] position, World world)
	{
		super(position, new float[] {50, 44}, world);
		render = new RenderEntity(this);
		shootTimer = 800;
	}

	@Override
	public String getTextureLoc()
	{
		return "res/RangedMob1.png";
	}

	@Override
	public RenderEntity getRender()
	{
		return render;
	}

	@Override
	public void onCollideWithEntity(Entity ent)
	{
		if(ent instanceof EntityPlayer)
			this.damage(0.5F, ent.facing.copy().scale(2));
	}
	
	public void attack()
	{
		world.registerEntity(new EntityArrow(new float[] {this.pos[0] + this.facing.x * this.box.size[0] * 1.5F, this.pos[1] + this.facing.y * this.box.size[1] * 1.5F}, world, this.facing, this.getAttackDamage()));
	}

	@Override
	public void updateAI(int delta)
	{
		if(this.distanceToEntity(target) < 350)
		{
			this.lookat(target);
			if(this.shootTimer < 0)
			{
				this.attack();
				shootTimer = 800;
			}
			else
				this.shootTimer -= delta;
		}
	}

	@Override
	public float maxHealth()
	{
		return 2.5F;
	}

	@Override
	public float getAttackDamage()
	{
		return 1.0F;
	}

	@Override
	public void onCollideWithTile(Tile t){}

	@Override
	public int getScoreValue()
	{
		return 100;
	}

}
