public void SaveExperienceToServer(uint xpEarnedOnThisLevel, bool leveledUp) { FashionGameCommands.SetLevelComplete(mXP, xpEarnedOnThisLevel + mXpForCoins, leveledUp, delegate(Message message) { //string coinsEarned = (string)message.Data[0]; string totalCoins = (string)message.Data[1]; SendNotification(GameFacade.RECV_USER_BALANCE, new string[] { totalCoins, "" }); }); mXpForCoins = 0; if (leveledUp) { FashionGameGui gui = GameFacade.Instance.RetrieveMediator <FashionGameGui>(); gui.LeveledUp(); } }
public IGuiStyle GetThumbStyle(ItemId clothingId) { IGuiStyle result; ClothingItem prototype; if (mItemIdsToClothingItems.TryGetValue(clothingId, out prototype)) { FashionGameGui gui = GameFacade.Instance.RetrieveMediator <FashionGameGui>(); result = new GuiStyle(gui.GetNamedStyle(prototype.StyleName), "ThumbnailStyle"); result.InternalMargins = result.InternalMargins * 0.5f; } else { throw new Exception("Unexpected clothing of itemId (" + clothingId + ")"); } return(result); }
private void BuyEnergy(string itemOffer) { mLevel.SendNotification(GameFacade.HIDE_POPUP); InventoryProxy inventoryProxy = GameFacade.Instance.RetrieveProxy <InventoryProxy>(); inventoryProxy.PurchaseRequest(itemOffer, InventoryGlobals.CASH, delegate(Message message) { XmlDocument xmlResponse = new XmlDocument(); xmlResponse.LoadXml((string)message.Data[0]); inventoryProxy.HidePurchaseModel(); XmlNode errorCode = xmlResponse.SelectSingleNode("Response/errors/error/@code"); if (errorCode == null) { List <object> args = new List <object>(); args.Add(FashionGameTranslation.SUCCESS); args.Add(FashionGameTranslation.PURCHASE_COMPLETE); Hangout.Shared.Action okcb = delegate() { mLevel.SendNotification(GameFacade.HIDE_POPUP); FashionGameGui gui = GameFacade.Instance.RetrieveMediator <FashionGameGui>(); gui.EnergyRefilled(); mLevel.Gameplay.StartWaves(); }; args.Add(okcb); args.Add(FashionGameTranslation.PLAY_LEVEL); GameFacade.Instance.SendNotification(GameFacade.SHOW_DIALOG, args); } else if (int.Parse(errorCode.InnerText) == 270007) // Attempt to go below account minimum balance. { // Leave the minigame completely and go to the webpage for buying more cash BuyCoinUtility.GoToBuyCashPage ( FashionGameTranslation.NOT_ENOUGH_CASH_TITLE, FashionGameTranslation.NOT_ENOUGH_CASH_MESSAGE, delegate(string jsResult) { ShowOutOfEnergyGui(); }, ShowOutOfEnergyGui ); } }); }
// This is the function that was an anonymous delegate, mLevelGameplay was passed implicitly at the place this function is now executed. public void ExecuteClosureHack() { if (!mModel.Ready) { mLevelGameplay.mMissedModels++; FashionGameGui gui = GameFacade.Instance.RetrieveMediator <FashionGameGui>(); foreach (ItemId item in mModel.RequiredClothes) { gui.RemoveClothingItem(item); } EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.MODEL_COMPLETE, LogGlobals.CLOTHING_MISSED, mModel.RequiredClothes.Count.ToString()); EventLogger.Log(LogGlobals.CATEGORY_FASHION_MINIGAME, LogGlobals.MODEL_COMPLETE, LogGlobals.STATIONS_MISSED, mModel.RequiredStations.Count.ToString()); } mLevelGameplay.mLevel.ModelInactive(mModel); mModel.SetToInactive(); mModel.ClearNeeds(); }
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(); }