示例#1
0
    /*
     *  Find the entity group for the player's wish list, or create one if does not exist
     *
     *  @param player_entityKeyId: the entity ID of the player; for a title entity the ID should be;
     *      in most cases, this can be found in LoginResult.EntityToken.Entity.Id
     *  @param player_entityKeyType: the entity type of the player whose wish list we are searching
     *      for; should be title_player_account entity in most cases
     *
     */

    public static void FindOrCreateWishList(string player_entityKeyId, string player_entityKeyType)
    {
        PlayFab.DataModels.EntityKey ent = new PlayFab.DataModels.EntityKey {
            Id = player_entityKeyId, Type = player_entityKeyType
        };

        var req = new PlayFab.DataModels.GetObjectsRequest {
            Entity = ent
        };

        PlayFabDataAPI.GetObjects(req, result => {
            if (!result.Objects.ContainsKey("wishlist"))
            {
                // Empty so need to create
                CreateEntityWishList();
            }
            else
            {
                string wl = (string)result.Objects["wishlist"].DataObject;

                // Exists so can set up store
                StoreSetup.SetUpStore(wl, false);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
示例#2
0
    /*
     *
     *  Execute a PlayFab Cloud Script function to update the group entity object data to the
     *  updated CSV. Title-level data should not be changed directly from the client.
     *
     *  @param dataobj: the updated CSV; the Cloud Script function sets the entity group object data to
     *      this value.
     *  @param item_id: ItemID of the item that was either added or removed
     *
     */

    private void UpdateObject(string dataobj, bool adding_item, string item_id)
    {
        PlayFab.DataModels.EntityKey entity = new PlayFab.DataModels.EntityKey {
            Id = LoginClass.getPlayerEntityKeyId(), Type = LoginClass.getPlayerEntityKeyType()
        };

        List <PlayFab.DataModels.SetObject> ObjList = new List <PlayFab.DataModels.SetObject>();

        ObjList.Add(

            new PlayFab.DataModels.SetObject {
            ObjectName = "wishlist",
            DataObject = dataobj
        }

            );

        var request = new PlayFab.DataModels.SetObjectsRequest {
            Entity  = entity,
            Objects = ObjList
        };

        PlayFabDataAPI.SetObjects(request, result => {
            if (adding_item)
            {
                StoreSetup.SetUpStore(item_id, false);
            }
            else
            {
                StoreSetup.SetUpStore(item_id, true);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
示例#3
0
        //UTILS

        //Retruns a new GetObjectsRequest with with EscapedDataObject set
        private static GetObjectsRequest CreateGetCharacterObjectRequestEscaped(PlayFab.DataModels.EntityKey characterEntityKey)
        {
            return(new GetObjectsRequest
            {
                Entity = characterEntityKey,
                EscapeObject = true
            });
        }
示例#4
0
    /*
     *
     *  If the item is on the wish list, remove it. If the item is not on the wish list, add it.
     *
     *  @param item_id: ItemID of the item to be added to or remove from the wishlist
     *
     *  This function gets the "wishlist" object from the entity group data. If the item is on the wish list,
     *  this function updates the CSV by removing it. If the item is not on the wish list, this function
     *  updates the CSV by adding it. It then calls UpdateGroupObject, which updates the actual entity group data.
     *
     */

    public void UpdateWishlist(string item_id)
    {
        /* Create entity key and request to get object data from group. */
        PlayFab.DataModels.EntityKey group_ek = new PlayFab.DataModels.EntityKey {
            Id = WishList.group_entityKeyId, Type = WishList.group_entityKeyType
        };
        GetObjectsRequest getObjectsRequest = new GetObjectsRequest {
            Entity = group_ek
        };

        /* GetObjects to get the wish list in CSV form. */
        PlayFabDataAPI.GetObjects(getObjectsRequest, objectResult => {
            string wl;
            bool adding_item; // This tells us whether we are adding or removing an item from the wish list


            if (!string.IsNullOrEmpty((string)objectResult.Objects["wishlist"].DataObject))
            {
                wl = (string)objectResult.Objects["wishlist"].DataObject;  // string of the CSV of items on the wish list

                if (!WishlistContainsItem(wl, item_id))
                {
                    /* Wish list does not contain the item, so we must add it. */
                    wl          = AddItemToCSV(wl, item_id);
                    adding_item = true;
                }
                else
                {
                    /* Wish list contains item, so we must remove it. */
                    wl          = RemoveItemFromCSV(wl, item_id);
                    adding_item = false;
                }
            }
            else
            {
                wl          = item_id;
                adding_item = true;
            }

            /* UpdateGroupObject is where the entity group data is actually updated */
            UpdateGroupObject(wl, adding_item, item_id);
        }, error => {
            Debug.LogError(error.GenerateErrorReport());
        });
    }
示例#5
0
        void RetrieveCharacterData(ushort ConnectedClientID, string characterID)
        {
            PlayFab.DataModels.EntityKey characterEntityKey = CreateKeyForEntity(characterID, "character");
            GetObjectsRequest            getObjectsRequest  = CreateGetCharacterObjectRequestEscaped(characterEntityKey);

            PlayFabDataAPI.GetObjects(getObjectsRequest,
                                      result =>
            {
                PlayFabCharacterData characterData = PlayFabSimpleJson.DeserializeObject <PlayFabCharacterData>(result.Objects["CharacterData"].EscapedDataObject);
                Debug.Log($"character position for retrieved character: {characterData.WorldPositionX}, {characterData.WorldPositionY}, {characterData.WorldPositionZ}");
                characterData.SetWorldPosition(characterData.WorldPositionX, characterData.WorldPositionY, characterData.WorldPositionZ);
                Debug.Log($"character position AS VECTOR 3 for retrieved character: {characterData.WorldPosition.ToString()}");

                SetCurrentCharacterDataForConnectedClient(ConnectedClientID, characterData);
            }, error =>
            {
                Debug.Log("Error setting player info from PlayFab result object");
                Debug.Log(error.ErrorMessage);
            });
        }
示例#6
0
        void SaveCharacterData(PlayFabCharacterData characterData)
        {
            var dataList = new List <SetObject>();

            dataList.Add(ReturnNewSetObject("CharacterData", SetCharacterInfoData(characterData)));

            PlayFab.DataModels.EntityKey characterEntityKey = CreateKeyForEntity(characterData.CharacterID, "character");

            SetObjectsRequest setCharacterObjectDataRequest = new SetObjectsRequest()
            {
                Entity  = characterEntityKey,
                Objects = dataList
            };

            PlayFabDataAPI.SetObjects(setCharacterObjectDataRequest,
                                      result =>
            {
                if (characterData.IsInitialCharacterData)
                {
                    ushort clientID = ReturnClientConnectionByPlayFabCharacterID(characterData);

                    if (clientID != 9999)
                    {
                        ServerManager.Instance.SendToClient(clientID, Tags.RegisterNewCharacterResponse, new RegisterNewCharacterResponseData(true));
                    }
                    else
                    {
                        ServerManager.Instance.SendToClient(clientID, Tags.RegisterNewCharacterResponse, new RegisterNewCharacterResponseData(false));
                    }
                }
            },
                                      error =>
            {
                Debug.Log($"Failed to save character state data");
                Debug.Log(error.ErrorMessage);
                Debug.Log(error.ErrorDetails);
            });
        }
示例#7
0
    /*
     *
     *  If the wish list does not exist, we create an entity object for the player.
     *
     */

    private static void CreateEntityWishList()
    {
        PlayFab.DataModels.EntityKey entity = new PlayFab.DataModels.EntityKey {
            Id = LoginClass.getPlayerEntityKeyId(), Type = LoginClass.getPlayerEntityKeyType()
        };

        /* SetObjects takes in a list of type SetObject. These will contain the objects that we want to set. */

        List <PlayFab.DataModels.SetObject> ObjList = new List <PlayFab.DataModels.SetObject>();

        /*
         *  We will add an object of type wishlist. The DataObject is empty because we are initializing the entity object,
         *  as it does not exist. We do not have any ItemId's to add to the wish list yet.
         */

        ObjList.Add(

            new PlayFab.DataModels.SetObject {
            ObjectName = "wishlist",
            DataObject = ""
        }

            );

        var request = new PlayFab.DataModels.SetObjectsRequest {
            Entity  = entity,
            Objects = ObjList
        };

        /* Call PlayFab SetObjects to set the object data for the player entity. */

        PlayFabDataAPI.SetObjects(request, result => {
            /* The title player now has a wishlist object. */

            Debug.Log("Set object successful");
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
示例#8
0
    /*
     *  Find the entity group for the player's wish list, or create one if does not exist
     *
     *  @param player_entityKeyId: the entity ID of the player; for a title entity the ID should be;
     *      in most cases, this can be found in LoginResult.EntityToken.Entity.Id
     *  @param player_entityKeyType: the entity type of the player whose wish list we are searching
     *      for; should be title_player_account entity in most cases
     *
     *  Upon login, this function examines all entity groups that the player belongs to. For each group,
     *  the group name is compared to the nomenclature for wish list groups. If the group is not found,
     *  then one is created
     */

    public static void FindOrCreateWishList(string player_entityKeyId, string player_entityKeyType)
    {
        /* Create entity key for the ListMembership request */

        PlayFab.GroupsModels.EntityKey entity = new PlayFab.GroupsModels.EntityKey {
            Id = player_entityKeyId, Type = player_entityKeyType
        };

        var request = new ListMembershipRequest {
            Entity = entity
        };

        PlayFabGroupsAPI.ListMembership(request, membershipResult => {
            bool found = false; // Will tell us whether the wish list entity group exists

            /*
             *  Iterate through all groups the player belongs to. If the wish list entity group exists,
             *  it should be one of these groups
             */

            for (int i = 0; i < membershipResult.Groups.Count; i++)
            {
                string group_name = LoginClass.getPlayerEntityKeyId() + "wishlist";

                /* Compare the name of the group to the nomenclature the wish list entity group name will follow */

                if (membershipResult.Groups[i].GroupName.Equals(group_name))
                {
                    found = true; // If the name matches, we found the wish list entity group

                    /* Set the wish list group's entity ID and entity type so we can access the group in other functions */
                    WishList.group_entityKeyId   = membershipResult.Groups[i].Group.Id;
                    WishList.group_entityKeyType = membershipResult.Groups[i].Group.Type;

                    PlayFab.DataModels.EntityKey group_ek = new PlayFab.DataModels.EntityKey {
                        Id = membershipResult.Groups[i].Group.Id, Type = membershipResult.Groups[i].Group.Type
                    };
                    GetObjectsRequest getObjectsRequest = new GetObjectsRequest {
                        Entity = group_ek
                    };

                    /*  This is the wish list entity group. To get the wish list CSV, we need to get the object in that entity
                     *  group with the "wishlist" key
                     */

                    PlayFabDataAPI.GetObjects(getObjectsRequest, objectResult => {
                        if (!string.IsNullOrEmpty((string)objectResult.Objects["wishlist"].DataObject))
                        {
                            string wl = (string)objectResult.Objects["wishlist"].DataObject;
                            /* Set up the Unity game store. Specifically, change colors and button text if an item is on the wishlist */
                            StoreSetup.SetUpStore(wl, false);
                        }
                    }, error => { Debug.LogError(error.GenerateErrorReport()); });
                }
            }

            // AddPlayFabIdToGroup(); // Where should this go?


            /* Wish list entity group does not exist, so create one */
            if (!found)
            {
                /*
                 *  Wish list entity groups should follow the following nomenclature:
                 *  [PlayFab title ID] + "wishlist.
                 *
                 *  This nomenclature allows us to find the group by name in the future.
                 */
                string group_name = LoginClass.getPlayerEntityKeyId() + "wishlist";
                CreateWishlist(group_name);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }
示例#9
0
    public override void OnStartLocalPlayer()
    {
        if (LoginManager.instance.isGuest)
        {
            isGuest = true;

            CmdSetupPlayer("guest " + NetworkClient.connection.identity.netId, new Color(1f, 1f, 1f), Random.ColorHSV());
            CmdSendLoginMessage();
            return;
        }

        var userDataRequest = new GetUserDataRequest()
        {
            Keys = new List <string> {
                "rights"
            }
        };

        PlayFabClientAPI.GetUserData(userDataRequest, result =>
        {
            if (result.Data == null)
            {
                return;
            }

            if (result.Data.ContainsKey("rights"))
            {
                rights = Int16.Parse(result.Data["rights"].Value);
            }
        }, (error) =>
        {
            Debug.Log("Got error retrieving user data:");
            Debug.Log(error.GenerateErrorReport());
        });


        Color  nameColor;
        Color  matColor = Random.ColorHSV();
        string playerUserName;

        string email = String.IsNullOrEmpty(LoginManager.instance.emailField.text) ? PlayerPrefs.GetString("email") : LoginManager.instance.emailField.text;

        var accInfoRequest = new PlayFab.ClientModels.GetAccountInfoRequest {
            Email = email
        };

        PlayFabClientAPI.GetAccountInfo(accInfoRequest, (getResult) =>
        {
            playerUserName = getResult.AccountInfo.Username;

            if (rights > 1)
            {
                nameColor = new Color(255f, 174f, 0f);
            }
            else
            {
                nameColor = new Color(1f, 1f, 1f);
            }

            CmdSetupPlayer(playerUserName, nameColor, matColor);
            CmdSendLoginMessage();
        }, (error) =>
        {
            Debug.LogError(error);
            NetworkManager.singleton.StopClient();
        });

        playerEntity = LoginManager.instance.playerEntity;
    }