package projectzombie.tiles;

import java.util.Random;

import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d;
import projectzombie.entity.Entity;
import projectzombie.entity.EntityAlive;
import projectzombie.entity.particle.ParticleLava;
import projectzombie.init.Models;
import projectzombie.model.Model;
import projectzombie.util.TileState;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;

public class TileLava extends Tile
{
	private Random rand = new Random();

	public TileLava() {
		
		this.slowness = 0.5;
		this.tileWalkable = false;
		this.emitsLight = true;
		this.unbreakable = true;
	}
	
	@Override
	public Model getModel(byte meta) {
		return Models.TILE_LAVA;
	}
	
	@Override
	public double getLightLevel(TileState state, Vec2i pos) {
		return 0.8;
	}
	
	@Override
	public void onWalkedOn(Chunk chunk, Layer layer, Vec2i pos, Entity entity, TileState state)
	{
		// Call super
		super.onWalkedOn(chunk, layer, pos, entity, state);
		
		// Create a lava particle
		layer.spawnEntity(new ParticleLava(entity.getPos(), entity.getVelocity(), 1));
		
		if(entity instanceof EntityAlive) {
			EntityAlive ea = (EntityAlive) entity;
			ea.addFireDamage(5);
		}
	}
	
	@Override
	public void tickRandomly(Layer layer, Chunk chunk, TileState state, Vec2i pos) {
		super.tickRandomly(layer, chunk, state, pos);
		
		if(rand.nextDouble() > 0.98) {
			chunk.spawnEntity(new ParticleLava(new Vec3d(
					pos.x + rand.nextDouble(), 0, pos.y + rand.nextDouble()), new Vec3d(0, 0, 0)));
		}
	}
	
	@Override
	public double getResistance(TileState state) {
		return 0.75;
	}
	
	@Override
	public double getSlipperiness(TileState state) {
		return 0.75;
	}

}
