Creating a server for online MMO games in PHP part 9 – Game server mechanics

After successfully optimizing the client side and server architecture, it’s time to write the mechanics of the game itself for interaction via API – I call them events (they are hung up on some game object on the server, placed in a queue and triggered when their time comes).

The essence of the interaction between the authoritarian server and the client part is as follows:

  1. We create a group in which some game mechanics will be collected (for example, go to the specified point, go in the specified direction, follow the specified object).

  2. We specify the timeout for calling the mechanics of this group in seconds or in the form of a code that will result in a floating point number (for example, a pause between movements 1 / скорость * магнитуду направленииbut it can also be 0 – for example, on the mechanics of taking damage).

  3. We indicate whether the player can call the mechanic directly (if not, it can only be called from another mechanic, for example, calling the mechanic of taking damage on attack).

  4. We can specify what additional parameters can be when calling the mechanics (for example, the amount of life regeneration or the amount of damage).

  5. We specify whether it is necessary to send a packet with data when the mechanic is applied to some creature (for example, you can send a timeout, additional mechanic parameters such as damage amount).

  6. And finally, we specify the mechanics code itself, which manipulates the parameters of the object on which the mechanics worked and those objects that are on the map.

  7. Additionally, you can specify whether it is necessary to hang an event on the same creature when it works out (for example, regeneration is necessary).

An example of creating a game mechanics group

An example of creating a game mechanics group

example of several game mechanics in one group

example of several game mechanics in one group

example code when creating game mechanics in the mechanics group

example code when creating game mechanics in the mechanics group

An example code for adding a simple mechanic to LUA

An example code for adding a simple mechanic to LUA

Thus, you can create a lot of mechanics that can be called by sending a packet over a Websocket connection from the client side, as well as called by chain inside each other. Plus, we can change the code of their work without changing anything in the client (if this does not affect some visual part that has not yet been implemented).

When measuring the speed of work on a VPS with 2 processor cores and 4GB of RAM, the results tend to 1.000.000 RPS and this is only on the CPU (in the future I plan to implement parallel computing on the GPU), although there are long mechanics such as:

  • saving to the player’s database (despite the fact that it is already being done asynchronously)

  • pathfinding calculation when moving to a point

speed of execution of game mechanics on the server

speed of execution of game mechanics on the server

In the previous article, I talked about horizontal scaling of the game server, so that when you reach 60FPS from the server (in the example above, it is 1000FPS), you can shift the calculations of part of the open world to another hardware (I will talk about the open seamless world in the following articles that you can find on my profile).

In conclusion, I prepared a couple of short and not only videos demonstrating the code and the work of the game mechanics of the project (demo access is available on the website my-fantasy.com). There is still a long way ahead in which it will be necessary to develop mechanics for MMO RPGs related to physics.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *