Objective: to implement a passive battle in an online game, that is, without the participation of the player. The player has fighters, each with a certain amount of damage per second. It is necessary to organize a battle of fighters with enemies, while the player does not take part directly in the battle, but simply watches the battle of his units.
My thoughts: implement a script that runs every second every second and analyzes the current, active battles of the players and organizes a combat round between units. But vryatli such an approach can be called correct, and most importantly, fast. Please share your thoughts on this matter.
Technologies: php, mysql, html
A script that runs every second is not the best approach 🙂
According to good practices, you need to write a daemon that will contain the logic of the battle, and when you send it a signal to start a battle from some client via the API (normal or proxying), it will write to the storage that the battle has started (you can show this to the client) and after which the battle itself is calculated in the demon, the moves are recorded in the storage and the battle is played back to the client (if required)
In fact, you can do this online without a daemon if the load is low and the calculations are simple and fast.