Exemplo n.º 1
0
    public ChestRewards GenerateChestRewards(Rarity rarity)
    {
        ChestRewards            lhs           = new ChestRewards();
        ChestGenerationSettings chestSettings = GetChestSettings(rarity);

        if (chestSettings == null)
        {
            UnityEngine.Debug.LogError("Chest reward pool not found.");
            return(null);
        }
        lhs += GenerateTankRewards(chestSettings);
        List <Tank> list = new List <Tank>();

        foreach (Card card in lhs.cards)
        {
            Tank tank = GetTank(card.id);
            if (card.isNew)
            {
                list.Add(tank);
            }
        }
        lhs += GenerateBoosterRewards(chestSettings, list);
        lhs.cards.Sort(delegate(Card item, Card other)
        {
            if (item.type == CardType.BoosterCard)
            {
                return(1);
            }
            if (other.type == CardType.BoosterCard)
            {
                return(-1);
            }
            if (item.rarity > other.rarity)
            {
                return(1);
            }
            return((item.rarity < other.rarity) ? (-1) : 0);
        });
        lhs.coins += chestSettings.coinCount.Random();
        if (UnityEngine.Random.value <= chestSettings.gemDropProbability)
        {
            lhs.gems += chestSettings.gemCount.Random();
        }
        if (PlayerDataManager.IsSubscribed())
        {
            for (int i = 0; i != lhs.cards.Count; i++)
            {
                lhs.cards[i].count *= 2;
            }
            lhs.coins *= 2;
            lhs.gems  *= 2;
        }
        return(lhs);
    }
Exemplo n.º 2
0
    private IEnumerator ChestOpenAnimationRoutine(Rarity chestRarity)
    {
        rewardingDone       = false;
        chestExploded       = false;
        currentChestRewards = Variables.instance.GenerateChestRewards(chestRarity);
        PlayerDataManager.AddChestRewards(currentChestRewards);
        contentGridLayoutGroup.enabled = true;
        for (int j = 0; j != currentChestRewards.cards.Count; j++)
        {
            CardElement       component = UnityEngine.Object.Instantiate(cardPrefab).GetComponent <CardElement>();
            Card              card      = currentChestRewards.cards[j];
            ShopMenu.ShopItem item      = new ShopMenu.ShopItem
            {
                rarity = card.rarity,
                count  = card.count,
                id     = card.id,
                type   = ((card.type == CardType.TankCard) ? ShopMenu.ShopItemType.TankCard : ShopMenu.ShopItemType.BoosterCard),
                isNew  = card.isNew
            };
            shopItems.Add(item);
            AddElement(component);
            if (card.type == CardType.TankCard)
            {
                Tank tank = Variables.instance.GetTank(card.id);
                if (card.isNew)
                {
                    newCards.Push(new KeyValuePair <Collectible, CardElement>(tank, component));
                }
            }
        }
        if (currentChestRewards.gems > 0)
        {
            CardElement       component2 = UnityEngine.Object.Instantiate(cardPrefab).GetComponent <CardElement>();
            ShopMenu.ShopItem item2      = new ShopMenu.ShopItem
            {
                rarity = Rarity.Epic,
                count  = currentChestRewards.gems,
                type   = ShopMenu.ShopItemType.Gem
            };
            shopItems.Add(item2);
            AddElement(component2);
        }
        CardElement component3 = UnityEngine.Object.Instantiate(cardPrefab).GetComponent <CardElement>();

        ShopMenu.ShopItem item3 = new ShopMenu.ShopItem
        {
            rarity = chestRarity,
            count  = currentChestRewards.coins,
            type   = ShopMenu.ShopItemType.Coin
        };
        shopItems.Add(item3);
        AddElement(component3);
        LayoutRebuilder.ForceRebuildLayoutImmediate(contentGridLayoutGroup.GetComponent <RectTransform>());
        contentGridLayoutGroup.enabled = false;
        foreach (CardElement element in elements)
        {
            element.gameObject.SetActive(value: false);
        }
        chest.gameObject.SetActive(value: true);
        Image  image = chest;
        object sprite;

        switch (chestRarity)
        {
        default:
            sprite = commonChestSprite;
            break;

        case Rarity.Rare:
            sprite = rareChestSprite;
            break;

        case Rarity.Epic:
            sprite = epicChestSprite;
            break;
        }
        image.sprite = (Sprite)sprite;
        chest.SetNativeSize();
        yield return(new WaitForSeconds(currentOptions.shakeTime));

        AudioMap.PlayClipAt(AudioMap.instance["chestShake"], Vector3.zero, AudioMap.instance.uiMixerGroup);
        LeanTween.delayedCall(currentOptions.windupTime - 0.367f, (Action) delegate
        {
            AudioMap.PlayClipAt(AudioMap.instance["chestWindup"], Vector3.zero, AudioMap.instance.uiMixerGroup);
        });
        for (float time = 0f; time <= currentOptions.windupTime; time += Time.deltaTime)
        {
            chest.transform.rotation = Quaternion.Euler(0f, 0f, 50f * (Mathf.PingPong(time / 0.2f, 0.3f) - 0.2f));
            glowImage.color          = new Color(1f, 1f, 1f, LeanTween.easeInExpo(0f, 1f, time / currentOptions.windupTime));
            yield return(null);
        }
        chest.gameObject.SetActive(value: false);
        chest.transform.rotation = Quaternion.identity;
        currentOptions.explosion.Play();
        AudioMap.PlayClipAt(AudioMap.instance["chestOpen"], Vector3.zero, AudioMap.instance.uiMixerGroup);
        if (chestRarity == Rarity.Epic)
        {
            AudioMap.PlayClipAt(AudioMap.instance["chestOpenChime"], Vector3.zero, AudioMap.instance.uiMixerGroup);
        }
        yield return(new WaitForSeconds(currentOptions.postExplosionWaitTime));

        doubleRewardsOfferButton.gameObject.SetActive(!isSubscribed);
        doubleRewardingDone = !isSubscribed;
        chestExploded       = true;
        MenuController.backButtonOverrideAction = FinishAnimation;
        int num;

        for (int i = 0; i < elements.Count; i = num)
        {
            if (!(elements[i] == null))
            {
                CardElement cardElement = elements[i];
                AudioMap.PlayClipAt(AudioMap.instance["cardReveal"], Vector3.zero, AudioMap.instance.uiMixerGroup);
                cardElement.gameObject.SetActive(value: true);
                cardElement.SetValues(shopItems[i], animateRoll: true, deductCount: true, isSubscribed);
                if (shopItems[i].type == ShopMenu.ShopItemType.TankCard && shopItems[i].isNew)
                {
                    SetNewCard(i);
                }
                if (shopItems[i].type == ShopMenu.ShopItemType.Coin)
                {
                    AnimatedCurrencyController.AnimateCoins(isSubscribed ? (shopItems[i].count / 2) : shopItems[i].count, MenuController.UICamera.WorldToViewportPoint(cardElement.transform.position), MenuController.TotalCoinsPositionViewport, 5, null, delegate(int ts)
                    {
                        MenuController.instance.topTotalCoinsText.Tick(ts);
                    });
                }
                else if (shopItems[i].type == ShopMenu.ShopItemType.Gem)
                {
                    AnimatedCurrencyController.AnimateGems(isSubscribed ? (shopItems[i].count / 2) : shopItems[i].count, MenuController.UICamera.WorldToViewportPoint(cardElement.transform.position), MenuController.TotalGemsPositionViewport, 1, null, delegate(int ts)
                    {
                        MenuController.instance.topTotalGemsText.Tick(ts);
                    });
                }
                yield return(new WaitForSeconds(0.25f));
            }
            num = i + 1;
        }
        if (isSubscribed)
        {
            doubleRewardRoutine = StartCoroutine(DoubleRewardsRoutine());
        }
        FinishAnimation();
    }
