public void EatDessert(Widget widget) { if (this.IsEating() || widget == null) { return; } this.isEating = true; GameObject gameObject = (GameObject)widget.GetComponent <DraggableButton>().DragObject; GameProgress.EatDesserts(gameObject.GetComponent <Dessert>().saveId, 1); int num = GameProgress.DessertCount(gameObject.GetComponent <Dessert>().saveId); this.SetButtonCount(widget, num); this.CheckAchievements(); this.availableDessertsCount--; base.StartCoroutine(this.PlayChewingAnim(1f)); if (num <= 0) { if (widget.GetComponent <DraggableButton>().isDragging) { this.CancelDrag(widget, null); } this.m_scrollList.RemoveButton(widget); } FeedingPrize.PrizeType prizeType = this.GiveReward(gameObject); this.m_CurGrowScale = this.m_CurGrowScale * this.m_GrowStepMul + this.m_GrowStepAdd; if (this.m_CurGrowScale > this.m_GrowLimit || prizeType != FeedingPrize.PrizeType.None) { this.m_CurGrowScale = this.m_InitialScale; base.StartCoroutine(this.PlayChewThenShrinkAndBurpAnim(1f, this.m_GrowDuration, prizeType)); } else { if (this.m_GrowSoundFx) { Singleton <AudioManager> .Instance.Play2dEffect(this.m_GrowSoundFx); } this.scaleAnimTime = 0f; } GameProgress.SetFloat("KingPigFeedScale", this.m_CurGrowScale, GameProgress.Location.Local); this.scaleStart = this.m_kingPig.transform.parent.localScale; }
private IEnumerator PlayChewThenShrinkAndBurpAnim(float chewTime, float burpTime, FeedingPrize.PrizeType prizeType) { KingPig kp = this.m_kingPig.GetComponent <KingPig>(); this.PlayKingPigExpressionAudioEffect(Pig.Expressions.Chew); yield return(base.StartCoroutine(kp.PlayAnimation(Pig.Expressions.Chew, chewTime))); this.DelayAction(delegate { this.scaleAnimTime = 0f; if (prizeType == FeedingPrize.PrizeType.Junk || prizeType == FeedingPrize.PrizeType.None) { GameObject gameObject = GameObject.FindGameObjectWithTag("KingPigMouth"); int num = UnityEngine.Random.Range(0, this.m_JunkPrizes.Length); Vector3 position = gameObject.transform.position; position.z = -2f; UnityEngine.Object.Instantiate <GameObject>(this.m_JunkPrizes[num], position, Quaternion.identity); } }, 0.2f); this.PlayKingPigExpressionAudioEffect(Pig.Expressions.Burp); yield return(base.StartCoroutine(kp.PlayAnimation(Pig.Expressions.Burp, burpTime))); kp.SetExpression(this.m_defaultExpression); yield break; }
private FeedingPrize.PrizeType GiveReward(GameObject dessert) { FeedingPrize.PrizeType result = FeedingPrize.PrizeType.None; int num = GameProgress.EatenDessertsCount(); if (UnityEngine.Random.value < this.m_PrizeProbability || num <= 1 || dessert.name == "GoldenCake") { FeedingPrize feedingPrize; if (num <= 1) { feedingPrize = null; foreach (FeedingPrize x in this.m_FeedingPrizes) { if (x.type == FeedingPrize.PrizeType.SuperGlue) { feedingPrize = x; break; } } } else { feedingPrize = this.SelectFeedingPrize(); } FeedingPrize feedingPrize2 = feedingPrize; if (dessert.name == "GoldenCake" && feedingPrize2.type == FeedingPrize.PrizeType.Junk) { feedingPrize2 = this.m_FeedingPrizes[1]; } if (feedingPrize2 != null) { if (feedingPrize2.type != FeedingPrize.PrizeType.Junk && feedingPrize2.type != FeedingPrize.PrizeType.None) { GameObject gameObject = this.m_Reward.transform.Find("Offset/AnimationNode").gameObject; if (gameObject.transform.childCount > 0) { UnityEngine.Object.Destroy(gameObject.transform.GetChild(0).gameObject); } GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(feedingPrize2.icon, gameObject.transform.position, gameObject.transform.rotation); gameObject2.transform.parent = gameObject.transform; gameObject2.transform.localScale = Vector3.one * feedingPrize2.iconScale; CurrencyParticleBurst burst = null; string text = "King Pig feeding prize"; switch (feedingPrize2.type) { case FeedingPrize.PrizeType.SuperGlue: GameProgress.AddSuperGlue(1); if (Singleton <IapManager> .Instance != null) { Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.SuperGlueSingle, 1, text); } break; case FeedingPrize.PrizeType.SuperMagnet: GameProgress.AddSuperMagnet(1); if (Singleton <IapManager> .Instance != null) { Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.SuperMagnetSingle, 1, text); } break; case FeedingPrize.PrizeType.TurboCharge: GameProgress.AddTurboCharge(1); if (Singleton <IapManager> .Instance != null) { Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.TurboChargeSingle, 1, text); } break; case FeedingPrize.PrizeType.SuperMechanic: GameProgress.AddBluePrints(1); if (Singleton <IapManager> .Instance != null) { Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.BlueprintSingle, 1, text); } break; case FeedingPrize.PrizeType.NightVision: GameProgress.AddNightVision(1); if (Singleton <IapManager> .Instance != null) { Singleton <IapManager> .Instance.SendFlurryInventoryGainEvent(IapManager.InAppPurchaseItemType.NightVisionSingle, 1, text); } break; case FeedingPrize.PrizeType.SnoutCoins: { int value = Singleton <GameConfigurationManager> .Instance.GetValue <int>("king_pig_snout_reward", "min"); int value2 = Singleton <GameConfigurationManager> .Instance.GetValue <int>("king_pig_snout_reward", "max"); int num2 = UnityEngine.Random.Range(value, value2 + 1); if (num2 > 0) { if (Singleton <DoubleRewardManager> .Instance.HasDoubleReward) { num2 *= 2; } GameProgress.AddSnoutCoins(num2); GameObject gameObject3 = GameObject.FindGameObjectWithTag("KingPigMouth"); if (gameObject3 != null) { Camera main = Camera.main; Camera camera = Singleton <GuiManager> .Instance.FindCamera(); if (main == null || camera == null) { break; } Vector3 a = gameObject3.transform.position * (1f / main.orthographicSize); gameObject2.transform.parent = null; gameObject2.transform.position = a * camera.orthographicSize; } burst = gameObject2.GetComponent <CurrencyParticleBurst>(); if (burst != null) { burst.SetBurst(num2, 10f, true); } } break; } case FeedingPrize.PrizeType.Scrap: { int value3 = Singleton <GameConfigurationManager> .Instance.GetValue <int>("king_pig_scrap_reward", "min"); int value4 = Singleton <GameConfigurationManager> .Instance.GetValue <int>("king_pig_scrap_reward", "max"); int num3 = UnityEngine.Random.Range(value3, value4 + 1); if (num3 > 0) { GameProgress.AddScrap(num3); GameObject gameObject4 = GameObject.FindGameObjectWithTag("KingPigMouth"); if (gameObject4 != null) { Camera main2 = Camera.main; Camera camera2 = Singleton <GuiManager> .Instance.FindCamera(); if (main2 == null || camera2 == null) { break; } Vector3 a2 = gameObject4.transform.position * (1f / main2.orthographicSize); gameObject2.transform.parent = null; gameObject2.transform.position = a2 * camera2.orthographicSize; } burst = gameObject2.GetComponent <CurrencyParticleBurst>(); if (burst != null) { burst.SetBurst(num3, 10f, true); } } break; } } if (feedingPrize2.type == FeedingPrize.PrizeType.SnoutCoins || feedingPrize2.type == FeedingPrize.PrizeType.Scrap) { this.DelayAction(delegate { if (burst != null) { burst.Burst(); } }, 1.3f); } else { this.DelayAction(delegate { this.m_Reward.SetActive(true); }, this.m_GrowDuration); } if (PlayerProgressBar.Instance != null && Singleton <PlayerProgress> .IsInstantiated()) { GameObject gameObject5 = GameObject.FindGameObjectWithTag("KingPigMouth"); Vector3 vector = gameObject5.transform.position * (1f / this.m_mainCam.orthographicSize); vector *= this.m_hudCam.orthographicSize; PlayerProgressBar.Instance.DelayUpdate(); int amount = Singleton <PlayerProgress> .Instance.AddExperience(PlayerProgress.ExperienceType.KingBurp); PlayerProgressBar.Instance.AddParticles(vector, amount, 1.3f, 0f, null); } if (Singleton <SocialGameManager> .IsInstantiated()) { Singleton <SocialGameManager> .Instance.ReportAchievementProgress("grp.KINGS_FAVORITE", 100.0); } } result = feedingPrize2.type; } } return(result); }