question

kennyroy avatar image
kennyroy asked

Entities, Entity Groups and using them as persistent Data "containers"

Hey guys, a long while back I was asking about using characters to represent multiplayer rooms that could have some custom data stored in them;

https://community.playfab.com/questions/18236/possible-to-query-all-users-for-the-same-character.html?childToView=18257#comment-18257

The problem was that I didn't fully understand the ownership of characters, and how intensive it would be to search the entire player database to see if someone had one character (only one person can "own" this multiplayer room at a time, and the game is to do battle and claim that room, essentially). There's more to it that involves saving some info to the "character" but those are the broad strokes.

However, now that there is Entity Groups, it seems like this is FAR more possible. Even if still impossible, I'd like to discuss the broad strokes again in the context of Entity Groups and see what you all think.

  1. Player A tries to join a room on photon. This assumes nobody has claimed this room before. Let's call it "Room A".
  2. Player A checks PlayFab for Entity Group "Room A". It doesn't exist. CloudScript fires that creates Room A and adds Player A as the only member. Player A roams around in Photon in Room A as well.
  3. Player B connects to the game. They chose to go to Room A. Photon returns the room in existence (Player A is still online). Playfab returns the Entity Group Room A as well. Player B sees that Player A "owns" Room A and he enters.
  4. They do battle and Player B wins.
  5. CloudScript removes Player A from EG "Room A" and adds Player B as the only member of Room A.
  6. Player B goes offline.
  7. Player C goes online.
  8. Player C chooses to go to Room A. The Photon room doesn't exist, but it is created again by Player C (the level's generation seed is the hashed name of the room, so everyone gets the same thing).
  9. Playfab returns the Entity Group Room A as well. Player C sees that Player B "owns" Room A and he enters.
  10. Photon triggers CloudScript to do a Push Notification to Player B, notifying them Player C is currently in Room A and will take control of it unless Player B logs in and defends it.
  11. Player B ignores so Player C can find the flag, replace it with their own, and trigger the Entity Group membership swap as described above.

Would this work?

Also, what kind of Data can be attached to an Entity Group? If I am procedurally generating the levels based of a seed of the room name, but I also want there to be some permanent destruction, etc., could I store this in the Entity Group itself? Or, would I make an Entity on Playfab that is a dummy Entity, that is always a member of a Room's Entity Group, for the sole purpose of having that custom data applied?

e.g. When you control a room, you get to hide the flag in a new spot. The v3 location and rotation of that flag would be stored in the EG (if possible), or in a dummy entity created when an EG is.

Open to thoughts.

entities
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kennyroy avatar image kennyroy commented ·

Oops. #6 is meant to read Player "A" goes offline.

0 Likes 0 ·
kennyroy avatar image kennyroy commented ·

Oops again, #6 meant to read BOTH Player "A" and Player "B" goes offline.

0 Likes 0 ·

1 Answer

·
v-humcin avatar image
v-humcin answered

Hello,

So far the described flow seems good, you are correct that Entity Groups will be a much better fit for this kind of functionality!

The biggest concern would be in how you are handling accessing these rooms and how many different people might try to access a room at one time. Are the names of these rooms based on some sort of world map that everyone can see and could try to join at any time? Can all players create there own room with any name and then player's will just browse different levels? Can only two players be in a room at once?

More information on how you are planning to handle room discover-ability and joining will be important to this functionality.

7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kennyroy avatar image kennyroy commented ·

So it's a Discord integrated game. The rooms are actually generated by your username on a Discord server. If a username doesn't exist, then the room cannot be joined/created. I'm using Discord API to get online members of a server, then a player would get those users as the available rooms to invade. The game offers me to invade them, and when I choose one, the level is seeded based on that name, I also go into the photon room of that name, and the game posts a message on the discord server with @thatperson from me through the Discord API that I'm in their room, killing their doods! They can log in the game and join their room to defend if they'd like.

The rooms are accessible by anybody on that discord server, to gamify the use of Discord channels. You have to be logged into discord (through API in-Game) to search the server for users anyway, so ALL rooms in existence are not indexable or searchable by a user, only the players logged into the server at the time they are playing on that discord server itself.

8 people can battle in a room, with 1 slot always reserved for the room owner.

0 Likes 0 ·
v-humcin avatar image v-humcin ♦ kennyroy commented ·

That system seems like it could work well to mitigate potential issues! The most important step would be having proper API access policies in place to make sure the groups are only being modified by the appropriate sources. As long as it is setup so that only one endpoint is trying to make updates for each group at a time then this seems like a good flow.

As for what kind of data can be stored in an Entity Group, being an entity they have access to all Entity based API including the Data API. You can store both JSON objects and files for entities. Files have a site-wide size limit rather than individual size limit. You can read more about Entity Objects and Entity Files here: https://docs.microsoft.com/en-us/gaming/playfab/features/data/entities/quickstart

0 Likes 0 ·
kennyroy avatar image kennyroy v-humcin ♦ commented ·

Ok very good.

Explaining a bit more: One of the data objects might be the arrangement of defenses around your flag. It would be a json object with turretType, v3 location and q rotation. To edit that though, you would have to own the room.

So I would just have the one request to take over a room made from the client that wins the room which calls cloudscript with some simple checks on their request to see if the battle was legit, (damage done, time in the room, etc.) From then on, only the owner can change that rooms specific data. (Moving the flag to a new spot a for example). So in essence you have to be logged into PF, and Photon, and in the room, and the room owner to be making these calls anyway too; so the frequency is super low on the data objects on the entity group. What is the object and filesize limit? My dashboard shows for Object, but not File.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.