Exemple #1
0
        private IEnumerator <IYieldInstruction> BuildNpcs
        (
            Jobs job,
            FashionLevel level,
            IEnumerable <XmlNode> modelsXml,
            Hangout.Shared.Action onBuildingNpcsComplete
        )
        {
            // Key = FBID, Value = name, assets for model
            Dictionary <long, Pair <string, IEnumerable <Asset> > > modelInfos = new Dictionary <long, Pair <string, IEnumerable <Asset> > >();
            uint gettingAssets         = 0;
            ClientAssetRepository repo = GameFacade.Instance.RetrieveProxy <ClientAssetRepository>();

            foreach (XmlNode modelXml in modelsXml)
            {
                string  name;
                XmlNode fbidNode = modelXml.SelectSingleNode(".//@FBID");
                if (fbidNode == null)
                {
                    throw new Exception("modelXml doesn't have an FBID attribute: " + modelXml.OuterXml);
                }

                long uniqueId = long.Parse(fbidNode.InnerText);
                name = modelXml.Attributes["FirstName"].InnerText;                // +" " + modelXml.Attributes["LastName"].InnerText;

                // Only grab the avatars we don't already have loaded
                if (!JobHasNpc(job, uniqueId) && !modelInfos.ContainsKey(uniqueId))
                {
                    gettingAssets++;
                    List <AssetInfo> assetInfos = new List <AssetInfo>();
                    foreach (AssetInfo assetInfo in ClientAssetInfo.Parse(modelXml))
                    {
                        if (!mIgnoredAssets.Contains(assetInfo.AssetSubType))
                        {
                            assetInfos.Add(assetInfo);
                        }
                    }

                    repo.GetAssets <Asset>(assetInfos, delegate(IEnumerable <Asset> modelAssets)
                    {
                        gettingAssets--;
                        if (!modelInfos.ContainsKey(uniqueId))
                        {
                            modelInfos.Add(uniqueId, new Pair <string, IEnumerable <Asset> >(name, modelAssets));
                        }
                        else
                        {
                            Console.WriteLine("Attempted to download model info for " + uniqueId + " twice at the same time.");
                        }
                    });
                }
            }

            yield return(new YieldWhile(delegate()
            {
                return gettingAssets != 0;
            }));

            int spreadFrames = 25;
            List <Pair <long, INpc> > newNpcs = new List <Pair <long, INpc> >();

            foreach (KeyValuePair <long, Pair <string, IEnumerable <Asset> > > assets in modelInfos)
            {
                // This object will be cleaned up by the fashion model
                GameObject displayObject = (GameObject)GameObject.Instantiate(mRigPrototype);
                displayObject.SetActiveRecursively(false);

                HeadController headController = new HeadController(GameObjectUtility.GetNamedChildRecursive("Head", displayObject));
                BodyController bodyController = new BodyController(displayObject);

                bodyController.SetAssets(assets.Value.Second);
                headController.SetAssets(assets.Value.Second);

                bodyController.UpdateAssetsOverFrames(spreadFrames);
                headController.UpdateAssetsOverFrames(spreadFrames);

                INpc newNpc;
                if (job == Jobs.Model)
                {
                    newNpc = new FashionModel(assets.Value.First, level, displayObject, headController, bodyController);
                }
                else
                {
                    newNpc = new StationWorker(assets.Value.First, displayObject, headController, bodyController);
                }

                CharacterMediator.AddAnimationClipToRig(newNpc.DisplayObject, "Avatar/F_walk_normal_loop");
                CharacterMediator.AddAnimationClipToRig(newNpc.DisplayObject, "Avatar/F_idle_normal_loop");

                newNpcs.Add(new Pair <long, INpc>(assets.Key, newNpc));
            }

            yield return(new YieldWhile(delegate()
            {
                return spreadFrames-- != 0 || !mModelAnimationsDownloaded;
            }));

            foreach (Pair <long, INpc> npc in newNpcs)
            {
                switch (job)
                {
                case Jobs.Hair:
                    mHairStationWorkers.AddNpc(npc.First, npc.Second);
                    break;

                case Jobs.Makeup:
                    mMakeupStationWorkers.AddNpc(npc.First, npc.Second);
                    break;

                case Jobs.Model:
                    FashionModel newModel = (FashionModel)npc.Second;

                    newModel.SetImpatientSitIdle(mImpatientSitIdle);
                    newModel.SetSittingIdle(mSittingIdle);
                    newModel.SetMediumHurried(mMediumHurried, mMediumHurriedSpeed);
                    newModel.SetCatWalk(mCatWalk, mCatWalkSpeed);

                    mFashionModels.AddNpc(npc.First, npc.Second);
                    break;

                case Jobs.Seamstress:
                    mSewingStationWorkers.AddNpc(npc.First, npc.Second);
                    break;
                }
            }

            if (onBuildingNpcsComplete != null)
            {
                onBuildingNpcsComplete();
            }
        }
        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();
        }