示例#1
0
        public override async Task <CloudScriptResponse> ExecuteStackAsync(CloudScriptRequestStack request)
        {
            DateTime benginRequest = DateTime.UtcNow;

            if (IsClientValidRequest(request))
            {
                var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

                if (await PlayFabApiHandler.GetPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    MetaDataState state = MetaDataState.FromJson <MetaDataState>(cloudData.DataAsString);

                    foreach (var stack in request.CloudScriptMethod)
                    {
                        string settingId = stack.Params["key"];

                        switch (stack.Params["type"])
                        {
                        case "setting":

                            int value = Convert.ToInt32(stack.Params["value"]);
                            state.SettingState.SetSetting(settingId, value);
                            break;

                        case "tutorial":
                            bool tutorialProgressValue = Convert.ToBoolean(stack.Params["value"]);
                            state.SettingState.SetTutorialProgress(settingId, tutorialProgressValue);
                            break;

                        case "keyvaluepairs":
                            string keyValue = stack.Params["value"];
                            state.SettingState.SetKeyValuePairs(settingId, keyValue);
                            break;
                        }
                    }

                    cloudData.DataAsString = state.ToJson();

                    if (await PlayFabApiHandler.UploadPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                    {
                        cloudData
                    }))
                    {
                        var response = new CloudScriptResponse()
                        {
                            ResponseCode = ResponseCode.Success
                        };
                        return(response);
                    }
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
示例#2
0
        public override async Task <CloudScriptResponse> ExecuteAsync(CloudScriptRequest request, string[] urlArguments)
        {
            DateTime benginRequest = DateTime.UtcNow;

            if (IsClientValidRequest(request))
            {
                var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

                if (await PlayFabApiHandler.GetPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    MetaDataState metaDataState = MetaDataState.FromJson <MetaDataState>(cloudData.DataAsString);

                    if (metaDataState != null)
                    {
                        bool updatePlayerData = false;

                        if (AddEnergyToPlayer(metaDataState) > 0)
                        {
                            updatePlayerData = true;
                        }

                        if (metaDataState.SyncLoginCalendar())
                        {
                            updatePlayerData = true;
                        }

                        bool applyDailyReset = false;
                        if (DateTime.UtcNow > metaDataState.NextDailyReset)
                        {
                            metaDataState.ApplyDailyReset();
                            updatePlayerData = true;
                        }

                        if (updatePlayerData)
                        {
                            cloudData.DataAsString = metaDataState.ToJson();
                            await PlayFabApiHandler.UploadPlayerTitleData(request.UserId, new List <PlayFabFileDetails>() { cloudData });
                        }

                        CloudScriptResponse response = new CloudScriptResponse();
                        response.Method       = this.GetType().Name;
                        response.ResponseCode = ResponseCode.Success;
                        response.Params.Add("EnergyBalance", metaDataState.Consumables.GetConsumableAmount(Consumable.GetByName <Consumable>(MetaSettings.EnergyId)).ToString());
                        response.Params.Add("ApplyDailyReset", applyDailyReset.ToString());
                        response.Params.Add("UniqueId", metaDataState.UniqueId);
                        return(response);
                    }
                }
            }
            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
        public override async Task <CloudScriptResponse> ExecuteStackAsync(CloudScriptRequestStack request)
        {
            DateTime benginRequest = DateTime.UtcNow;

            if (IsClientValidRequest(request))
            {
                var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

                if (await PlayFabApiHandler.GetPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    MetaDataState metaDataState = MetaDataState.FromJson <MetaDataState>(cloudData.DataAsString);

                    bool success = true;

                    foreach (var stack in request.CloudScriptMethod)
                    {
                        AchievementType type   = (AchievementType)Enum.Parse(typeof(AchievementType), stack.Params["type"]);
                        bool            result = metaDataState.AchievementDataState.RegisterAchievementCount(type);
                    }

                    cloudData.DataAsString = metaDataState.ToJson();

                    if (await PlayFabApiHandler.UploadPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                    {
                        cloudData
                    }))
                    {
                        if (success) // not being a success will trigger data mistmatch.
                        {
                            var response = new CloudScriptResponse()
                            {
                                ResponseCode = ResponseCode.Success
                            };
                            return(response);
                        }
                    }
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
示例#4
0
        public override async Task <CloudScriptResponse> ExecuteStackAsync(CloudScriptRequestStack request)
        {
            DateTime benginRequest = DateTime.UtcNow;

            if (IsClientValidRequest(request))
            {
                var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

                if (await PlayFabApiHandler.GetPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    MetaDataState metaDataState = MetaDataState.FromJson <MetaDataState>(cloudData.DataAsString);

                    bool success = true;

                    foreach (var stack in request.CloudScriptMethod)
                    {
                        //ShopManager.OfferMarkAsShown_Server(metaDataState, stack);
                    }

                    cloudData.DataAsString = metaDataState.ToJson();

                    if (await PlayFabApiHandler.UploadPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                    {
                        cloudData
                    }))
                    {
                        if (success) // not being a success will trigger data mistmatch.
                        {
                            var response = new CloudScriptResponse()
                            {
                                ResponseCode = ResponseCode.Success
                            };
                            return(response);
                        }
                    }
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
示例#5
0
        public override async Task <CloudScriptResponse> ExecuteAsync(CloudScriptRequest request, string[] urlArguments)
        {
            DateTime benginRequest = DateTime.UtcNow;

            if (IsClientValidRequest(request))
            {
                var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

                if (await PlayFabApiHandler.GetPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    MetaDataState state = MetaDataState.FromJson <MetaDataState>(cloudData.DataAsString);
                    cloudData.DataAsString = state.ToJson();

                    string methodName = urlArguments[0] + ServerMethodSuffix;

                    //Type shopManager = typeof(ShopManager);
                    //ShopRequestResult shopRequestResult = shopManager.GetMethod(methodName).Invoke(null, new object[] { state, request.CloudScriptMethod }) as ShopRequestResult;

                    cloudData.DataAsString = state.ToJson();

                    if (await PlayFabApiHandler.UploadPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                    {
                        cloudData
                    }))
                    {
                        CloudScriptResponse response = new CloudScriptResponse()
                        {
                            ResponseCode = ResponseCode.Success, Method = this.GetType().Name
                        };
                        //response.Params.Add("ShopRequestResult", JsonConvert.SerializeObject(shopRequestResult));
                        return(response);
                    }
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
示例#6
0
        public override async Task <CloudScriptResponse> ExecuteAsync(CloudScriptRequest request, string[] urlArguments)
        {
            DateTime benginRequest = DateTime.UtcNow;

            if (IsClientValidRequest(request))
            {
                var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

                if (await PlayFabApiHandler.GetPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    MetaDataState metaDataState = MetaDataState.FromJson <MetaDataState>(cloudData.DataAsString);

                    DailyObjectiveType type = (DailyObjectiveType)Enum.Parse(typeof(DailyObjectiveType), request.CloudScriptMethod.Params["type"]);

                    //bool result = MissionManager.ClaimDailyObjective(metaDataState, type);
                    bool result = true;

                    cloudData.DataAsString = metaDataState.ToJson();

                    if (result && await PlayFabApiHandler.UploadPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                    {
                        cloudData
                    }))
                    {
                        var response = new CloudScriptResponse()
                        {
                            ResponseCode = ResponseCode.Success
                        };
                        return(response);
                    }
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
示例#7
0
        public override async Task <CloudScriptResponse> ExecuteAsync(CloudScriptRequest request, string[] urlArguments)
        {
            DateTime benginRequest = DateTime.UtcNow;

            string playFabId   = urlArguments[0];
            string placementId = urlArguments[1];
            string eventId     = urlArguments[2];

            var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

            if (await PlayFabApiHandler.GetPlayerTitleData(playFabId, new List <PlayFabFileDetails>()
            {
                cloudData
            }))
            {
                MetaDataState state = MetaDataStateBase.FromJson <MetaDataState>(cloudData.DataAsString);

                AdPlacementType adPlacementType = (AdPlacementType)(Enum.Parse(typeof(AdPlacementType), placementId));
                //state.AdState.RegisterAdWatch(adPlacementType, state, () => AdData.GetAdRewardForTypeMethod(adPlacementType, state));

                cloudData.DataAsString = state.ToJson();

                if (await PlayFabApiHandler.UploadPlayerTitleData(playFabId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    CloudScriptResponse cloudScriptResponse = new CloudScriptResponse()
                    {
                        ResponseCode = ResponseCode.Success, Method = this.GetType().Name
                    };
                    cloudScriptResponse.Params.Add("status", eventId + ":OK");
                    return(cloudScriptResponse);
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
示例#8
0
        public override async Task <CloudScriptResponse> ExecuteAsync(CloudScriptRequest request, string[] urlArguments)
        {
            DateTime benginRequest = DateTime.UtcNow;

            if (IsClientValidRequest(request))
            {
                var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

                if (await PlayFabApiHandler.GetPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    MetaDataState metaDataState = MetaDataState.FromJson <MetaDataState>(cloudData.DataAsString);



                    cloudData.DataAsString = metaDataState.ToJson();

                    if (await PlayFabApiHandler.UploadPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                    {
                        cloudData
                    }))
                    {
                        var response = new CloudScriptResponse()
                        {
                            ResponseCode = ResponseCode.Success
                        };
                        return(response);
                    }
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
        public override async Task <CloudScriptResponse> ExecuteAsync(CloudScriptRequest request, string[] urlArguments)
        {
            DateTime benginRequest = DateTime.UtcNow;

            if (IsClientValidRequest(request))
            {
                var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

                if (await PlayFabApiHandler.GetPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    MetaDataState metaDataState = null;

                    //if file does not exist yet, create default for content, otherwise perfom Login Activies.
                    if (cloudData.ExistOnServer)
                    {
                        metaDataState = MetaDataState.FromJson <MetaDataState>(cloudData.DataAsString);
                    }
                    else
                    {
                        metaDataState = new MetaDataState();

                        metaDataState.Consumables.AddConsumable(Consumable.GetByName <Consumable>(MetaSettings.HardCurrencyId), 100);
                        metaDataState.Consumables.AddConsumable(Consumable.GetByName <Consumable>(MetaSettings.SoftCurrencyId), 3000);
                        metaDataState.Consumables.AddConsumable(Consumable.GetByName <Consumable>(MetaSettings.EnergyId), 72);

                        metaDataState.CreationDate = DateTime.UtcNow;



                        var playerProfile = await PlayFabApiHandler.GetPlayerProfileInfo(request.UserId);

                        if (playerProfile != null && playerProfile.Locations != null && playerProfile.Locations.LastOrDefault() != null)
                        {
                            switch (playerProfile.Locations.LastOrDefault().ContinentCode)
                            {
                            case PlayFab.ServerModels.ContinentCode.AF:
                            case PlayFab.ServerModels.ContinentCode.AN:
                            case PlayFab.ServerModels.ContinentCode.EU:
                                metaDataState.MetaTimeZone = MetaTimeZone.EU;
                                break;

                            case PlayFab.ServerModels.ContinentCode.NA:
                            case PlayFab.ServerModels.ContinentCode.SA:
                                metaDataState.MetaTimeZone = MetaTimeZone.NA;
                                break;

                            case PlayFab.ServerModels.ContinentCode.AS:
                            case PlayFab.ServerModels.ContinentCode.OC:
                                metaDataState.MetaTimeZone = MetaTimeZone.ASIA;
                                break;
                            }
                            metaDataState.CountryCode = playerProfile.Locations.LastOrDefault().CountryCode.ToString();
                        }
                        metaDataState.ApplyDailyReset();
                    }

                    if (metaDataState.NextDailyReset == DateTime.MinValue)
                    {
                        metaDataState.NextDailyReset = MetaSettings.GetNextDailyReset(metaDataState.MetaTimeZone, DateTime.UtcNow);
                    }

                    metaDataState.SyncLoginCalendar();
                    metaDataState.ServerDateTime = DateTime.UtcNow;

                    PlayerStatus.AddEnergyToPlayer(metaDataState);

                    if (DateTime.UtcNow > metaDataState.NextDailyReset)
                    {
                        metaDataState.ApplyDailyReset();
                    }

                    if (request.CloudScriptMethod.Params.ContainsKey("DisplayName"))
                    {
                        metaDataState.ProfileName = request.CloudScriptMethod.Params["DisplayName"].ToString();
                    }

                    cloudData.DataAsString = metaDataState.ToJson();

                    if (metaDataState.CountryCode == "CN")
                    {
                        return(new CloudScriptResponse()
                        {
                            ResponseCode = ResponseCode.Error
                        });
                    }

                    if (await PlayFabApiHandler.UploadPlayerTitleData(request.UserId, new List <PlayFabFileDetails>()
                    {
                        cloudData
                    }))
                    {
                        var response = new CloudScriptResponse()
                        {
                            ResponseCode = ResponseCode.Success
                        };
                        return(response);
                    }
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }