コード例 #1
0
        private IEnumerator <IYieldInstruction> BuildLevel
        (
            XmlDocument levelXml,
            LevelInfo levelInfo,
            bool firstTimePlayed,
            Action <FashionLevel> fashionLevelResult
        )
        {
            //Console.WriteLine(Time.realtimeSinceStartup.ToString("f2") + "> Building Level");

            // Start loading the clothing assets
            ClothingMediator clothingMediator = GameFacade.Instance.RetrieveMediator <ClothingMediator>();

            clothingMediator.LoadClothing
            (
                Functionals.Map <ItemId>
                (
                    delegate(object xmlNode)
            {
                return(new ItemId(XmlUtility.GetUintAttribute((XmlNode)xmlNode, "id")));
            },
                    levelXml.SelectNodes("Level/Clothing/ClothingItem")
                ),
                levelInfo.LevelDataPath
            );

            yield return(new YieldWhile(delegate()
            {
                return !clothingMediator.ClothingLoaded;
            }));

            FashionNpcMediator fashionModelFactory = GameFacade.Instance.RetrieveMediator <FashionNpcMediator>();

            // Clear this value
            mLeveledThisLevel = false;

            // Make the first level that this player qualifies for
            FashionLevel result = new FashionLevel(levelInfo.LevelDataPath, fashionModelFactory, firstTimePlayed, levelInfo.Energy);

            fashionLevelResult(result);
            //Console.WriteLine(Time.realtimeSinceStartup.ToString("f2") + "> Build Level Completed");
        }
コード例 #2
0
        private FashionModelNeeds BuildNeedsFromInfo(FashionModelInfo info, IEnumerable <ModelStation> modelStations)
        {
            FashionModelNeeds result = new FashionModelNeeds();
            int clothingNeeds        = mRand.Next(info.ClothingNeeds.Low, info.ClothingNeeds.High + 1);
            int stationNeeds         = mRand.Next(info.StationNeeds.Low, info.StationNeeds.High + 1);

            ClothingMediator    clothingMediator = GameFacade.Instance.RetrieveMediator <ClothingMediator>();
            List <ModelStation> stations         = new List <ModelStation>();

            foreach (ModelStation station in modelStations)
            {
                if (!(station is HoldingStation))
                {
                    stations.Add(station);
                }
            }

            List <string> clothingTypes = new List <string>(clothingMediator.ClothingItemTypes);

            // Setup Clothing Needs
            for (int i = 0; i < clothingNeeds; ++i)
            {
                string clothingType = clothingTypes[mRand.Next(0, clothingTypes.Count)];
                clothingTypes.Remove(clothingType);

                foreach (Pair <string> synonym in mSynonyms)
                {
                    if (synonym.First == clothingType)
                    {
                        clothingTypes.Remove(synonym.Second);
                    }
                    else if (synonym.Second == clothingType)
                    {
                        clothingTypes.Remove(synonym.First);
                    }
                }

                List <ClothingItem> clothesForThisType = new List <ClothingItem>(clothingMediator.ClothingForType(clothingType));
                if (clothesForThisType.Count == 0)
                {
                    continue;
                }

                ItemId clothing = clothesForThisType[mRand.Next(0, clothesForThisType.Count)].ItemId;
                result.Add(clothing);

                if (clothingTypes.Count == 0)
                {
                    break;
                }
            }

            // Setup Station Needs
            if (stations.Count != 0)
            {
                for (int i = 0; i < stationNeeds; ++i)
                {
                    ModelStation station = stations[mRand.Next(0, stations.Count)];

                    string stationName = station.Name;
                    stations.RemoveAll(delegate(ModelStation stationInList)
                    {
                        return(stationInList.Name == stationName);
                    });

                    result.Add(station);

                    if (stations.Count == 0)
                    {
                        break;
                    }
                }
            }

            result.NeedFixinChance = info.NeedFixinChance;

            return(result);
        }
コード例 #3
0
ファイル: FashionLevel.cs プロジェクト: lsmolic/hangoutsrc
        private IEnumerator <IYieldInstruction> BuildLevelAssetsCoroutine(Asset asset)
        {
            mLevelAsset = (UnityEngineAsset)asset;
            GameObject fashionGameAssets = (GameObject)mLevelAsset.UnityObject;

            mLevelRoot = (GameObject)GameObject.Instantiate(GameObjectUtility.GetNamedChild("Environment", fashionGameAssets));
            mLevelRoot.transform.position = Vector3.zero;

            GameObject stationsRoot = GameObjectUtility.GetNamedChild("Stations", fashionGameAssets);

            mFactory = new FashionGameStationFactory(stationsRoot);

            int           loadingStations = 0;
            List <string> labels          = new List <string>();

            foreach (XmlNode node in mLevelXml.SelectNodes("Level/Stations/Station"))
            {
                XmlNode labelNode = node.Attributes["label"];
                string  label     = null;
                if (labelNode != null)
                {
                    label = labelNode.InnerText;

                    if (labels.Contains(label))
                    {
                        throw new Exception("Fashion Minigame does not support multiple stations with the same label.");
                    }
                    labels.Add(label);
                }

                loadingStations++;
                mFactory.BuildStation
                (
                    node.Attributes["type"].InnerText,
                    XmlUtility.ParsePositionDirection(node),
                    label,
                    delegate(FashionGameStation station)
                {
                    loadingStations--;
                    foreach (Component component in station.UnityGameObject.GetComponentsInChildren(typeof(Collider)))
                    {
                        mStations.Add(component.gameObject, station);
                    }

                    if (station.RequiresWorker)
                    {
                        mLevelTasks.Add(mScheduler.StartCoroutine(AssignNpcWhenAvailable(station)));
                    }
                }
                );
            }

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

            yield return(new YieldWhile(delegate()
            {
                return loadingStations != 0 || !clothingMediator.ClothingLoaded;
            }));

            mLevelGameplay.SetupWaves();
            ReloadStationPositions();

            mLevelSetup = true;
        }
