M
M
Maxim Grechushnikov2014-10-31 17:24:25
PHP
Maxim Grechushnikov, 2014-10-31 17:24:25

PhpGameDev: Saving the state of a random NPC during combat. How?

I decided to try my hand at game development. The first question.
There is an NPC model and a User model.
Everything is clear with User, his skills are calculated based on specific data from the database or from somewhere else.
How are the NPCs? There is a page where I randomly generate NPC object skills. I show these characteristics on the page. But how to attack NPCs? On the new page, you will have to create a new object, and this new NPC will turn out, with different characteristics.
At the moment, I have come to the conclusion that I save the NPC object in the session. To what extent is this decision correct? I think it's expensive to store NPC data in the database.
If we count on 20 thousand players online, will my server not bend if the sessions are stored, for example, in radish?
ja4uL8UKZJ4.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yeletsky, 2014-11-01
@maxyc_webber

- Keeping the NPC makes sense in the essence of the "current battle", but where to store it is already a difference.
- If by saving to session means saving to cookies, then this is a bad idea, because, in the case of two simultaneous requests from the user, there will be conflicts.
- If saving to the session means saving on the server side, then this is most likely the saving in the database.
- “If you count on 20 thousand players online, will it bend over ...” - the question is not correct, because. the logic of the game and the hardware on the server are not described. If the calculation of the move is once a day, then it will not bend, if it is once a second, then it may bend.
- The number of online, by the way, is wildly optimistic.
There are two options:
1. Store in the database.
2. Store in a background process in memory, which does the logic calculation without accessing the database.
In the second case, you can communicate with such a process, for example, by sending amqp messages. The process can both store the results of calculations in the cache (which is much faster than the database), and send it immediately to the client (websockets).
If this is a commercial project OBJECTIVELY having the opportunity to get 20k online, get confused by the 2nd option. If it's a hobby, a prototype, or just learning new technology - don't bother and start from the 1st one as the game develops, things will become more obvious.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question