Hi everyone !
So I’m making a CCG (collectible card game) on Unity with Unity Multiplayer.
First, some context :
My model is obviously Hearthstone (HS), in terms of gameplay, but also in terms of networking.
In HS, clients are only remote controllers that tell the server what the client wants to do, an display what’s happening on the Server. The server is therefore doing all the logic part, like authorizing the player to make his move, calculating the damage, the activation of special effects…
You have a simplified representation of how the server part is working : here.
And what I’ve already done :
For the moment I coded both the server and the client code in the same scene.
I used the newtork GUI so I can choose if I want the instance of my game to be a server or a client (or even a host). If I choose server, nothing really happen until I choose to be a client on two other instances (when 2 clients enter the room), which start the game.
I’ve got a some GameObjects that are “server only” that help the networking and logic parts (with attached NetworkingBehaviour scripts). I have a player prefab which is instanciated for each player joining the room. And all the other GameObjets are basic Monobehaviour objects.
I’ve coded the game in a way where the logic part is only made on the server instance of the game, and the results are send to clients via RPC. For example when a player draw a card, I send a RpcDrawACard, and if the player that draw is the local client of the game instance, the card is drawn by the “bottom hero” (and visible), if the player is not the local client of the game instance, the card is drawn by the “top hero” (and not visible yet).
For the player actions I used Command functions. The client Player says what he wants to do, the Player on the server check if he can do that : if he can the actions are made and displayed on both clients screen via Rpc…
Now my problems :
When I use the Matchmaker, so that 2 players can play via internet, I can’t choose if I want to be a server or a client. If I understand well, when you create a room with the matchmaker, you are the host of the game. And that’s a real problem for my game, because I need the logic part to be separated (avoid cheating, the game continue event if one player disconnect). I need the server to be authoritative, the clients always need to go through it to interact.
Thus, I don’t even know if my method of using the same scene is accurate, because the logic code would be stored in the compilated client game.
Lastly, I would like to have a system that can store the cards of the players on a server, so they need to login to have access to their own collection.
Some leads I have :
As I said before, I’m a real noob, but I did some research.
I found Photon cloud and PUN, which does basically the same thing that Unity Multiplayer.
But somewhere I read that the photon rooms where hosted online, so wouldn’t it better than what I’m currently using ?
I also read that It wasn’t enough, and that I needed to use Photon Server, and to write the logic for it and not in unity…
For player profiles and collection, I heard about Playfab. I saw that it’s compatible with unity and photon, do you think it’s a good way to achieve what I want ?
For the moment I store my cards in Scriptable objects but if I want to store them on a server wouldn’t I need to “convert” them into text files with all their informations ?
As you can see I know what I want but I’m a bit lost on how to do it, I really need some help !