LaroTaio
Who many enemies will be on screen? I think this part of code could produce overhead. E.g. if there are 10 enemies on the screen they will all check every tick if they have line of sight. With the second part you want to create the alteration of time between two shots. I would recommend to use a "timer" for it. So when an enemy shoots you set a timer for "not being idle to shoot / reloading / waiting" (however you want to call it^^). Timers trigger automatically a state as soon as done. So you can not only use it for something like a bomb (trigger on finished) but for "is not counting down / blocked" right now. I would do it like this:
Every 0.1 seconds
-> check for enemies that are not "reloading" then
--> check if they have "line of sight"
If both is true spawn a bullet (shoot) and activate the timer of that enemey with a random number. I think sometimes it helps to try to put the code in human readable sentences or scenarios. E.g. your code above says:
the system is stressed and asking ten enemies on the layout every tick: "hey guys, do you have line of sight towards the player?" - three say "yes" and think (may we should? we are idle, never fired ever before). Seven say "no" (we don't see the player) The system want to give the order to fire but wait! System is cheking its watch and says: "sry guys, we can only shoot if the pointer for seconds is at 12 because you need time to reload. this will be in 6 seconds but never mind I will ask you 360 (60 ticks x 6 seconds) times until then if you have line of sight but won't give the order to fire". Enemies: "we don't need to relaod <img src="{SMILIES_PATH}/icon_evil.gif" alt=":evil:" title="Evil or Very Mad"> "
So the core question is why should everybody wait together. By timer you can tell single enemies to reload (wait). It doesn't matter if they have line of sight. So to give my example as a story:
the system is chilled and asking ten enemies on the layout every 6 ticks: "hey guys, please, everybody that is not currently reloading listen to me". All of them are answering "hey, we are idle" (but if some would say reloading that enemies would not listen anymore. The system says: "please check if you have line of sight to the player". Two enemies answer "yes, we do". system says: "ok fire and then you wait/reload". The system is randomly giving these two enemies tickets with numbers on it which says "reload 1 second" or "reload 2 seconds".
https://www.scirra.com/manual/167/timer