Design/Pattern/Architecture help needed
I'm developing a game.
In that game every user have a lot of data stored in database on the server. Such as "Gold Currency", "Ruby Currency", "Unlocked Avatars", "Quests Progress", "Rank", "Level", "Collectable Towers Level and Amount" etc.
There is ingame shop, for example. In which you can buy things like some amount of collectable towers in exchange for ingame currency.
Every action (such as buying something from shop) is done via REST request to backend server. And in order to synchronize data between client and backend, we create response models for each request, that would contain every possible data that could've changed during that request and apply the deltas.
Pseudocode example of button in the ingame shop:
As seen in the example, this code assumes, that the only thing you can buy in shop is tower and shows the tower acquired animation itself, which is not something I'm ok with. Additionally, it also assumes that we spent some currency at the process. By the way,
response.currencyDelta
in the example is something like
So the problems with this:
1. OnClick button code triggers "tower acquired animation" itself
2. We can only use Currency
as price for buying in shop. What if I want to take something else from the player that is not considered Currency
type or not to take anything at all
3. We can only buy tower. And I would need to add more code here and in response model to support any other type of item sold in shop3 Replies
And this was just one example. What I want is the underlying system that would help me to synchronize any data that could've possibly changed during any request processing. As well as triggering any animations or popups that may be needed in the process.
So the ingame shop button code would simply become:
and the general logic would be somewhere inside like
of course I could make insanely large class containing every possible delta and make a tower of
if
statements in the response handler. That would even be fast server-side because server is on TypeScript and doesn't need to create full object to serialize. But I feel there is something betterit's called "a database"...?
To sync data changes you want a db
And a better planning of your dto's
Your question regarding paying with something else than an in-game currency boils down to how you implement things
Both your money and whatever else classes can inherit an interface or base class that would be provided to a Pay function that consumes the given item from the player's inventory
Take a step back from implementing and think everything through, regardless of what you've already implemented
Otherwise down the road you might face a huge issue that can only be solved be rewriting everything from scratch....