Example #1
0
        /// <summary>
        /// Creates a booster pack based on the set
        /// </summary>
        /// <param name="toUse">Set to use for pack creation</param>
        private void CreateBooster(Set toUse)
        {
            packs.Add(new Dictionary<ListViewItem, Card>());
            packRefs.Add(new List<ListViewItem>());

            var booster = packs[packs.Count - 1];
            var refs = packRefs[packRefs.Count - 1];

            int commons = 0, uncommons = 0, rares = 0, mythics = 0, basics = 0;
            foreach (Card card in toUse.Cards)
            {
                if (card.Rarity == Rarity.Common)
                    commons++;
                if (card.Rarity == Rarity.Uncommon)
                    uncommons++;
                if (card.Rarity == Rarity.Rare)
                    rares++;
                if (card.Rarity == Rarity.MythicRare)
                    mythics++;
                if (card.Rarity == Rarity.BasicLand)
                    basics++;
            }

            if ((basics % 5) != 0)
                throw new ArgumentException("The current set has inequally divided its basic lands");
            if (commons == 0 || uncommons == 0 || rares == 0)
                throw new ArgumentException("The current set lacks cards of either common, uncommon, or rare rarity.");

            if (mythics == 0 || (mythics > 0 && TrueRandom(8) != 0))
            {
                int index = 0, current = 0, num = TrueRandom(rares);
                while (true)
                {
                    if (index == num && toUse.Cards[current].Rarity == Rarity.Rare)
                    {
                        Card card = toUse.Cards[current];
                        var item = new ListViewItem(card.Name);
                        item.ForeColor = card.Color;
                        item.SubItems.AddRange(new string[] { "Rare" });
                        booster.Add(item, card);
                        refs.Add(item);
                        break;
                    }
                    if (toUse.Cards[current].Rarity == Rarity.Rare)
                        index++;
                    current++;
                    if (current >= toUse.Cards.Count)
                        throw new ArgumentException("Booster pack generation error");
                }
            }
            else
            {
                int index = 0, current = 0, num = TrueRandom(mythics);
                while (true)
                {
                    if (index == num && toUse.Cards[current].Rarity == Rarity.MythicRare)
                    {
                        Card card = toUse.Cards[current];
                        var item = new ListViewItem(card.Name);
                        item.ForeColor = card.Color;
                        item.SubItems.AddRange(new string[] { "Mythic Rare" });
                        booster.Add(item, card);
                        refs.Add(item);
                        break;
                    }
                    if (toUse.Cards[current].Rarity == Rarity.MythicRare)
                        index++;
                    current++;
                    if (current >= toUse.Cards.Count)
                        throw new ArgumentException("Booster pack generation error");
                }
            }

            for (int i = 0; i < 3; i++)
            {
                int index = 0, current = 0, num = TrueRandom(uncommons);
                while (true)
                {
                    if (index == num && toUse.Cards[current].Rarity == Rarity.Uncommon)
                    {
                        Card card = toUse.Cards[current];
                        var item = new ListViewItem(card.Name);
                        item.ForeColor = card.Color;
                        item.SubItems.AddRange(new string[] { "Uncommon" });
                        booster.Add(item, card);
                        refs.Add(item);
                        break;
                    }
                    if (toUse.Cards[current].Rarity == Rarity.Uncommon)
                        index++;
                    current++;
                    if (current >= toUse.Cards.Count)
                        throw new ArgumentException("Booster pack generation error");
                }
            }

            for (int i = 0; i < 10; i++)
            {
                int index = 0, current = 0, num = TrueRandom(commons);
                while (true)
                {
                    if (index == num && toUse.Cards[current].Rarity == Rarity.Common)
                    {
                        Card card = toUse.Cards[current];
                        var item = new ListViewItem(card.Name);
                        item.ForeColor = card.Color;
                        item.SubItems.AddRange(new string[] { "Common" });
                        booster.Add(item, card);
                        refs.Add(item);
                        break;
                    }
                    if (toUse.Cards[current].Rarity == Rarity.Common)
                        index++;
                    current++;
                    if (current >= toUse.Cards.Count)
                        throw new ArgumentException("Booster pack generation error");
                }
            }

            if (basics != 0)
            {
                int index = 0, current = 0, num = TrueRandom(basics);
                while (true)
                {
                    if (index == num && toUse.Cards[current].Rarity == Rarity.BasicLand)
                    {
                        Card card = toUse.Cards[current];
                        var item = new ListViewItem(card.Name);
                        item.ForeColor = card.Color;
                        item.SubItems.AddRange(new string[] { "Basic Land" });
                        booster.Add(item, card);
                        refs.Add(item);
                        break;
                    }
                    if (toUse.Cards[current].Rarity == Rarity.BasicLand)
                        index++;
                    current++;
                    if (current >= toUse.Cards.Count)
                        throw new ArgumentException("Booster pack generation error");
                }
            }
            else
            {
                int index = 0, current = 0, num = TrueRandom(commons);
                while (true)
                {
                    if (index == num && toUse.Cards[current].Rarity == Rarity.Common)
                    {
                        Card card = toUse.Cards[current];
                        var item = new ListViewItem(card.Name);
                        item.ForeColor = card.Color;
                        item.SubItems.AddRange(new string[] { "Common" });
                        booster.Add(item, card);
                        refs.Add(item);
                        break;
                    }
                    if (toUse.Cards[current].Rarity == Rarity.Common)
                        index++;
                    current++;
                    if (current >= toUse.Cards.Count)
                        throw new ArgumentException("Booster pack generation error");
                }
            }
        }
Example #2
0
 /// <summary>
 /// Creates and instantiates the next booster pack
 /// </summary>
 private void NextBooster()
 {
     boosters++;
     cSet = sets[setRefs[boosters]];
     packs = new List<Dictionary<ListViewItem, Card>>();
     packRefs = new List<List<ListViewItem>>();
     passed = 0;
     for (int i = 0; i < 8; i++)
         CreateBooster(cSet);
     LoadBooster(0);
     panelPackInfo.Invalidate();
     cardImage.Image = null;
     labelTips.Text = "TIP";
 }