예제 #1
0
    public static void GeneratePlayerData()
    {
        Debug.Log("Generate Player Data");
        localPlayerDataCache                        = new LocalPlayerData();
        localPlayerDataCache.name                   = ResourcesManager.PlayerAttributesData.name;
        localPlayerDataCache.health                 = ResourcesManager.PlayerAttributesData.health;
        localPlayerDataCache.carriedIBSprites       = new List <string>();
        localPlayerDataCache.ibSprites              = new Dictionary <string, int>();
        localPlayerDataCache.bodyStyle              = "default";
        localPlayerDataCache.bodyOutlineColor       = Color.black;
        localPlayerDataCache.bodyColor              = Color.blue;
        localPlayerDataCache.eyeStyle               = "default";
        localPlayerDataCache.eyeOutlineColor        = Color.black;
        localPlayerDataCache.eyeColor               = Color.cyan;
        localPlayerDataCache.dodgeTrailColor        = ResourcesManager.PlayerAttributesData.dodgeTrailSettings.color;
        localPlayerDataCache.accelerationTrailColor = ResourcesManager.PlayerAttributesData.accelerationTrailSettings.color;
        localPlayerDataCache.bloodColor             = ResourcesManager.PlayerAttributesData.bloodColor;
        localPlayerDataCache.items                  = new List <string>();
        localPlayerDataCache.unlockedItems          = new List <string>();

                #if UNITY_EDITOR
        localPlayerDataCache.jumpPowerDecayIndex   = 3;
        localPlayerDataCache.jumpTimesIndex        = 2;
        localPlayerDataCache.dodgeCapacityIndex    = 2;
        localPlayerDataCache.dodgeCooldownIndex    = 3;
        localPlayerDataCache.ibSpriteCapacityIndex = 3;
                #endif

        SaveLocalPlayerData();
    }
예제 #2
0
        /// <summary>
        /// does a webrequest to get the current player state
        /// </summary>
        /// <param name="DeviceID"></param>
        /// <returns></returns>
        public async Task <Player> GetPlayerStateAsync(string DeviceID)
        {
            if (state == null)
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>
                {
                    { "device_id", DeviceID }
                };

                var response = await RestHelper.GetRequestAsync("api/player/get", parameters);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    state = RestHelper.ConvertJsonToObject <Models.DatabaseModels.Player>(response.Content);
                    await LocalPlayerData.SaveLocalPlayerData(state);
                }
                else
                {
                    state = await LocalPlayerData.LoadLocalPlayerDataAsync();

                    if (response.StatusCode == HttpStatusCode.InternalServerError)
                    {
                        if (response.StatusDescription == "No player found with this deviceid")
                        {
                            //remove the local player state
                            await LocalPlayerData.RemoveLocalPlayerData();

                            return(null);
                        }
                    }
                }
            }

            return(state);
        }
