No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

161 líneas
6.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using CIG;
  4. using CIG.Translation;
  5. using CIGEnums;
  6. using SUISS.Core;
  7. using SUISSEngine;
  8. using UnityEngine;
  9. public class MoreCashGoldPopupState : PopupBaseState
  10. {
  11. public override void Leave(State newState)
  12. {
  13. if (this._purchaseCallback != null)
  14. {
  15. this.FirePurchaseDone(false, false);
  16. this._purchaseCallback = null;
  17. }
  18. base.Leave(newState);
  19. }
  20. public void UpdateInfo(Currencies purchasePrice, bool enableGoldAsAlternativeForCash, Action<bool, Currencies> purchaseCallback)
  21. {
  22. this._purchasePrice = purchasePrice;
  23. this._purchaseCallback = purchaseCallback;
  24. CIGGameState instance = SingletonMonobehaviour<CIGGameState>.Instance;
  25. Currencies currencies = instance.Balance.MissingCurrencies(purchasePrice);
  26. int num = Mathf.RoundToInt((!currencies.Contains("Gold")) ? 0f : ((float)currencies.GetValue("Gold")));
  27. int num2 = Mathf.RoundToInt((!currencies.Contains("Cash")) ? 0f : ((float)currencies.GetValue("Cash")));
  28. string currency = (num < num2) ? "Cash" : "Gold";
  29. int value = (num < num2) ? num2 : num;
  30. this._currentOffer = null;
  31. CIGSaleManager.Sale currentSale = SingletonMonobehaviour<CIGSaleManager>.Instance.CurrentSale;
  32. List<CIG3StoreProduct> list = new List<CIG3StoreProduct>(SingletonMonobehaviour<CIGStoreManager>.Instance.Store.GetProducts((CIG3StoreProduct p) => p.Category == StoreProductCategory.Shop || p.Category == StoreProductCategory.ShopSale));
  33. for (int i = 0; i < list.Count; i++)
  34. {
  35. CIG3StoreProduct cig3StoreProduct = list[i];
  36. Currencies currencies2 = cig3StoreProduct.Currencies;
  37. bool isSale = cig3StoreProduct.IsSale;
  38. if (!currencies2.ContainsApproximate("Cash") || isSale == currentSale.Cash)
  39. {
  40. if (!currencies2.ContainsApproximate("Gold") || isSale == currentSale.Gold)
  41. {
  42. if (currencies2.ContainsPositive(currency) && currencies2.GetValue(currency) >= value && (this._currentOffer == null || currencies2.GetValue(currency) <= this._currentOffer.Currencies.GetValue(currency)))
  43. {
  44. this._currentOffer = cig3StoreProduct;
  45. }
  46. }
  47. }
  48. }
  49. List<BuyMoreCurrencyButton.BuyMoreCurrency> list2 = new List<BuyMoreCurrencyButton.BuyMoreCurrency>();
  50. if (purchasePrice.Contains("Cash") && enableGoldAsAlternativeForCash)
  51. {
  52. decimal value2 = instance.Balance.GetValue("Cash");
  53. decimal num3 = (!(value2 < 0m) && !(value2 < SingletonMonobehaviour<CIGVariables>.Instance.GoldToCashRatio)) ? value2 : 0m;
  54. decimal num4 = Math.Max(1m, SingletonMonobehaviour<CIGVariables>.Instance.TranslateCashToGold(purchasePrice.GetValue(currency) - num3));
  55. decimal num5 = Math.Max(num4, SingletonMonobehaviour<CIGVariables>.Instance.TranslateCashToGold(purchasePrice.GetValue(currency)));
  56. if (num3 > 0m && num4 <= instance.Balance.GetValue("Gold"))
  57. {
  58. list2.Add(new BuyMoreCurrencyButton.BuyMoreCurrency(null, new Currencies("Gold", num4) + new Currencies("Cash", num3), new Action<BuyMoreCurrencyButton.BuyMoreCurrency>(this.TryBuyAndClosePopup), null));
  59. }
  60. if (num5 <= instance.Balance.GetValue("Gold"))
  61. {
  62. list2.Add(new BuyMoreCurrencyButton.BuyMoreCurrency(null, new Currencies("Gold", num5), new Action<BuyMoreCurrencyButton.BuyMoreCurrency>(this.TryBuyAndClosePopup), null));
  63. }
  64. }
  65. if (this._currentOffer != null)
  66. {
  67. list2.Add(new BuyMoreCurrencyButton.BuyMoreCurrency(this._currentOffer, this._currentOffer.Currencies, new Action<BuyMoreCurrencyButton.BuyMoreCurrency>(this.TryBuyAndClosePopup), Localization.Literal(" (" + this._currentOffer.FormattedPrice + ")")));
  68. }
  69. if (num >= num2)
  70. {
  71. this.OpenGoldPopup(num, list2.ToArray());
  72. }
  73. else
  74. {
  75. this.OpenCashPopup(num2, list2.ToArray());
  76. }
  77. }
  78. public void OpenBank()
  79. {
  80. base.ClosePopup(delegate()
  81. {
  82. SingletonMonobehaviour<PopupManager>.Instance.OpenShopMenu(this._bankShopMenuTab);
  83. });
  84. }
  85. private void TryBuyAndClosePopup(BuyMoreCurrencyButton.BuyMoreCurrency paymentOption)
  86. {
  87. if (paymentOption.IsIAP)
  88. {
  89. base.ClosePopup(delegate()
  90. {
  91. SingletonMonobehaviour<CIGStoreManager>.Instance.PurchaseHandler.InitiatePurchase(this._currentOffer, delegate
  92. {
  93. this.FirePurchaseDone(true, true);
  94. });
  95. });
  96. }
  97. else
  98. {
  99. int spent = Mathf.RoundToInt((float)paymentOption.Currency.GetValue("Gold"));
  100. SingletonMonobehaviour<CIGGameStats>.Instance.AddGoldSpent_CashExchange(spent);
  101. SingletonMonobehaviour<CIGGameState>.Instance.SpendCurrencies(paymentOption.Currency, true, null);
  102. this._spentCurrency = paymentOption.Currency;
  103. this.FirePurchaseDone(true, false);
  104. base.ClosePopup();
  105. }
  106. }
  107. private void OpenCashPopup(decimal missing, BuyMoreCurrencyButton.BuyMoreCurrency[] paymentOptions)
  108. {
  109. this._bankShopMenuTab = ShopMenuTabs.Cash;
  110. ((MoreCashGoldPopupView)this.View).UpdateInfo(Localization.Format(Localization.Key("you_need_more_cash"), new ILocalizedString[]
  111. {
  112. Localization.Integer(missing)
  113. }), paymentOptions);
  114. }
  115. private void OpenGoldPopup(decimal missing, BuyMoreCurrencyButton.BuyMoreCurrency[] paymentOptions)
  116. {
  117. this._bankShopMenuTab = ShopMenuTabs.Gold;
  118. ((MoreCashGoldPopupView)this.View).UpdateInfo(Localization.Format(Localization.Key("you_need_more_gold"), new ILocalizedString[]
  119. {
  120. Localization.Integer(missing)
  121. }), paymentOptions);
  122. }
  123. private void FirePurchaseDone(bool succes, bool spendCurrencies)
  124. {
  125. if (this._purchaseCallback != null)
  126. {
  127. if (succes && spendCurrencies)
  128. {
  129. SingletonMonobehaviour<CIGGameState>.Instance.SpendCurrencies(this._purchasePrice, false, this._purchaseCallback);
  130. }
  131. else if (succes)
  132. {
  133. this._purchaseCallback(true, this._spentCurrency);
  134. this._spentCurrency = null;
  135. }
  136. else
  137. {
  138. this._purchaseCallback(false, null);
  139. }
  140. }
  141. this._purchaseCallback = null;
  142. }
  143. private Currencies _purchasePrice;
  144. private Currencies _spentCurrency;
  145. private ShopMenuTabs _bankShopMenuTab;
  146. private CIG3StoreProduct _currentOffer;
  147. private Action<bool, Currencies> _purchaseCallback;
  148. }