Example #1
0
        public override void EnterState()
        {
            PlayerProgression progression = GameFacade.Instance.RetrieveMediator <PlayerProgression>();

            progression.GetNextLevel(delegate(FashionLevel level)
            {
                mScheduler.StartCoroutine(SetupLevel(level));
            });
        }
Example #2
0
        private IEnumerator <IYieldInstruction> SpawnWaves()
        {
            PlayerProgression progression = GameFacade.Instance.RetrieveMediator <PlayerProgression>();

            mLevelStartTime = DateTime.UtcNow;

            EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.LEVEL_STARTED, "Level", mLevel.Name);

            uint startXp = progression.XP;

            yield return(new YieldWhile(delegate()
            {
                return !mLevel.IsLoaded;
            }));

            FashionGameGui fashionGameGui = GameFacade.Instance.RetrieveMediator <FashionGameGui>();
            int            waveNum        = 0;

            foreach (ModelWave wave in mWaves)
            {
                mNextWaveTime = Time.time + mTimeBetweenWaves;

                waveNum++;
                mLevel.Gui.SetWave(wave, waveNum, mWaves.Count);

                yield return(new YieldForSeconds(mTimeBetweenWaves));

                // Pair: clothing name and need fixin chance
                List <Pair <ItemId, float> > clothesThisWave = new List <Pair <ItemId, float> >();
                foreach (FashionModelNeeds needs in wave.Needs)
                {
                    foreach (ItemId itemId in needs.Clothing)
                    {
                        clothesThisWave.Add(new Pair <ItemId, float>(itemId, needs.NeedFixinChance));
                    }
                }

                ClothingMediator clothingMediator = GameFacade.Instance.RetrieveMediator <ClothingMediator>();

                // Scramble the list and make some of the clothing need fixin
                while (clothesThisWave.Count > 0)
                {
                    Pair <ItemId, float> item = clothesThisWave[mRandom.Next(0, clothesThisWave.Count)];
                    clothesThisWave.Remove(item);

                    ClothingItem newItem = clothingMediator.BuildClothingItem(item.First);

                    if (UnityEngine.Random.value < item.Second)
                    {
                        newItem.MakeNeedFixin();
                        mLevel.NeedsFixinTotal++;
                    }

                    fashionGameGui.PutItemInGui(newItem);

                    yield return(new YieldUntilNextFrame());                    // Spreads out the texture copies over a few frames to avoid slowdowns
                }

                ITask spawnModelTask = mScheduler.StartCoroutine(SpawnModels(wave));
                mSpawnModels.Add(spawnModelTask);

                // Yield while there are any active models left from this wave,
                //  or if a model is still at a station.
                yield return(new YieldWhile
                             (
                                 delegate()
                {
                    bool keepWaiting = true;

                    if (mNextWaveButtonPressed)
                    {
                        int modelsLeft = 0;
                        foreach (FashionModel model in mActiveModels.Values)
                        {
                            if (!model.Ready)
                            {
                                modelsLeft++;
                            }
                        }

                        if (modelsLeft > wave.Models.Count)
                        {
                            modelsLeft = wave.Models.Count;
                        }

                        GameFacade.Instance.SendNotification
                        (
                            FashionMinigame.EARNED_EXPERIENCE_NOTIFICATION,
                            new ExperienceInfo
                            (
                                ExperienceType.NextWave,
                                (uint)modelsLeft + 1
                            )
                        );
                        keepWaiting = false;

                        mNextWaveButtonPressed = false;
                    }
                    else if (wave.AllModelsSpawned)
                    {
                        bool allModelsDone = true;
                        foreach (FashionModel model in mActiveModels.Values)
                        {
                            if (!model.Ready)
                            {
                                allModelsDone = false;
                                break;
                            }
                        }

                        bool allStationsFree = true;
                        foreach (ModelStation station in mLevel.ModelStations)
                        {
                            if (station.InUse)
                            {
                                allStationsFree = false;
                                break;
                            }
                        }
                        keepWaiting = !(allModelsDone && allStationsFree);
                    }
                    return keepWaiting;
                }
                             ));
            }

            if (mMissedModels == 0)
            {
                GameFacade.Instance.SendNotification
                (
                    FashionMinigame.EARNED_EXPERIENCE_NOTIFICATION,
                    new ExperienceInfo
                    (
                        ExperienceType.PerfectLevel
                    )
                );
            }

            // This is a prediction of the same math the server should be doing and get the same result.
            int experienceFromLevel = (int)(progression.XP - startXp);
            int coinsEarned         = Rewards.GetCoinsFromExperience(experienceFromLevel);

            uint entourageBonusXp    = (uint)Rewards.GetEntourageExperienceBonus(experienceFromLevel, (int)progression.EntourageSize);
            int  entourageBonusCoins = Rewards.GetCoinsFromExperience((int)entourageBonusXp);

            progression.EarnedXP((uint)entourageBonusXp);

            // Log for metrics
            EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.LEVEL_COMPLETE, "Level", mLevel.Name);
            EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.LEVEL_COMPLETE,
                            LogGlobals.MINIGAME_TOTAL_XP, progression.XP.ToString());
            EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.LEVEL_COMPLETE,
                            LogGlobals.MINIGAME_COINS, (coinsEarned + entourageBonusCoins).ToString());
            EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.LEVEL_COMPLETE,
                            LogGlobals.MISSED_MODELS_IN_LEVEL, mMissedModels.ToString());
            EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.LEVEL_COMPLETE,
                            LogGlobals.TIME_TO_COMPLETE_LEVEL, (DateTime.UtcNow - mLevelStartTime).ToString());
            EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.LEVEL_COMPLETE,
                            LogGlobals.UNFIXED_CLOTHING, mLevel.UnfixedClothing + "/" + mLevel.NeedsFixinTotal);
            if (progression.IsLeveledUp())
            {
                EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.LEVELED_UP_EVENT, "Level", mLevel.Name);
            }

            mLevel.Gui.CompleteLevel(startXp, entourageBonusXp, progression, coinsEarned, entourageBonusCoins, delegate()
            {
                mComplete = true;
            });
        }
        private IEnumerator <IYieldInstruction> ProcessLoadingInfo(Message loadingInfoMessage)
        {
            if (loadingInfoMessage.Data.Count < 7)
            {
                throw new Exception("Loading Info Message does not contain all the expected data");
            }

            FashionGameInput input = new FashionGameInput();

            GameFacade.Instance.RegisterMediator(input);

            FashionGameGui gui = new FashionGameGui();

            gui.SetEnergy
            (
                (float)loadingInfoMessage.Data[2],
                (float)loadingInfoMessage.Data[3],
                DateTime.Parse((string)loadingInfoMessage.Data[4])
            );
            gui.SetWave(1, 1);
            gui.SetLevel("Loading...");
            gui.EnableNextWave(false);
            GameFacade.Instance.RegisterMediator(gui);

            PlayerProgression progression = new PlayerProgression((uint)loadingInfoMessage.Data[5], (uint)loadingInfoMessage.Data[6]);

            progression.UpdateProgressGUI(false);
            GameFacade.Instance.RegisterMediator(progression);

            XmlDocument modelClothesXml = new XmlDocument();

            modelClothesXml.LoadXml((string)loadingInfoMessage.Data[0]);

            XmlDocument stationWorkerClothesXml = new XmlDocument();

            stationWorkerClothesXml.LoadXml((string)loadingInfoMessage.Data[1]);

            FashionNpcMediator npcFactory = new FashionNpcMediator();

            GameFacade.Instance.RegisterMediator(npcFactory);

            IEnumerable <Asset>   modelClothes    = null;
            ClientAssetRepository clientAssetRepo = GameFacade.Instance.RetrieveProxy <ClientAssetRepository>();

            clientAssetRepo.GetAssets <Asset>
            (
                ClientAssetInfo.Parse(modelClothesXml),
                delegate(IEnumerable <Asset> downloadedAssets)
            {
                modelClothes = downloadedAssets;
            }
            );

            IEnumerable <Asset> stationWorkerClothes = null;

            clientAssetRepo.GetAssets <Asset>
            (
                ClientAssetInfo.Parse(stationWorkerClothesXml),
                delegate(IEnumerable <Asset> downloadedAssets)
            {
                stationWorkerClothes = downloadedAssets;
            }
            );

            yield return(new YieldWhile(delegate()
            {
                return modelClothes == null || stationWorkerClothes == null;
            }));

            npcFactory.SetModelDefaultClothes(modelClothes);
            npcFactory.SetStationWorkerDefaultClothes(stationWorkerClothes);

            GameFacade.Instance.RegisterMediator(new ClothingMediator());
            input.StartListeningForInput();

            mOnInitialInfoLoaded();
        }