Exemplo n.º 3
0
    private ChestRewards GenerateBoosterRewards(ChestGenerationSettings chest, List <Tank> newTanks = null)
    {
        ChestRewards   chestRewards          = new ChestRewards();
        int            num                   = chest.boosterCardCount.Random();
        List <Booster> boostersForOwnedTanks = PlayerDataManager.GetBoostersForOwnedTanks();

        if (newTanks != null && newTanks.Count > 0)
        {
            foreach (Tank newTank in newTanks)
            {
                boostersForOwnedTanks.AddRange(PlayerDataManager.GetTankBoosters(newTank));
            }
        }
        boostersForOwnedTanks.Shuffle();
        for (int i = 0; i != num; i++)
        {
            if (i > boostersForOwnedTanks.Count || boostersForOwnedTanks.Count == 0)
            {
                chestRewards.coins += GetRandomBooster().coinValue;
                continue;
            }
            Booster booster = boostersForOwnedTanks.Random();
            if (UnityEngine.Random.value < chest.newBoosterCardProbability)
            {
                if (boostersForOwnedTanks.Count > 0)
                {
                    foreach (Booster item in boostersForOwnedTanks)
                    {
                        if (item.Count <= 0)
                        {
                            booster = item;
                            boostersForOwnedTanks.Remove(item);
                            break;
                        }
                    }
                }
            }
            else
            {
                List <Booster> list = new List <Booster>();
                foreach (Booster item2 in boostersForOwnedTanks)
                {
                    if (item2.Count > 0)
                    {
                        list.Add(item2);
                    }
                }
                if (list.Count > 0)
                {
                    booster = list.Random();
                }
            }
            boostersForOwnedTanks.Remove(booster);
            int  stackSize = chest.boosterStackSize.Random();
            Card card      = booster.CreateCards(stackSize);
            card.isNew = (booster.Count == 0);
            bool flag = false;
            for (int j = 0; j != chestRewards.cards.Count; j++)
            {
                if (chestRewards.cards[j].id.Equals(card.id))
                {
                    chestRewards.cards[j].count += card.count;
                    flag = true;
                }
            }
            if (!flag)
            {
                chestRewards.cards.Add(card);
            }
        }
        return(chestRewards);
    }
