Hello!

Task: in an online game to realize a passive battle, that is, without the participation of a player. The player has fighters, each has 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: to implement a script that starts every second in crowns and analyzes current, active player battles and organizes a combat round between units. But this approach can hardly be called correct, and most importantly, fast. Please share your thoughts on this.

Technologies: php, mysql, html

  • The classic cron has a minimum frequency of 1 minute. In general, it is better to dig in line queues, built either on Redis or on RabbitMQ. - cheops

1 answer 1

The 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 a signal to him to start the battle from some client through the API (normal or proxy), he will write to the storage that the battle has begun (you can show it 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 to the client (if required)

In fact, you can do it online without a daemon, if the load is low and the calculations are simple and fast.