Example #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);
    }
Example #2
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);
    }
Example #3
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);
    }