Example #4
0
        public void CompleteLevel(uint startXp, uint entourageBonusXp, PlayerProgression progression, int coinEarned, int entourageBonusCoins, Hangout.Shared.Action onNextLevelPressed)
        {
            IGuiManager manager = GameFacade.Instance.RetrieveMediator <RuntimeGuiManager>();
            string      levelCompleteGuiPath = mLevelXml.SelectSingleNode("Level/LevelCompleteGui/@path").InnerText;

            mLevelCompleteGui = new GuiController(manager, levelCompleteGuiPath);

            // If we leveled up, show the complete frame, otherwise show the replay frame
            GuiFrame levelCompleteFrame = mLevelCompleteGui.MainGui.SelectSingleElement <GuiFrame>("**/LevelCompleteFrame");
            GuiFrame levelReplayFrame   = mLevelCompleteGui.MainGui.SelectSingleElement <GuiFrame>("**/LevelReplayFrame");
            GuiFrame activeFrame        = null;

            // How much total we have now
            uint currentXP = progression.XP;

            // How much we just earned
            uint earnedXP = (currentXP - startXp);

            // How much total we need to get to the next level
            uint nextLevelXP = progression.GetNextLevelXP();

            // How much we need to finish this level
            uint pointsToNextLevel = nextLevelXP - currentXP;

            progression.SaveExperienceToServer(earnedXP, progression.IsLeveledUp());

            if (progression.IsLeveledUp())
            {
                // DID level up
                if (mLevelUpSfx != null)
                {
                    GameObject mainCamera = GameFacade.Instance.RetrieveMediator <CameraManagerMediator>().MainCamera;
                    AudioSource.PlayClipAtPoint(mLevelUpSfx, mainCamera.transform.position, 0.5f);
                }

                levelCompleteFrame.Showing = true;
                levelReplayFrame.Showing   = false;
                activeFrame = levelCompleteFrame;

                // Facebook Share button
                Button shareButton = activeFrame.SelectSingleElement <Button>("**/ShareButton");
                shareButton.AddOnPressedAction(delegate()
                {
                    // Now that they've shared, disable the button
                    shareButton.Disable();
                    ShareLevelUp(mLevel.Name);
                });
            }
            else
            {
                // Did NOT level up
                if (mLevelCompleteSfx != null)
                {
                    GameObject mainCamera = GameFacade.Instance.RetrieveMediator <CameraManagerMediator>().MainCamera;
                    AudioSource.PlayClipAtPoint(mLevelCompleteSfx, mainCamera.transform.position, 0.5f);
                }
                levelCompleteFrame.Showing = false;
                levelReplayFrame.Showing   = true;
                activeFrame = levelReplayFrame;
                Label levelDetailsLabel = activeFrame.SelectSingleElement <Label>("**/LevelDetails");
                levelDetailsLabel.Text = String.Format(levelDetailsLabel.Text, pointsToNextLevel.ToString());
            }

            // Update coins
            Label coinLabel = activeFrame.SelectSingleElement <Label>("**/CoinsEarnedLabel");

            coinLabel.Text = String.Format(coinLabel.Text, coinEarned.ToString());

            // Entourage bonus
            Label bonusCoinsLabel = activeFrame.SelectSingleElement <Label>("**/EntourageBonusCoinLabel");

            bonusCoinsLabel.Text = String.Format(bonusCoinsLabel.Text, entourageBonusCoins.ToString());
            Label bonusXpLabel = activeFrame.SelectSingleElement <Label>("**/EntourageBonusXpLabel");

            bonusXpLabel.Text = String.Format(bonusXpLabel.Text, entourageBonusXp.ToString());

            Button inviteFriendsButton = mLevelCompleteGui.MainGui.SelectSingleElement <Button>("**/InviteFriendsButton");

            inviteFriendsButton.Text = Translation.ENTOURAGE_INVITE_FRIENDS_BUTTON_TEXT;
            inviteFriendsButton.AddOnPressedAction(delegate()
            {
                InviteFriendsToEntourage();
            });

            // Next level button
            Button nextLevelButton = mLevelCompleteGui.MainGui.SelectSingleElement <Button>("**/NextLevelButton");

            nextLevelButton.AddOnPressedAction(onNextLevelPressed);
            nextLevelButton.AddOnPressedAction(CleanupLevelCompleteGui);

            Button exitToRunwayButton = mLevelCompleteGui.MainGui.SelectSingleElement <Button>("**/ExitToRunwayButton");

            if (exitToRunwayButton != null)
            {
                exitToRunwayButton.AddOnPressedAction(delegate()
                {
                    FashionMinigame.GoToRunway();
                });
            }
        }