예제 #3
0
    protected override IEnumerator setup()
    {
        GcsAccessTokenService gcsAccessTokenService = new GcsAccessTokenService(ConfigHelper.GetEnvironmentProperty <string>("GcsServiceAccountName"), new GcsP12AssetFileLoader(ConfigHelper.GetEnvironmentProperty <string>("GcsServiceAccountFile")));

        Service.Set((IGcsAccessTokenService)gcsAccessTokenService);
        string cdnUrl = ContentHelper.GetCdnUrl();
        string cpipeMappingFilename = ContentHelper.GetCpipeMappingFilename();
        CPipeManifestService cpipeManifestService = new CPipeManifestService(cdnUrl, cpipeMappingFilename, gcsAccessTokenService);

        Service.Set((ICPipeManifestService)cpipeManifestService);
        base.gameObject.AddComponent <KeyChainManager>();
        GameSettings gameSettings = new GameSettings();

        Service.Set(gameSettings);
        ContentManifest definition = ContentManifestUtility.FromDefinitionFile("Configuration/embedded_content_manifest");

        Service.Set(new Content(definition));
        Localizer localizer = Localizer.Instance;

        Service.Set(localizer);
        NullCPSwrveService cpSwrveService = new NullCPSwrveService();

        Service.Set((ICPSwrveService)cpSwrveService);
        NetworkServicesConfig networkConfig = NetworkController.GenerateNetworkServiceConfig(TestEnvironment);

        Service.Set((INetworkServicesManager) new NetworkServicesManager(this, networkConfig, offlineMode: false));
        CommerceService commerceService = new CommerceService();

        commerceService.Setup();
        Service.Set(commerceService);
        Service.Set(new MembershipService(null));
        ConnectionManager connectionManager = base.gameObject.AddComponent <ConnectionManager>();

        Service.Set(connectionManager);
        Service.Set(new SessionManager());
        Service.Set(new MixLoginCreateService());
        Service.Set((CPDataEntityCollection) new CPDataEntityCollectionImpl());
        LocalPlayerData localPlayerData = new LocalPlayerData
        {
            name         = "TestPlayer",
            tutorialData = new List <sbyte>()
        };
        PlayerId playerId = localPlayerData.id = new PlayerId
        {
            id   = "999999999999999",
            type = PlayerId.PlayerIdType.SESSION_ID
        };

        Service.Get <CPDataEntityCollection>().ResetLocalPlayerHandle();
        PlayerDataEntityFactory.AddLocalPlayerProfileDataComponents(Service.Get <CPDataEntityCollection>(), localPlayerData);
        LoginController loginController = new LoginController();

        Service.Set(loginController);
        loginController.SetNetworkConfig(networkConfig);
        IntegrationTestEx.FailIf(Service.Get <MixLoginCreateService>().NetworkConfigIsNotSet);
        yield return(null);
    }
예제 #4
0
 public LocalPlayerDataProxy(LocalPlayerData data) : base(data)
 {
     hasFinishedStarterLevel = data.hasFinishedStarterLevel;
     numBronzeMeritCards     = data.numBronzeMeritCards;
     numSilverMeritCards     = data.numSilverMeritCards;
     numGoldMeritCards       = data.numGoldMeritCards;
     items         = new List <string>(data.items);
     unlockedItems = new List <string>(data.unlockedItems);
 }
예제 #5
0
        public static async Task Initialize()
        {
            var response = await RestHelper.GetRequestAsync("api/Assets/monsters");

            Monsters = RestHelper.ConvertJsonToObject <List <Models.DatabaseModels.Monster> >(response.Content);
            if (Monsters != null && Monsters?.Count != 0)
            {
                await LocalPlayerData.SaveLocalData(Monsters, "monsters-asset-data.json");
            }
            else
            {
                Monsters = await LocalPlayerData.LoadLocalData <List <Models.DatabaseModels.Monster> >("monsters-asset-data.json");
            }
        }
예제 #6
0
        public static async Task Initialize()
        {
            var response = await RestHelper.GetRequestAsync("api/Assets/heroes");

            Heroes = RestHelper.ConvertJsonToObject <List <Models.DatabaseModels.Hero> >(response.Content);
            if (Heroes != null && Heroes?.Count != 0)
            {
                await LocalPlayerData.SaveLocalData(Heroes, "heroes-asset-data.json");
            }
            else
            {
                Heroes = await LocalPlayerData.LoadLocalData <List <Models.DatabaseModels.Hero> >("heroes-asset-data.json");
            }
        }
예제 #7
0
    private static void logPlayerStatusBI(LocalPlayerData data)
    {
        string tier = "free";

        if (data.member)
        {
            tier = "paid_member";
        }
        else if (data.membershipExpireDate > 0)
        {
            tier = "lapsed_member";
        }
        Service.Get <ICPSwrveService>().Action("login_type", tier);
    }
예제 #8
0
 private void FindComponents()
 {
     if (PlayerDataComponent == null && GameObject.Find("LocalPlayerData") != null)
     {
         PlayerDataComponent = GameObject.Find("LocalPlayerData").GetComponent <LocalPlayerData> ();
     }
     if (PlayerInfo == null && GameObject.Find("PlayerInfo") != null)
     {
         PlayerInfo = GameObject.Find("PlayerInfo").GetComponent <MyPlayerStatsInfo> ();
     }
     if (myNetManager == null && GameObject.Find("NetworkManager") != null)
     {
         myNetManager = GameObject.Find("NetworkManager").GetComponent <MyNetworkManager> ();
     }
 }
