private IEnumerator OpenChestInner(TreasureHuntChestView chest, Action finishAction) { if (_inProcess) { yield break; } _inProcess = true; var winner = false; if (_winCount >= 3) { winner = false; } else if (_openedChest <= 3) { winner = UnityEngine.Random.Range(0, 1f) < WinChance; } else { winner = true; } chest.SetAnim(winner ? TreasureHuntAnimType.OpenReward : TreasureHuntAnimType.OpenEmpty); yield return(new WaitForSeconds(0.8f)); Services.SoundService.PlayOneShot(SoundName.Poof); yield return(new WaitForSeconds(0.4f)); if (winner) { var reward = RewardManager.CreateReward(); WinView.Reset(); WinView.Activate(reward, chest.FullIcon.sprite); //Debug.Log($"TreasureHunt Reward {reward.name}"); _winCount++; } else { LoseView.Show(chest.EmptyIcon.sprite); } _openedChest++; _inProcess = false; yield return(new WaitForSeconds(1)); finishAction.Invoke(); }
public void Play(TreasureHuntChestView chest) { if (!_canPlay || !Services.TreasureHuntService.HasTries) { return; } _canPlay = false; chest.ChestButton.interactable = false; EventSystemController.OffEventSystemForSeconds(2f); TreasureHuntGameController.OpenChest(chest, () => { _canPlay = true; Services.TreasureHuntService.RemoveTries(1); chest.ChestButton.interactable = false; if (!TreasureHuntGameController.HasAnyReward()) { Services.TreasureHuntService.RemoveTries(Services.TreasureHuntService.TriesCount); } GameEvents.OnTutorialEvent(new TutorialEventData(TutorialEventName.ChestOpened)); }); }
public void OpenChest(TreasureHuntChestView chest, Action finishAction) { StartCoroutine(OpenChestInner(chest, finishAction)); }