コード例 #4
0
ファイル: LevelGameplay.cs プロジェクト: lsmolic/hangoutsrc
        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;
            });
        }
コード例 #5
0
ファイル: FashionModel.cs プロジェクト: lsmolic/hangoutsrc
        /// <summary>
        /// Starts a walk down the runway
        /// </summary>
        public void SetActive(FashionModelNeeds needs, FashionLevel level)
        {
            if (needs == null)
            {
                throw new ArgumentNullException("needs");
            }
            mNeeds = needs;

            if (level == null)
            {
                throw new ArgumentNullException("level");
            }
            mLevel = level;

            mNametag.MainGui.Showing = true;

            mDesiredClothing.Clear();
            if (mDesiredClothingFrame != null)
            {
                mDesiredClothingFrame.ClearChildWidgets();
            }
            mDesiredStations.Clear();

            mStateMachine = new FashionModelStateMachine(this, mLevel);

            UnityGameObject.transform.position = mLevel.Start.First;

            mActiveWalkCycle      = mCatWalk;
            mActiveWalkCycleSpeed = mCatWalkSpeed;

            mCompletionBonusTime = 5.0f;
            mReady = false;

            mHandleBonusTask = mScheduler.StartCoroutine(HandleBonus());

            IGuiManager manager = GameFacade.Instance.RetrieveMediator <RuntimeGuiManager>();

            mDesiredClothingFrame = new GuiFrame("MainFrame", new MainFrameSizePosition());

            IGuiStyle windowStyle = new GuiStyle(manager.GetDefaultStyle(typeof(Window)), "ModelNeedsWindow");

            windowStyle.Normal.Background = null;
            windowStyle.Hover.Background  = null;

            // TODO: Hard coded values
            float windowHeight = 192.0f;

            mDesiredClothingWindow = new Window
                                     (
                "ModelClothingPanel",
                new FixedSize(128.0f, windowHeight),
                manager,
                mDesiredClothingFrame,
                windowStyle
                                     );

            // TODO: Hard coded values
            mFollowWorldSpaceObject = new FollowWorldSpaceObject
                                      (
                GameFacade.Instance.RetrieveMediator <FashionCameraMediator>().Camera,
                this.DisplayObject.transform,
                GuiAnchor.CenterLeft,
                new Vector2(0.0f, windowHeight * 0.4f),
                new Vector3(0.125f, APPROX_AVATAR_HEIGHT * 1.3f, 0.25f)
                                      );

            manager.SetTopLevelPosition
            (
                mDesiredClothingWindow,
                mFollowWorldSpaceObject
            );

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

            // Setup Clothes GUI
            foreach (ItemId clothing in mNeeds.Clothing)
            {
                Image desiredClothingImage = new Image("DesiredClothingLabel", clothingMediator.GetThumbStyle(clothing), clothingMediator.GetThumbnail(clothing));
                mDesiredClothing.Add(clothing, desiredClothingImage);
                mDesiredClothingFrame.AddChildWidget(desiredClothingImage, new HorizontalAutoLayout());
            }

            // Setup Station GUI
            foreach (ModelStation station in mNeeds.Stations)
            {
                Image desiredStationImage = new Image("DesiredStationImage", station.Image);

                mDesiredStations.Add(station, desiredStationImage);
                mDesiredClothingFrame.AddChildWidget(desiredStationImage, new HorizontalAutoLayout());

                mCompletionBonusTime += station.WaitTime + mWalkToStationTimeBonus;
            }

            this.DisplayObject.SetActiveRecursively(true);

            Shader fashionModelShader = Shader.Find("Avatar/Fashion Model");

            if (fashionModelShader == null)
            {
                throw new Exception("Cannot find 'Avatar/Fashion Model' shader");
            }

            mModelMaterials.Clear();
            foreach (Component component in UnityGameObject.GetComponentsInChildren(typeof(Renderer)))
            {
                Renderer renderer = (Renderer)component;
                foreach (Material mat in renderer.materials)
                {
                    mat.shader = fashionModelShader;
                    mModelMaterials.Add(mat);
                }
            }

            mNeeds.AddOnCompleteAction(ModelComplete);
        }