예제 #9
0
    public override LocalPlayerData Load()
    {
        LocalPlayerData result = new LocalPlayerData();

        //名稱
        if (PlayerPrefs.HasKey(keyPlayerName))
        {
            result.Name = PlayerPrefs.GetString(keyPlayerName);
        }
        else
        {
            result.Name = "No Name";
            PlayerPrefs.SetString(keyPlayerName, result.Name);
        }
        //錢
        if (PlayerPrefs.HasKey(keyPlayerMoney))
        {
            result.Money = PlayerPrefs.GetInt(keyPlayerMoney);
        }
        else
        {
            result.Money = 0;
            PlayerPrefs.SetInt(keyPlayerMoney, result.Money);
        }
        //貢丸套裝
        if (PlayerPrefs.HasKey(keyPlayerMeatBallSets))
        {
            result.MeatBallSets = PlayerPrefs.GetString(keyPlayerMeatBallSets);
        }
        else
        {
            //僅有初始套裝
            result.MeatBallSets = "1";
            PlayerPrefs.SetString(keyPlayerMeatBallSets, result.MeatBallSets);
        }
        //劇情進度
        if (PlayerPrefs.HasKey(keyStageProgress))
        {
            result.StageProgress = PlayerPrefs.GetString(keyStageProgress);
        }
        else
        {
            //空進度
            result.StageProgress = "";
            PlayerPrefs.SetString(keyStageProgress, result.StageProgress);
        }
        return(result);
    }
예제 #10
0
        /// <summary>
        /// uploads the current player state to the server
        /// </summary>
        /// <param name="player"></param>
        public async Task SetPlayerStateAsync(Player player)
        {        //todo: add hero's to the player object.
            state = player;
            Models.DatabaseModels.Player dbPlayer = player;
            var response = await RestHelper.PostRequestAsync("api/player/set", dbPlayer);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                await LocalPlayerData.SaveLocalPlayerData(state);
            }
            else
            {
                //save the current player state, and then throw an exception
                await LocalPlayerData.SaveLocalPlayerData(state);

                throw new Exception($"Couldn't set the player state... Api error: [{response.StatusCode}] {response.ErrorMessage}");
            }
        }
예제 #11
0
        public static async Task Initialize()
        {
            NormalScenes = await LocalPlayerData.LoadLocalData <List <Models.DatabaseModels.Scene> >("normal-scenes-asset-data.json");

            if (NormalScenes == null || NormalScenes?.Count == 0)
            {
                var response = await RestHelper.GetRequestAsync("api/Assets/scenes");

                NormalScenes = RestHelper.ConvertJsonToObject <List <Models.DatabaseModels.Scene> >(response.Content);
                if (NormalScenes != null && NormalScenes?.Count != 0)
                {
                    await LocalPlayerData.SaveLocalData(NormalScenes, "normal-scenes-asset-data.json");
                }
                else
                {
                    NormalScenes = await LocalPlayerData.LoadLocalData <List <Models.DatabaseModels.Scene> >("normal-scenes-asset-data.json");
                }
            }
        }
예제 #12
0
        public void Execute(int index)
        {
            var p = pList[index];

            if (lpdList[index].currentNeedMove > 0)
            {
                lpdList[index] = new LocalPlayerData
                {
                    currentNeedMove = lpdList[index].currentNeedMove - 1,
                    speed           = lpdList[index].speed
                };
                var newV = pList[index].Value;
                newV.x      += lpdList[index].speed * dl;
                pList[index] = new Position
                {
                    Value = newV
                };
            }
        }
예제 #13
0
        /// <summary>
        /// Creates a new user instance and posts the data to the API, which then is saved in the database.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="connectionId"></param>
        public async Task CreateUser(string username, string DeviceId)
        {
            Models.DatabaseModels.Player player = new Models.DatabaseModels.Player
            {
                DeviceId   = DeviceId,
                PlayerName = username,
                PlayerGuid = Guid.NewGuid().ToString()
            };

            var response = await RestHelper.PostRequestAsync("api/player/create", player);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                //after creating a new user, also store that new player
                await LocalPlayerData.SaveLocalPlayerData(player);
            }
            else
            {
                await LocalPlayerData.SaveLocalPlayerData(player);

                throw new Exception($"Couldn't create the player... Api error: [{response.StatusCode}] {response.ErrorMessage}");
            }
        }
