private void UpdateNextLevelControls() { IBankService bankService = Services.GetService <IBankService>(); ILocalizationRepository localization = Services.ResourceService.Localization; int currentLevel = bankService.CurrentBankLevel; if (bankService.IsMaxLevel(currentLevel)) { nextLevelControlsParent.Deactivate(); maxLevelText.Activate(); } else { nextLevelControlsParent.Activate(); maxLevelText.Deactivate(); openBankNextLevelLabel.text = string.Format(localization.GetString("lbl_next_level_bank_desc"), bankService.NextLevel); BankLevelData bankLevelData = Services.ResourceService.BankLevelRepository.GetBankLevelData(bankService.NextLevel); ProfitInterval profitInterval = AdjustProfitInterval(bankLevelData.Profit, (int)bankLevelData.ProfitInterval); string profitString = profitInterval.Profit.ToString().Size(72).Colored("#fde090"); string intervalString = UpdateTimeText(profitInterval.Interval).Size(72).Colored("#00fdf7"); nextLevelProfit.text = profitString + " " + intervalString; /* * if (bankLevelData.Profit.IsWhole()) { * string profitString = ((int)bankLevelData.Profit).ToString().Size(80).Colored("#fde090"); * int hours = TimeSpan.FromSeconds(bankLevelData.ProfitInterval).Hours; * string intervalString = UpdateTimeText(hours).Size(72).Colored("#00fdf7"); * nextLevelProfit.text = profitString + " " + intervalString; * } else { * string profitString = ((int)(bankLevelData.Profit * 2)).ToString().Size(80).Colored("#fde090"); * int hours = TimeSpan.FromSeconds(bankLevelData.ProfitInterval * 2).Hours; * string intervalString = UpdateTimeText(hours).Size(72).Colored("#00fdf7"); * nextLevelProfit.text = profitString + " " + intervalString; * }*/ openNextLevelPriceText.text = bankLevelData.LevelPriceCoins.ToString(); openNextLevelButton.SetListener(() => { if (IsAllowBuyNextLevel(bankLevelData)) { StartCoroutine(OpenEffectImpl()); Services.GetService <ISoundService>().PlayOneShot(SoundName.buyCoins); } else { ViewService.Show(ViewType.CoinRequiredView, new ViewData { UserData = bankLevelData.LevelPriceCoins, ViewDepth = GetComponentInParent <BankView>().ViewDepth + 1 }); Sounds.PlayOneShot(SoundName.click); } }); openNextLevelButton.interactable = (!bankService.IsMaxLevel(bankService.CurrentBankLevel)); } }
public TimeSpan SpanWhenBankBeFull() { BankLevelData bankLevelData = Services.ResourceService.BankLevelRepository.GetBankLevelData(CurrentBankLevel); var diff = MaxCapacity - CoinsAccumulatedCount; if (diff > 0 && bankLevelData != null) { var totalSeconds = diff / bankLevelData.Profit * 3600; return(TimeSpan.FromSeconds(totalSeconds)); } return(TimeSpan.Zero); }
private IEnumerator GetBankImpl(Action <List <BankLevelData> > onSuccess, Action <string> onError) { UnityWebRequest request = UnityWebRequest.Get(FullUrl(kBankUrl)); request.SetRequestHeader(authKey, AuthHeader); UnityWebRequestAsyncOperation operation = request.SendWebRequest(); yield return(operation); if (operation.isDone) { if (!operation.webRequest.isHttpError) { try { string result = operation.webRequest.downloadHandler.text; string json = JsonWebToken.Decode(result, secretKey); //print(json.Colored(ConsoleTextColor.teal).Bold()); JObject parent = JObject.Parse(json); JToken arr = parent["response"]["data"]; List <BankLevelData> bankLevels = new List <BankLevelData>(); int level = 1; foreach (JToken token in arr) { int price = token.Value <int>(0); float profit = token.Value <float>(1); float interval = token.Value <float>(2); BankLevelData data = new BankLevelData(level, price, profit, interval); bankLevels.Add(data); level++; } onSuccess?.Invoke(bankLevels); } catch (Exception exception) { UDebug.LogError(exception.Message.Bold()); UDebug.LogError(exception.StackTrace.Bold()); onError?.Invoke($"{exception.Message}{Environment.NewLine}{exception.StackTrace}"); } } else { UDebug.LogError(operation.webRequest.error); onError?.Invoke(operation.webRequest.error); } } else { UDebug.LogError($"operation {nameof(GetBankImpl)} is not done".Bold()); onError?.Invoke($"operation {nameof(GetBankImpl)} is not done"); } }
public void Setup() { BankLevelData bankLevelData = Services.ResourceService.BankLevelRepository.GetBankLevelData(1); if (bankLevelData.Profit.IsWhole()) { countText.text = ((int)bankLevelData.Profit).ToString(); int hours = TimeSpan.FromSeconds(bankLevelData.ProfitInterval).Hours; UpdateTimeText(hours); } else { countText.text = ((int)(bankLevelData.Profit * 2)).ToString(); int hours = TimeSpan.FromSeconds(bankLevelData.ProfitInterval * 2).Hours; UpdateTimeText(hours); } openButtonText.text = bankLevelData.LevelPriceCoins.ToString(); openButton.SetListener(() => { if (IsAllowOpenBank(bankLevelData)) { StartCoroutine(OpenEffectImpl()); Sounds.PlayOneShot(SoundName.buyCoins); } else { ViewService.Show(ViewType.CoinRequiredView, new ViewData { UserData = bankLevelData.LevelPriceCoins, ViewDepth = GetComponentInParent <BankView>().ViewDepth + 1 }); Sounds.PlayOneShot(SoundName.click); } }); //UpdateOpenButtonState(bankLevelData); }
private bool IsAllowBuyNextLevel(BankLevelData bankLevelData) => Player.Coins >= bankLevelData.LevelPriceCoins;
private bool IsAllowOpenBank(BankLevelData levelData) => Player.Coins >= levelData.LevelPriceCoins;