Ejemplo n.º 1
0
    public void Initialize(BonusGroup bonusGroup, UnityAction onClickAction, HashSet <int> exceptionCardIDs, List <Bonus_BudgetLifeEnergyMixed.BudgetLifeEnergyComb> exceptionBudgetLifeEnergyComb)
    {
        Reset();

        BonusGroup = bonusGroup;
        if (BonusGroup.IsAlways)
        {
            Button.interactable = false;
            Button.enabled      = false;
            Button.onClick.RemoveAllListeners();
        }
        else
        {
            Button.interactable = true;
            Button.enabled      = true;
            Button.onClick.RemoveAllListeners();
            Button.onClick.AddListener(delegate
            {
                onClickAction();
                AudioManager.Instance.SoundPlay("sfx/OnStoryButtonClick");
            });
        }

        List <int>   newBonusCardIDs = new List <int>();
        List <Bonus> removeBonuses   = new List <Bonus>();
        List <Bonus> addBonuses      = new List <Bonus>();

        foreach (Bonus bonus in BonusGroup.Bonuses)
        {
            if (bonus is Bonus_UnlockCardByID b_id)
            {
                if (exceptionCardIDs.Contains(b_id.CardID))
                {
                    removeBonuses.Add(bonus);
                }
                else
                {
                    exceptionCardIDs.Add(b_id.CardID);
                }
            }
        }

        foreach (Bonus bonus in BonusGroup.Bonuses)
        {
            if (bonus is Bonus_UnlockCardByLevelNum b_level)
            {
                CardInfo_Base ci = AllCards.GetRandomCardInfoByLevelNum(b_level.LevelNum, exceptionCardIDs);
                removeBonuses.Add(bonus);

                if (ci != null)
                {
                    exceptionCardIDs.Add(ci.CardID);
                    newBonusCardIDs.Add(ci.CardID);
                }
            }

            if (bonus is Bonus_BudgetLifeEnergyMixed b_mixed)
            {
                Bonus_BudgetLifeEnergyMixed.BudgetLifeEnergyComb comb = b_mixed.GetBudgetLifeEnergyComb(exceptionBudgetLifeEnergyComb);

                removeBonuses.Add(bonus);

                if (comb != null)
                {
                    exceptionBudgetLifeEnergyComb.Add(comb);
                    addBonuses.AddRange(comb.GenerateBonuses());
                }
            }
        }

        foreach (Bonus b in addBonuses)
        {
            BonusGroup.Bonuses.Add(b);
        }

        foreach (int newBonusCardID in newBonusCardIDs)
        {
            exceptionCardIDs.Add(newBonusCardID);
            BonusGroup.Bonuses.Add(new Bonus_UnlockCardByID(newBonusCardID));
        }

        foreach (Bonus removeBonus in removeBonuses)
        {
            BonusGroup.Bonuses.Remove(removeBonus);
        }

        foreach (Bonus bonus in BonusGroup.Bonuses)
        {
            BonusItem_Base bi = BonusItem_Base.InstantiateBonusItem(bonus, Container);
            M_BonusItems.Add(bi);
        }

        if (M_BonusItems.Count == 1 && M_BonusItems[0] is BigBonusItem)
        {
            BigBonusItem bigBonusItem = (BigBonusItem)M_BonusItems[0];
            card = bigBonusItem.CurrentCard;
            card.BeDimColor();
            card.ShowCardBloom(false);
            BG_Image.gameObject.SetActive(false);
            BorderSelected.gameObject.SetActive(false);
            Border.gameObject.SetActive(false);
        }
    }
Ejemplo n.º 2
0
    public void Initialize(Shop shop)
    {
        Reset();

        CrystalWhenEnter = StoryManager.Instance.GetStory().Crystal;
        Cur_Shop         = (Shop)shop.Clone();

        ShopNameText.text = Cur_Shop.LevelNames[LanguageManager.Instance.GetCurrentLanguage()];

        List <ShopItem_Card> si_cards  = new List <ShopItem_Card>();
        List <ShopItem>      si_others = new List <ShopItem>();

        foreach (ShopItem si in Cur_Shop.ShopItems)
        {
            if (si is ShopItem_Card sic)
            {
                si_cards.Add(sic);
            }
            else
            {
                si_others.Add(si);
            }
        }

        int shopItemCardCount   = shop.ShopItemCardCount;
        int shopItemOthersCount = shop.ShopItemOthersCount;

        if (si_cards.Count > 0)
        {
            List <ShopItem_Card> si_cards_random = Utils.GetRandomWithProbabilityFromList(si_cards, shopItemCardCount); // 卡片按概率随机
            HashSet <int>        cardIdHashSet   = new HashSet <int>();
            foreach (ShopItem_Card sic in si_cards_random)
            {
                CardInfo_Base ci = AllCards.GetRandomCardInfoByLevelNum(sic.CardRareLevel, cardIdHashSet);
                if (ci != null)
                {
                    sic.GenerateCardID = ci.CardID;
                    sic.Price          = Mathf.CeilToInt(Random.Range(ci.BaseInfo.ShopPrice * 0.8f, ci.BaseInfo.ShopPrice * 1.2f));
                    cardIdHashSet.Add(sic.GenerateCardID);
                    ShopItemButton btn = ShopItemButton.GenerateShopItemButton(sic, ShopItemSmallContainers, ShopItemContainer);
                    ShopItemButtons.Add(sic.ShopItemID, btn);
                }
                else
                {
                    shopItemCardCount--;
                    shopItemOthersCount++;
                }
            }
        }

        if (si_others.Count > 0)
        {
            List <ShopItem> si_others_random = Utils.GetRandomWithProbabilityFromList(si_others, shopItemOthersCount * SHOP_ITEM_OTHERS_GROUP_CAPACITY); // 其他物品按概率随机

            foreach (ShopItem si in si_others_random)
            {
                if (si is ShopItem_Budget)
                {
                    ShopItemButton btn = ShopItemButton.GenerateShopItemButton(si, ShopItemSmallContainers, ShopItemContainer);
                    ShopItemButtons.Add(si.ShopItemID, btn);
                }
            }

            foreach (ShopItem si in si_others_random)
            {
                if (si is ShopItem_LifeUpperLimit)
                {
                    ShopItemButton btn = ShopItemButton.GenerateShopItemButton(si, ShopItemSmallContainers, ShopItemContainer);
                    ShopItemButtons.Add(si.ShopItemID, btn);
                }
            }

            foreach (ShopItem si in si_others_random)
            {
                if (si is ShopItem_EnergyUpperLimit)
                {
                    ShopItemButton btn = ShopItemButton.GenerateShopItemButton(si, ShopItemSmallContainers, ShopItemContainer);
                    ShopItemButtons.Add(si.ShopItemID, btn);
                }
            }
        }

        RefreshAllShopItemAffordable();
    }