Exemplo n.º 4
0
    private ChestRewards GenerateTankRewards(ChestGenerationSettings chest)
    {
        ChestRewards chestRewards = new ChestRewards();
        Dictionary <Rarity, List <Tank> > tanksWithNoCards = PlayerDataManager.GetTanksWithNoCards();
        int num = 0;

        foreach (KeyValuePair <Rarity, List <Tank> > item in tanksWithNoCards)
        {
            num += item.Value.Count;
        }
        Dictionary <Rarity, List <Tank> > tanksWithOwnedCards = PlayerDataManager.GetTanksWithOwnedCards();
        Dictionary <Rarity, List <Tank> > nonMaxedTanks       = PlayerDataManager.GetNonMaxedTanks();
        int num2 = chest.tankCardCount.Random();
        int num3 = 0;

        for (int i = 0; i != chest.newTankCardsMax; i++)
        {
            if (UnityEngine.Random.value < chest.newTankCardProbability)
            {
                num3++;
            }
        }
        for (int j = 0; j != num2; j++)
        {
            Rarity   tankRarity = chest.GetTankRarity(UnityEngine.Random.value);
            Rarity[] raritiesOrderedPriorityLow = GetRaritiesOrderedPriorityLow(tankRarity);
            Tank     tank = null;
            bool     flag = false;
            if (nonMaxedTanks[tankRarity].Count == 0)
            {
                for (int k = 0; k != raritiesOrderedPriorityLow.Length; k++)
                {
                    if (nonMaxedTanks[raritiesOrderedPriorityLow[k]].Count > 0)
                    {
                        flag = true;
                        tank = nonMaxedTanks[raritiesOrderedPriorityLow[k]].Random();
                    }
                }
            }
            else
            {
                tank = nonMaxedTanks[tankRarity].Random();
            }
            if (num3 > 0 && num > 0)
            {
                for (int l = 0; l != raritiesOrderedPriorityLow.Length; l++)
                {
                    if (tanksWithNoCards[raritiesOrderedPriorityLow[l]].Count > 0)
                    {
                        tank = tanksWithNoCards[raritiesOrderedPriorityLow[l]].Random();
                        tanksWithNoCards[raritiesOrderedPriorityLow[l]].Remove(tank);
                        num3--;
                        num--;
                        break;
                    }
                }
            }
            else
            {
                bool flag2 = false;
                for (int m = 0; m != raritiesOrderedPriorityLow.Length; m++)
                {
                    if (tanksWithOwnedCards[raritiesOrderedPriorityLow[m]].Count > 0)
                    {
                        tank = tanksWithOwnedCards[raritiesOrderedPriorityLow[m]].Random();
                        tanksWithOwnedCards[raritiesOrderedPriorityLow[m]].Remove(tank);
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    chestRewards.coins += GetTankCardCoinValue(tankRarity) * chest.GetDrop(tankRarity).stackSize.Random();
                    continue;
                }
            }
            if (tank == null)
            {
                chestRewards.coins += GetTankCardCoinValue(tankRarity) * chest.GetDrop(tankRarity).stackSize.Random();
                continue;
            }
            nonMaxedTanks[tankRarity].Remove(tank);
            int tankCardCount = PlayerDataManager.GetTankCardCount(tank);
            int num4          = (tankCardCount == 0) ? 1 : Mathf.RoundToInt(chest.GetDrop(tankRarity).stackSize.Random());
            if (flag)
            {
                int num5 = 1;
                for (int n = 0; n != instance.tanks.Length; n++)
                {
                    if (instance.tanks[n].rarity == tankRarity)
                    {
                        num5 = instance.tanks[n].coinValue;
                    }
                }
                num4 = Mathf.Max(1, Mathf.FloorToInt((float)(num4 * num5) / (float)tank.coinValue));
            }
            Card card = tank.CreateCards(num4);
            card.isNew = (tankCardCount == 0);
            bool flag3 = false;
            for (int num6 = 0; num6 != chestRewards.cards.Count; num6++)
            {
                if (chestRewards.cards[num6].type == CardType.TankCard && chestRewards.cards[num6].id.Equals(card.id))
                {
                    chestRewards.cards[num6].count += card.count;
                    flag3 = true;
                }
            }
            if (!flag3)
            {
                chestRewards.cards.Add(card);
            }
        }
        return(chestRewards);
    }