예제 #14
0
 public static void LoadLocalPlayerData()
 {
     localPlayerData = new LocalPlayerData(LocalDataManager.ReadDataFromFile <LocalPlayerDataProxy>(PlayerDataPath));
     RefreshLocalPlayerDataCache();
 }
예제 #15
0
    public static DataEntityHandle AddLocalPlayerProfileDataComponents(DataEntityCollection dataEntityCollection, LocalPlayerData data, bool isOnline = false)
    {
        DataEntityHandle dataEntityHandle = dataEntityCollection.FindEntityByName("LocalPlayer");

        if (dataEntityHandle.IsNull)
        {
            return(dataEntityHandle);
        }
        if (data == null)
        {
            return(dataEntityHandle);
        }
        if (!dataEntityCollection.TryGetComponent(dataEntityHandle, out DisplayNameData component2))
        {
            component2 = dataEntityCollection.AddComponent <DisplayNameData>(dataEntityHandle);
        }
        component2.DisplayName = data.name;
        if (!dataEntityCollection.TryGetComponent(dataEntityHandle, out QuestStateData component3))
        {
            component3 = dataEntityCollection.AddComponent <QuestStateData>(dataEntityHandle);
        }
        component3.Data = data.quests;
        if (!dataEntityCollection.TryGetComponent(dataEntityHandle, out AvatarDetailsData component4))
        {
            component4           = dataEntityCollection.AddComponent <AvatarDetailsData>(dataEntityHandle);
            component4.BodyColor = AvatarService.DefaultBodyColor;
            component4.Outfit    = new DCustomEquipment[0];
        }
        if (data.outfit != null && data.outfit.Count > 0)
        {
            component4.Outfit = CustomEquipmentResponseAdaptor.ConvertResponseToOutfit(data.outfit);
        }
        if (data.profile != null)
        {
            Dictionary <int, AvatarColorDefinition> avatarColors = Service.Get <GameData>().Get <Dictionary <int, AvatarColorDefinition> >();
            component4.BodyColor = AvatarBodyColorAdaptor.GetColorFromDefinitions(avatarColors, data.profile.colour);
        }
        if (!dataEntityCollection.TryGetComponent(dataEntityHandle, out ProfileData component5))
        {
            component5 = dataEntityCollection.AddComponent <ProfileData>(dataEntityHandle);
        }
        component5.PenguinAgeInDays = ((data.profile != null) ? data.profile.daysOld : 0);
        component5.IsOnline         = isOnline;
        component5.IsMigratedPlayer = (data.migrationData != null && data.migrationData.status.Equals("MIGRATED"));
        component5.ZoneId           = data.zoneId;
        if (!dataEntityCollection.TryGetComponent(dataEntityHandle, out MembershipData component6))
        {
            component6 = dataEntityCollection.AddComponent <MembershipData>(dataEntityHandle);
        }
        component6.IsMember                 = data.member;
        component6.MembershipType           = (data.member ? MembershipType.Member : MembershipType.None);
        component6.MembershipExpireDate     = data.membershipExpireDate;
        component6.MembershipTrialAvailable = data.trialAvailable;
        if (!component6.IsMember && Service.Get <AllAccessService>().IsAllAccessActive())
        {
            component6.IsMember       = true;
            component6.MembershipType = MembershipType.AllAccessEventMember;
        }
        logPlayerStatusBI(data);
        if (!dataEntityCollection.TryGetComponent(dataEntityHandle, out SubscriptionData component7))
        {
            component7 = dataEntityCollection.AddComponent <SubscriptionData>(dataEntityHandle);
        }
        component7.SubscriptionVendor         = data.subscriptionVendor;
        component7.SubscriptionProductId      = data.subscriptionProductId;
        component7.SubscriptionPaymentPending = data.subscriptionPaymentPending;
        component7.SubscriptionRecurring      = data.recurring;
        if (data.migrationData != null && data.migrationData.legacyAccountData != null)
        {
            if (!dataEntityCollection.TryGetComponent(dataEntityHandle, out LegacyProfileData component8))
            {
                component8 = dataEntityCollection.AddComponent <LegacyProfileData>(dataEntityHandle);
            }
            component8.Username     = data.migrationData.legacyAccountData.username;
            component8.IsMember     = data.migrationData.legacyAccountData.member;
            component8.CreatedDate  = data.migrationData.legacyAccountData.createdDate;
            component8.MigratedDate = data.migrationData.migratedDate;
        }
        byte[] array = new byte[data.tutorialData.Count];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = (byte)data.tutorialData[i];
        }
        if (!dataEntityCollection.TryGetComponent(dataEntityHandle, out TutorialData component9))
        {
            component9 = dataEntityCollection.AddComponent <TutorialData>(dataEntityHandle);
        }
        component9.Data = new BitArray(array);
        switch (data.id.type)
        {
        case PlayerId.PlayerIdType.SESSION_ID:
            if (!dataEntityCollection.HasComponent <SessionIdData>(dataEntityHandle))
            {
                dataEntityCollection.AddComponent(dataEntityHandle, delegate(SessionIdData component)
                {
                    component.SessionId = Convert.ToInt64(data.id.id);
                });
            }
            break;

        case PlayerId.PlayerIdType.SWID:
            if (!dataEntityCollection.HasComponent <SwidData>(dataEntityHandle))
            {
                dataEntityCollection.AddComponent <SwidData>(dataEntityHandle).Swid = data.id.id;
            }
            break;
        }
        setClaimedRewardIds(dataEntityCollection, dataEntityHandle, data.claimedRewardIds);
        addDailySpinDataComponent(dataEntityCollection, dataEntityHandle, data);
        return(dataEntityHandle);
    }
        protected override void PerformOfflineAction(OfflineDatabase offlineDatabase, IOfflineDefinitionLoader offlineDefinitions)
        {
            ResponseBody        = new LocalPlayerData();
            ResponseBody.member = true;
            ResponseBody.membershipExpireDate       = DateTime.UtcNow.AddMonths(1).GetTimeInMilliseconds();
            ResponseBody.trialAvailable             = false;
            ResponseBody.subscriptionPaymentPending = false;
            ResponseBody.id = new PlayerId
            {
                id   = offlineDatabase.AccessToken,
                type = PlayerId.PlayerIdType.SWID
            };
            ClubPenguin.Net.Offline.Profile profile = offlineDatabase.Read <ClubPenguin.Net.Offline.Profile>();
            ResponseBody.profile = new ClubPenguin.Net.Domain.Profile
            {
                colour  = profile.Colour,
                daysOld = profile.DaysOld
            };
            ResponseBody.outfit           = offlineDatabase.Read <ClubPenguin.Net.Offline.PlayerOutfitDetails>().Parts;
            ResponseBody.mascotXP         = offlineDatabase.Read <ClubPenguin.Net.Offline.PlayerAssets>().Assets.mascotXP;
            ResponseBody.minigameProgress = new List <MinigameProgress>();
            ResponseBody.quests           = SetProgressOperation.GetQuestStateCollection(offlineDatabase.Read <QuestStates>(), offlineDefinitions, includeComplete: true);
            ResponseBody.tutorialData     = new List <sbyte>(offlineDatabase.Read <TutorialData>().Bytes);
            List <Breadcrumb> list = new List <Breadcrumb>();

            foreach (Breadcrumb breadcrumb in offlineDatabase.Read <BreadcrumbCollection>().breadcrumbs)
            {
                list.Add(new Breadcrumb
                {
                    id             = breadcrumb.id,
                    breadcrumbType = breadcrumb.breadcrumbType
                });
            }
            ResponseBody.breadcrumbs = new BreadcrumbsResponse
            {
                breadcrumbs = list
            };
            RegistrationProfile registrationProfile = offlineDatabase.Read <RegistrationProfile>();

            ResponseBody.name = registrationProfile.displayName;
            if (string.IsNullOrEmpty(ResponseBody.name))
            {
                ResponseBody.name = registrationProfile.userName;
            }
            ResponseBody.claimedRewardIds = offlineDatabase.Read <ClaimableRewardData>().ClimedRewards;
            ZoneId zoneId = new ZoneId();

            zoneId.name       = "DefaultIgloo";
            zoneId.instanceId = registrationProfile.Id();
            ZoneId      zoneId2     = zoneId;
            IglooEntity iglooEntity = offlineDatabase.Read <IglooEntity>();

            if (iglooEntity.Data.activeLayout != null)
            {
                string zoneId3 = iglooEntity.Data.activeLayout.zoneId;
                if (!string.IsNullOrEmpty(zoneId3))
                {
                    zoneId2.name = zoneId3;
                }
            }
            ResponseBody.zoneId = zoneId2;
            List <SavedIglooLayoutSummary> list2 = new List <SavedIglooLayoutSummary>();

            foreach (SavedSceneLayout layout in offlineDatabase.Read <SceneLayoutEntity>().Layouts)
            {
                list2.Add(new SavedIglooLayoutSummary
                {
                    createdDate     = layout.createdDate.GetValueOrDefault(0L),
                    lastUpdatedDate = layout.lastModifiedDate.GetValueOrDefault(0L),
                    layoutId        = layout.layoutId,
                    lot             = layout.zoneId,
                    memberOnly      = layout.memberOnly,
                    name            = layout.name
                });
            }
            ResponseBody.iglooLayouts = new SavedIglooLayoutsSummary
            {
                activeLayoutId = iglooEntity.Data.activeLayoutId,
                activeLayoutServerChangeNotification = ActiveLayoutServerChangeNotification.NoServerChange,
                visibility = iglooEntity.Data.visibility.GetValueOrDefault(IglooVisibility.PRIVATE),
                layouts    = list2
            };
            ClubPenguin.Net.Offline.DailySpinData dailySpinData = offlineDatabase.Read <ClubPenguin.Net.Offline.DailySpinData>();
            ResponseBody.dailySpinData = new ClubPenguin.Net.Domain.DailySpinData
            {
                currentChestId = dailySpinData.CurrentChestId,
                numChestsReceivedOfCurrentChestId = dailySpinData.NumChestsReceivedOfCurrentChestId,
                numPunchesOnCurrentChest          = dailySpinData.NumPunchesOnCurrentChest,
                timeOfLastSpinInMilliseconds      = dailySpinData.TimeOfLastSpinInMilliseconds
            };
            ClubPenguin.Net.Offline.SessionData sessionData = offlineDatabase.Read <ClubPenguin.Net.Offline.SessionData>();
            if (sessionData.Data.sessionId != 0)
            {
                ResponseBody.onlineLocation = sessionData.CurrentRoom;
            }
        }
