Answer the question
In order to leave comments, you need to log in
Achievement system architecture design
The question arose of designing the architecture of the achievement system.
We are talking of course about the development of the logic of the server side of the application.
The game is a firmum for social networks.
Achievements are completely different:
1) logged in N days in a row
2) invited N friends
3) passed N levels
4) scored N specific achievements (roughly speaking, this allows you to organize a quest)
5) collected N money
, etc.
the number of such achievements can be measured in the hundreds.
I'm trying to come up with a solution so that the architecture is as flexible as possible and at the same time does not kill the performance of the application. Achievements should be displayed as soon as they are received (i.e. no cron\queue servers and other asynchronous ways to get data), i.e. the priority is still higher performance, flexibility of the solution.
"Achievements" are found in a huge number of games, of course there are own considerations, many solutions, I would like to ask the community - what system architecture did you choose?
Of particular interest is whether it is worth getting involved in the search for a universal solution, or split the achievements into groups and implement your own system for each group? What rake?
Database schemas and other diagrams in the answers are welcome.
Answer the question
In order to leave comments, you need to log in
My path would be like this:
- key-value db;
— each action generates an event;
- for each achievement there is a subscriber who happens the events he needs;
- when triggered, the subscriber reads the field in the database with the key __;
- compares with the limit;
- increases it or generates an event for adding a new achievement.
I do not pretend to be a solution, but the idea is this:
Most of the achievements are the number of some actions, that is, you need to do something several times. For these purposes, a table is created with the fields user id, achievement 1, achievement 2, ... achievement N. Accordingly, when the desired action is performed, the achievement in the table is increased.
Next, you can create a table with achievements already received, so that you can already take into account those achievements for which you need to complete several specific ones.
I think it will be easier to assign achievements itself with triggers that will check whether the achievement has been achieved when the record is updated.
This option will allow you to add achievements at any time, by simply adding a field to the table, and triggering more difficult achievements
Each achievement is a separate event handling logic. A chain of events comes into it, and the output is the result - the current state (for example,% completion).
Therefore:
1. We make the architecture of event subscription. Depending on the platform, you may need a separate event dispatcher.
2. We encapsulate the achievement logic as something that depends on the chain of events that came to it.
3. We call a check on triggers (for example, we have 90 achievements, we update the status on them at the end of each mission, provided that an event has come to the achievement).
4. We store the state in the database in any way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question