public List <RewardDataItem> GetReward()
        {
            List <RewardDataItem> result = new List <RewardDataItem>();

            foreach (KeyValuePair <string, int> entry in Rewards)
            {
                if (entry.Value > 0)
                {
                    result.Add(new RewardDataItem()
                    {
                        Consumable_Id = Consumable.GetByName(entry.Key).Id, Amount = entry.Value
                    });
                }
            }

            return(result);
        }
 public ConsumableCost GetCost()
 {
     if (Cost != null)
     {
         ConsumableCost result = new ConsumableCost(true);
         foreach (KeyValuePair <string, int> entry in Cost)
         {
             result.ConsumableCostItems.Add(new ConsumableCostItem()
             {
                 ConsumableId = Consumable.GetByName(entry.Key).Id, Ammount = entry.Value
             });
         }
         return(result);
     }
     else
     {
         return(null);
     }
 }
Exemple #3
0
        private void OnPlayerStatusReceived(CloudScriptResponse arg1, CloudScriptMethod arg2)
        {
            if (!Running)
            {
                return;
            }
            UnityEngine.Debug.Log("ROUTINE TASK MANAGER - PLAYER STATUS RECEIVED");

            if (arg1.ResponseCode == ResponseCode.Success)
            {
                if (arg1.Params.ContainsKey("EnergyBalance"))
                {
                    int newBalance = Convert.ToInt32(arg1.Params["EnergyBalance"]);
                    MetaDataStateBase.Current.Consumables.SetConsumableAmount(Consumable.GetByName(MetaStateSettings._EnergyId), newBalance);
                }

                MetaDataStateBase.Current.SyncLoginCalendar();

                if (arg1.Params.ContainsKey("UniqueId") && !string.IsNullOrEmpty(arg1.Params["UniqueId"]))
                {
                    if (arg1.Params["UniqueId"] != UnityEngine.SystemInfo.deviceUniqueIdentifier)
                    {
                        this.metaLoopGameManager.ShowUnavailableMessage(GameUnavailableMessageType.LOGIN_MISMATCH);
                    }
                }

                if (arg1.Params.ContainsKey("ApplyDailyReset"))
                {
                    if (arg1.Params["ApplyDailyReset"].ToLower() == "true")
                    {
                        MetaDataStateBase.Current.ApplyDailyReset();
                    }
                }

                if (OnPlayerStatusUpdate != null)
                {
                    UnityMainThreadDispatcher.Instance().Enqueue(() => OnPlayerStatusUpdate.Invoke());
                }
            }
        }
        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
            });
        }
Exemple #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 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
            });
        }