예제 #17
0
 private static void addDailySpinDataComponent(DataEntityCollection dataEntityCollection, DataEntityHandle handle, LocalPlayerData localPlayerData)
 {
     if (localPlayerData.dailySpinData != null)
     {
         if (!dataEntityCollection.TryGetComponent(handle, out DailySpinEntityData component))
         {
             component = dataEntityCollection.AddComponent <DailySpinEntityData>(handle);
         }
         component.CurrentChestId = localPlayerData.dailySpinData.currentChestId;
         component.NumChestsReceivedOfCurrentChestId = localPlayerData.dailySpinData.numChestsReceivedOfCurrentChestId;
         component.NumPunchesOnCurrentChest          = localPlayerData.dailySpinData.numPunchesOnCurrentChest;
         component.TimeOfLastSpinInMilliseconds      = localPlayerData.dailySpinData.timeOfLastSpinInMilliseconds;
     }
 }
예제 #18
0
 public LocalPlayerDataReceived(LocalPlayerData data)
 {
     Data = data;
 }
    private void localPlayerDataReturned(GetLocalPlayerDataOperation operation, HttpResponse response)
    {
        LocalPlayerData responseBody = operation.ResponseBody;

        Service.Get <EventDispatcher>().DispatchEvent(new PlayerStateServiceEvents.LocalPlayerDataReceived(responseBody));
    }