Hi there,
New to Playfab but have found it a nice and intuitive system to use so thanks!
I built my game originally to be offline but as i wanted to bring it online i needed a backend service to start running some server authoritative code which bought me to playfab.
My game:
It's quite similar in layout to a mobile game like clash of clans, you can have buildings, they have their own stats as well as an X and Y coordinate to say where they are in your base.
My question is three parts so apologies for the length.
Question 1 - where / how do i save and also load my json data.
At the moment i write this all to json and save it locally then load it in each playthrough. the data looks similar to this:
{"sceneData":{"items":[{"instanceId":1,"itemId":3635,"posX":28,"posZ":20,"currentLv":1},{"instanceId":2,"itemId":2496,"posX":22,"posZ":17,"currentLv":1},{"instanceId":59892,"itemId":4764,"posX":21,"posZ":11,"currentLv":1},{"instanceId":63502,"itemId":7666,"posX":26,"posZ":19,"currentLv":1},{"instanceId":26143,"itemId":1502,"posX":23,"posZ":25,"currentLv":1}]}}
I then have a supporting scriptable object that has all the configuration/item data about my itemId, so that i can keep a reduced DB size and not have to save alot per itemID:
I don't think i can keep this system when the game goes online, while i don't understand client hacking too well, i believe they could just hack a new value into the production rate as an example, and they would then be making way more. So i think this data also needs to be going up into the cloud.
I was reading a different thread about someone with a similar json structure and them trying to save it to playerdata as a read only string. They were encouraged by staff to rather try using the catalog / inventory system instead. I tend to agree with this because of the frequency i'll be making updates to things like position, i wouldn't want to be pulling back the data for my entire town every time i dragged a building. (i could mitigate this with only saving on exit etc but i digress).
So i started with a building like this:
I wrote some server code:
handlers.AddBuilding = function (args, context) {server.GrantItemsToUser({PlayFabId: currentPlayerId, ItemIds: "3265", CatalogVersion: "Buildings"}) var results = result.ItemGrantResults; //get the results var instId = results[0].ItemInstanceId; //get the instance ID to be adding custom data to. server.UpdateUserInventoryItemCustomData ({ PlayFabId: currentPlayerId, ItemInstanceId: instId, Data: {"Name":"GoldMine","Max Building Lv":"10","Grid Size":"3","Build Time":"30","Production Rate":"200","Product Max":"500","Power":"100","Product":"gold"} }); }; //add my custom data.
Client code:
public void AddBuildingStats() // will need to take a parameter of ID. { PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest() { FunctionName = "AddBuilding", //arbitrary function name (must exist in your uploaded cloud.js file --- the automation area) //FunctionParameter = i don't have the parameters yet, still working on making it work. GeneratePlayStreamEvent = true, //shows it in the playstream console. }, OnAddBuildingSuccess, //successful HTTP response. OnErrorShared); //failed HTTP response. } public void OnAddBuildingSuccess(ExecuteCloudScriptResult result) { Debug.Log("Hey you added a building!"); //actually build the building from your other code. }
My challenge is, i'm not sure how i can take my inventory items and convert it back into the json structure the game currently runs on.
Question 2 - The Configuration data
I'm not sure where i store the configuration data. it is all static values, but i need to have it in the cloud so that i can reference in my server code. Aka, a user wants go from a level 1 - 2 building, The client would submit 'level up' request along with the building ID. i would then need to check virtual currency, and some of the configuration data to determine the buildings new values as well as some other sense checks.
Question 3 - Virtual currency on new inventory item
I want to be reducing virtual currency based on the inventory item's cost. I can see there's a setup for this in the catalog item, just not sure how to reference it. once i have that i suppose it would be storing it as a var and subtracting it with SubtractUserVirtualCurrency
Apologies for all the text - i've changed the method of storing and saving data many times so i figured if i give you as much information you can guide me in the right direction.
Thanks,