for (var i = 0; i < spawnedEntities.length; i++) 
{
    var ent = spawnedEntities[i];
            ent.texture = "/newmobs/" + ent.getClassType() + ".png"
}

try
{
for (var i = 0; i < spawnedEntities.length; i++) {
    var ent = spawnedEntities[i];
    if (!ent.isAlive()) {
        if (k[i] < 10) {
            var drops = ent.getEntitiesWithinRange(1);
            for (var j = 0; j < drops.length; j++) {
                if (drops[j].getClassType() == "Item") {
                    drops[j].setDead();
            }   }
            k[i]++;
        }
        else {
            drop(ent);
            ent.spawnExplosionParticle();
            ent.setDead();
            k.splice(i, 1);
}   }   }

}
catch(e){}

for (var i = 0; i < spawnedEntities.length; i++) 
	{
	var ent = spawnedEntities[i];
	var s = ent.getHealth();
	if (s > 26) 
		{
		ent.setMoveSpeed(1);
		}
	}

for (var i = 0; i < spawnedEntities.length; i++) 
	{
	var ent = spawnedEntities[i];
	var s = ent.getHealth();
	if (s < 25) 
		{
		ent.setMoveSpeed(3);
		}
	}

for (var i = 0; i < spawnedEntities.length; i++) 
	{
	var ent = spawnedEntities[i];
	var pos = ent.getPosition();
        ent.setPosition(pos.x, pos.y, pos.z);
	if(s < 25 && robot == 0)
		{
		sound.playSound3D("sound.disfonctionnement",pos.x,pos.y,pos.z);
		ent.setStunned(100);
		robot=1;
			for (var i=0; i<50; i++)
			{
			ent.spawnExplosionParticle();
			}
		}
	}

try{
if (o<=20){
o = o+1
}
if (o==20){
o = 0
     if (particle == 0)    
	{
		 ent.spawnExplosionParticle();
		 particle = 1
	}
		function CreateFireProjectile()
		{
			var mpos = ent.getPosition();
			var mdir = ent.getLookVec();
			// creation de la bdf
			var projectile = effect.spawnParticle("reddust", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
			projectile.setPosition(mpos.x + mdir.x, (mpos.y)+1, mpos.z + mdir.z); //point d'apparition
			projectile.setVelocity(mdir.x * FIRE_SPEED, mdir.y * FIRE_SPEED, mdir.z * FIRE_SPEED);
			projectile.collidesWithClipBlocks = false;
			fireProjectiles.splice(fireProjectiles.length, 0, Array(FIRE_LIFE, projectile, projectile.position.x, projectile.position.y, projectile.position.z, projectile.velocity.x, projectile.velocity.y, projectile.velocity.z));
		}
	CreateFireProjectile();
}

		
	for (var i = 0; i < fireProjectiles.length; i++)
	{
		var deleted = false;
		// prendre la position du prochain projectil
		
		fireProjectiles[i][2] += fireProjectiles[i][5];
		fireProjectiles[i][3] += fireProjectiles[i][6];
		fireProjectiles[i][4] += fireProjectiles[i][7];
		
		// garder le projectil en memoire
		var projectile = effect.spawnParticle("reddust", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
		var fpx = fireProjectiles[i][2];
		var fpy = fireProjectiles[i][3];
		var fpz = fireProjectiles[i][4];
		
		var fvx = fireProjectiles[i][5];
		var fvy = fireProjectiles[i][6];
		var fvz = fireProjectiles[i][7];
		
		projectile.setPosition(fpx, fpy, fpz);
		projectile.setVelocity(fvx, fvy, fvz);
		projectile.collidesWithClipBlocks = false;
		fireProjectiles[i][1].setDead();
		fireProjectiles[i][1] = projectile;
		
		// creation fumée
		for (var j = 0; j < 5; j++)
		{
			var x = fireProjectiles[i][1].position.x + ((Math.random() * 0.2) - 0.1);
			var y = fireProjectiles[i][1].position.y + ((Math.random() * 0.2) - 0.1);
			var z = fireProjectiles[i][1].position.z + ((Math.random() * 0.2) - 0.1);
			var arg1 = 1.0;
			var arg2 = 0.5 + ((Math.random() * 0.5) - 0.25);
			var arg3 = 0.0;
			effect.spawnParticle("reddust", x, y, z, arg1, arg2, arg3);
		}
if (!deleted)
		{
			// conlision joueur + degats
			var mobsHit = fireProjectiles[i][1].getEntitiesWithinRange(1.0);
			if (mobsHit != null && mobsHit.length > 0)
			{
				for (var i = 0; i < mobsHit.length; i++)
				{
					try{
					if (mobsHit[i].getClassType() == "Player")
					{
						mobsHit[i].attackEntityFrom(player, 1);
						FireRodImpact(fireProjectiles[i][1].position.x, fireProjectiles[i][1].position.y, fireProjectiles[i][1].position.z, false);
						fireProjectiles[i][1].setDead();
						fireProjectiles.splice(i, 1);
						deleted = true;
					}
					}
					catch(fail)
					  {
					  }
				}
			}
		}
		
	
		if (!deleted && fireProjectiles[i] != null)
		{
			// colision contre les block
			fProjPosX = fireProjectiles[i][1].position.x + fireProjectiles[i][1].velocity.x;
			fProjPosY = fireProjectiles[i][1].position.y + fireProjectiles[i][1].velocity.y;
			fProjPosZ = fireProjectiles[i][1].position.z + fireProjectiles[i][1].velocity.z;
			if (world.getBlockID(Math.floor(fProjPosX), Math.floor(fProjPosY), Math.floor(fProjPosZ)) != 0)
			{
				FireRodImpact(fireProjectiles[i][1].position.x, fireProjectiles[i][1].position.y, fireProjectiles[i][1].position.z, true);
				fireProjectiles[i][1].setDead();
				fireProjectiles.splice(i, 1);
			}
		}
	}
	
	//explosion a l'impact
function FireRodImpact(x, y, z, hitBlock)
{
	x = Math.floor(x);
	y = Math.floor(y);
	z = Math.floor(z);

	for (var i = 0; i < 25; i++)
	{
		var px = x + ((Math.random() * 0.5) - 0.25);
		var py = y + ((Math.random() * 0.5) - 0.25);
		var pz = z + ((Math.random() * 0.5) - 0.25);
		effect.spawnParticle("reddust", px, py, pz, 0.0, 0.0, 0.0);
	}
}
	 }
	 catch(e)
	 {
	 }