using System; using System.Collections.Generic; using CIG; using CIG.Translation; using CIGEnums; using SUISS.Core; using SUISSEngine; using UnityEngine; public class MoreCashGoldPopupState : PopupBaseState { public override void Leave(State newState) { if (this._purchaseCallback != null) { this.FirePurchaseDone(false, false); this._purchaseCallback = null; } base.Leave(newState); } public void UpdateInfo(Currencies purchasePrice, bool enableGoldAsAlternativeForCash, Action purchaseCallback) { this._purchasePrice = purchasePrice; this._purchaseCallback = purchaseCallback; CIGGameState instance = SingletonMonobehaviour.Instance; Currencies currencies = instance.Balance.MissingCurrencies(purchasePrice); int num = Mathf.RoundToInt((!currencies.Contains("Gold")) ? 0f : ((float)currencies.GetValue("Gold"))); int num2 = Mathf.RoundToInt((!currencies.Contains("Cash")) ? 0f : ((float)currencies.GetValue("Cash"))); string currency = (num < num2) ? "Cash" : "Gold"; int value = (num < num2) ? num2 : num; this._currentOffer = null; CIGSaleManager.Sale currentSale = SingletonMonobehaviour.Instance.CurrentSale; List list = new List(SingletonMonobehaviour.Instance.Store.GetProducts((CIG3StoreProduct p) => p.Category == StoreProductCategory.Shop || p.Category == StoreProductCategory.ShopSale)); for (int i = 0; i < list.Count; i++) { CIG3StoreProduct cig3StoreProduct = list[i]; Currencies currencies2 = cig3StoreProduct.Currencies; bool isSale = cig3StoreProduct.IsSale; if (!currencies2.ContainsApproximate("Cash") || isSale == currentSale.Cash) { if (!currencies2.ContainsApproximate("Gold") || isSale == currentSale.Gold) { if (currencies2.ContainsPositive(currency) && currencies2.GetValue(currency) >= value && (this._currentOffer == null || currencies2.GetValue(currency) <= this._currentOffer.Currencies.GetValue(currency))) { this._currentOffer = cig3StoreProduct; } } } } List list2 = new List(); if (purchasePrice.Contains("Cash") && enableGoldAsAlternativeForCash) { decimal value2 = instance.Balance.GetValue("Cash"); decimal num3 = (!(value2 < 0m) && !(value2 < SingletonMonobehaviour.Instance.GoldToCashRatio)) ? value2 : 0m; decimal num4 = Math.Max(1m, SingletonMonobehaviour.Instance.TranslateCashToGold(purchasePrice.GetValue(currency) - num3)); decimal num5 = Math.Max(num4, SingletonMonobehaviour.Instance.TranslateCashToGold(purchasePrice.GetValue(currency))); if (num3 > 0m && num4 <= instance.Balance.GetValue("Gold")) { list2.Add(new BuyMoreCurrencyButton.BuyMoreCurrency(null, new Currencies("Gold", num4) + new Currencies("Cash", num3), new Action(this.TryBuyAndClosePopup), null)); } if (num5 <= instance.Balance.GetValue("Gold")) { list2.Add(new BuyMoreCurrencyButton.BuyMoreCurrency(null, new Currencies("Gold", num5), new Action(this.TryBuyAndClosePopup), null)); } } if (this._currentOffer != null) { list2.Add(new BuyMoreCurrencyButton.BuyMoreCurrency(this._currentOffer, this._currentOffer.Currencies, new Action(this.TryBuyAndClosePopup), Localization.Literal(" (" + this._currentOffer.FormattedPrice + ")"))); } if (num >= num2) { this.OpenGoldPopup(num, list2.ToArray()); } else { this.OpenCashPopup(num2, list2.ToArray()); } } public void OpenBank() { base.ClosePopup(delegate() { SingletonMonobehaviour.Instance.OpenShopMenu(this._bankShopMenuTab); }); } private void TryBuyAndClosePopup(BuyMoreCurrencyButton.BuyMoreCurrency paymentOption) { if (paymentOption.IsIAP) { base.ClosePopup(delegate() { SingletonMonobehaviour.Instance.PurchaseHandler.InitiatePurchase(this._currentOffer, delegate { this.FirePurchaseDone(true, true); }); }); } else { int spent = Mathf.RoundToInt((float)paymentOption.Currency.GetValue("Gold")); SingletonMonobehaviour.Instance.AddGoldSpent_CashExchange(spent); SingletonMonobehaviour.Instance.SpendCurrencies(paymentOption.Currency, true, null); this._spentCurrency = paymentOption.Currency; this.FirePurchaseDone(true, false); base.ClosePopup(); } } private void OpenCashPopup(decimal missing, BuyMoreCurrencyButton.BuyMoreCurrency[] paymentOptions) { this._bankShopMenuTab = ShopMenuTabs.Cash; ((MoreCashGoldPopupView)this.View).UpdateInfo(Localization.Format(Localization.Key("you_need_more_cash"), new ILocalizedString[] { Localization.Integer(missing) }), paymentOptions); } private void OpenGoldPopup(decimal missing, BuyMoreCurrencyButton.BuyMoreCurrency[] paymentOptions) { this._bankShopMenuTab = ShopMenuTabs.Gold; ((MoreCashGoldPopupView)this.View).UpdateInfo(Localization.Format(Localization.Key("you_need_more_gold"), new ILocalizedString[] { Localization.Integer(missing) }), paymentOptions); } private void FirePurchaseDone(bool succes, bool spendCurrencies) { if (this._purchaseCallback != null) { if (succes && spendCurrencies) { SingletonMonobehaviour.Instance.SpendCurrencies(this._purchasePrice, false, this._purchaseCallback); } else if (succes) { this._purchaseCallback(true, this._spentCurrency); this._spentCurrency = null; } else { this._purchaseCallback(false, null); } } this._purchaseCallback = null; } private Currencies _purchasePrice; private Currencies _spentCurrency; private ShopMenuTabs _bankShopMenuTab; private CIG3StoreProduct _currentOffer; private Action _purchaseCallback; }