public CardClass GenerateCard <CardClass>(Card baseCard, ECardRarity rarity) where CardClass : Card
        {
            Card generatedCard = null;

            if (baseCard != null)
            {
                generatedCard = baseCard.Clone() as Card;

                // Enchant card
                if (_settings.EnchantmentsNumberPerRarity.ContainsKey(rarity))
                {
                    uint numberOfEnchantments = _settings.EnchantmentsNumberPerRarity[rarity];

                    int[] selectedEnchantments = Globals.GenerateUniqueRandomNumbers(numberOfEnchantments, 0, _enchantments.Count);

                    if (selectedEnchantments != null)
                    {
                        for (var i = 0; i < numberOfEnchantments; ++i)
                        {
                            generatedCard.Enchantments.Add(_enchantments[selectedEnchantments[i]]);
                        }
                    }
                    else
                    {
                        Console.Error.WriteLine("Error during generation of a card, not enough enchantments in DB");
                    }
                }
                else
                {
                    Console.Error.WriteLine("Error during generation of a card, rarity not found : " + rarity.ToString());
                }
            }
            else
            {
                Console.Error.WriteLine("Error during generation of card creature, null base card");
            }

            return((CardClass)(Convert.ChangeType(generatedCard, typeof(CardClass))));
        }
예제 #2
0
        public override void OnAction(Name Action, Name Param)
        {
            if (Action == BackAction)
            {
                TriggerTranstion(BackTransition);
            }
            else if (Action == GenerateCreatureAction || Action == GenerateEquipmentAction)
            {
                ECardRarity requestedRarity = ECardRarity.None;

                if (Param == CommonRarityParameter)
                {
                    requestedRarity = ECardRarity.Common;
                }
                else if (Param == MagicRarityParameter)
                {
                    requestedRarity = ECardRarity.Magic;
                }
                else if (Param == RareRarityParameter)
                {
                    requestedRarity = ECardRarity.Rare;
                }

                if (requestedRarity != ECardRarity.None)
                {
                    if (Action == GenerateCreatureAction)
                    {
                        CreatureCard creatureCard = CardsGeneratorManager.GetInstance().GenerateRandomCard <CreatureCard>(requestedRarity);
                        _generateRandomCardForm.DisplayCard(creatureCard);
                    }
                    else
                    {
                        EquipmentCard equipmentCard = CardsGeneratorManager.GetInstance().GenerateRandomCard <EquipmentCard>(requestedRarity);
                        _generateRandomCardForm.DisplayCard(equipmentCard);
                    }
                }
            }
        }
        public CardClass GenerateRandomCard <CardClass>(ECardRarity rarity) where CardClass : Card
        {
            CardClass generatedCard = default(CardClass);

            if (typeof(CardClass) == typeof(CreatureCard))
            {
                if (_creatureCards.Count > 0)
                {
                    int selectedCard = Globals.RandomNumberGenerator.Next(0, _creatureCards.Count);
                    generatedCard = GenerateCard <CardClass>(_creatureCards[selectedCard], rarity);
                }
            }
            else if (typeof(CardClass) == typeof(EquipmentCard))
            {
                if (_equipmentCards.Count > 0)
                {
                    int selectedCard = Globals.RandomNumberGenerator.Next(0, _equipmentCards.Count);
                    generatedCard = GenerateCard <CardClass>(_equipmentCards[selectedCard], rarity);
                }
            }

            return(generatedCard);
        }
예제 #4
0
 /// <summary>
 /// Returns a random rarity from MinRarity to MaxRarity (Lower extreme included, Upper extreme exluded)
 /// </summary>
 /// <param name="MinRarity"></param>
 /// <param name="MaxRarity"></param>
 /// <returns></returns>
 public static ECardRarity GetRandomRarity(ECardRarity MinRarity = ECardRarity.Common, ECardRarity MaxRarity = ECardRarity.COUNT)
 {
     return((ECardRarity)(Globals.RandomNumberGenerator.Next((int)MinRarity, (int)MaxRarity)));
 }