/// <summary>
    ///
    /// Apply the filter for a dropdown of a particular type
    ///
    /// </summary>
    private GenerateCardFilter ApplyDropdownFilter <T>(TMP_Dropdown dropdown, GenerateCardFilter activeFilter)
    {
        //If the text is All, do not need to apply the filter
        if (dropdown.captionText.text != DEFAULT_DROPDOWN_STRING)
        {
            //Parses the selected value into the enum
            var selectedField = (T)Enum.Parse(typeof(T), dropdown.captionText.text.Replace(" ", ""));
            var type          = typeof(T);

            //Sets the filter to include the selected option based on the type of dropdown
            switch (type)
            {
            case Type _ when type == typeof(Classes.ClassList):
                activeFilter.Class = (Classes.ClassList)(object) selectedField;
                break;

            case Type _ when type == typeof(Tags):
                activeFilter.Tag = (Tags)(object)selectedField;
                break;

            case Type _ when type == typeof(CardResources):
                activeFilter.Resource = (CardResources)(object)selectedField;
                break;

            case Type _ when type == typeof(CardTypes):
                activeFilter.CardType = (CardTypes)(object)selectedField;
                break;
            }
        }

        return(activeFilter);
    }
    public void ConfirmButton()
    {
        if (!string.IsNullOrWhiteSpace(createdByInput.text))
        {
            var player = GameManager.instance.GetPlayer(activeOwnerToggle.isOn);

            var generationFilter = new GenerateCardFilter(player.PlayerClass)
            {
                Name     = nameInput.text,
                CardType = CardTypes.Item,
                IncludeUncollectables = includeUncollectablesToggle.isOn,
            };
            generationFilter.IsUnique = isChoiceToggle.isOn;

            var statModType = (StatModifierTypes)Enum.Parse(typeof(StatModifierTypes), durabilityModTypeDropdown.captionText.text);
            if (statModType != StatModifierTypes.None)
            {
                if (string.IsNullOrWhiteSpace(durabilityValueInput.text))
                {
                    durabilityValueInput.text = "0";
                }
                var durabilityValue = int.Parse(durabilityValueInput.text);

                generationFilter.DurabilityChange = new KeyValuePair <StatModifierTypes, int>(statModType, durabilityValue);
            }

            if (tagDropdown.captionText.text != DEFAULT_DROPDOWN_STRING)
            {
                generationFilter.Tag = (Tags)Enum.Parse(typeof(Tags), tagDropdown.captionText.text.Replace(" ", ""));
            }

            if (isChoiceToggle.isOn)
            {
                if (int.TryParse(numToChooseInput.text, out int result) && numToChooseInput.text != "0")
                {
                    generationFilter.NumToGenerate = Mathf.Max(1, result);
                }
                else
                {
                    generationFilter.NumToGenerate = 1;
                }
            }

            if (player.GenerateCards(generationFilter, CardGenerationTypes.Equip, isChoiceToggle.isOn, createdByInput.text))
            {
                StartEffect();
            }
            else
            {
                titleText.text = $"{defaultTitleText} (Failed)";
            }
        }
        else
        {
            createdByInput.placeholder.color = new Color(0.8f, 0.0f, 0.0f, 0.5f);
            titleText.text = $"{defaultTitleText} (Input Created By)";
        }
    }
Example #3
0
    /// <summary>
    ///
    /// Function call for generate card area to confirm card generation
    ///
    /// </summary>
    public bool ConfirmCardGeneration(GenerateCardFilter filter, bool isChoice, string createdBy, DeckPositions deckPositions = DeckPositions.Random)
    {
        var filterSuccess = Player.GenerateCards(filter, selectedCardGeneration, isChoice, createdBy, deckPositions);

        if (filterSuccess)
        {
            PlayerUIBar.RefreshPlayerBar();
        }
        return(filterSuccess);
    }
    /// <summary>
    ///
    /// Initialises the tutor draw area when it is opened
    ///
    /// </summary>
    public void OpenGenerateCardArea(CardGenerationTypes cardGenerationType)
    {
        CardGenerationType = cardGenerationType;

        GenerationFilter = new GenerateCardFilter(PlayerClass);

        titleText.text   = $"Add to {CardGenerationType}";
        defaultTitleText = titleText.text;
        createdByInput.placeholder.color = new Color(0.2f, 0.2f, 0.2f, 0.5f);

        //Sets area to default values
        dropdownFields.ForEach(x => x.value = 0);
        inputFields.ForEach(x => x.text     = "");
        includeUncollectablesToggle.isOn    = false;
        isUnique.isOn = false;
        isChoice.isOn = false;

        //Hides the position field
        positionFieldArea.SetActive(CardGenerationType == CardGenerationTypes.Deck);
    }
Example #5
0
    public void ConfirmButton()
    {
        if (!string.IsNullOrWhiteSpace(createdByInput.text))
        {
            var player = GameManager.instance.GetPlayer(activeOwnerToggle.isOn);

            var enchantment = new UnitEnchantment()
            {
                Status = UnitEnchantment.EnchantmentStatus.Permanent, Source = createdByInput.text
            };
            GetStatModifier(enchantment, Unit.StatTypes.Attack, attackModTypeDropdown, attackValueInput);
            GetStatModifier(enchantment, Unit.StatTypes.MaxHealth, healthModTypeDropdown, healthValueInput);
            GetStatModifier(enchantment, Unit.StatTypes.Range, rangeModTypeDropdown, rangeValueInput);
            GetStatModifier(enchantment, Unit.StatTypes.Speed, speedModTypeDropdown, speedValueInput);

            var generationFilter = new GenerateCardFilter(player.PlayerClass)
            {
                Name     = nameInput.text,
                CardType = CardTypes.Unit,
                IncludeUncollectables = includeUncollectablesToggle.isOn,
                IsUnique = isChoiceToggle.isOn,
            };

            if (tagDropdown.captionText.text != DEFAULT_DROPDOWN_STRING)
            {
                generationFilter.Tag = (Tags)Enum.Parse(typeof(Tags), tagDropdown.captionText.text.Replace(" ", ""));
            }

            if (enchantment.ValidEnchantment)
            {
                generationFilter.Enchantment = enchantment;
            }

            if (int.TryParse(numToCreateInput.text, out int result) && numToCreateInput.text != "0")
            {
                generationFilter.UnitsToCreate = Mathf.Max(1, result);
            }
            else
            {
                generationFilter.UnitsToCreate = 1;
            }

            if (isChoiceToggle.isOn)
            {
                generationFilter.NumToGenerate = generationFilter.UnitsToCreate;
            }

            if (player.GenerateCards(generationFilter, CardGenerationTypes.Deploy, isChoiceToggle.isOn, createdByInput.text))
            {
                StartEffect();
            }
            else
            {
                titleText.text = $"{defaultTitleText} (Failed)";
            }
        }
        else
        {
            createdByInput.placeholder.color = new Color(0.8f, 0.0f, 0.0f, 0.5f);
            titleText.text = $"{defaultTitleText} (Input Created By)";
        }
    }
Example #6
0
    public bool GenerateCards(GenerateCardFilter filter, CardGenerationTypes generationType, bool isChoice, string createdBy, DeckPositions deckPosition = DeckPositions.Random)
    {
        var generatedCardDatas = GameManager.instance.libraryManager.GenerateGameplayCards(filter);

        if (generatedCardDatas.Count == 0)
        {
            return(false);
        }

        if (!isChoice && generationType == CardGenerationTypes.Deploy && generatedCardDatas.Count > 1)
        {
            return(false);
        }

        var generatedCards = new List <Card>();

        foreach (var cardData in generatedCardDatas)
        {
            var generatedCard = GameManager.instance.libraryManager.CreateCard(cardData, this);
            if (generatedCard.Type == CardTypes.Unit && filter.Enchantment != null)
            {
                ((Unit)generatedCard).AddEnchantment(filter.Enchantment);
            }
            if (generatedCard.Type == CardTypes.Item && filter.DurabilityChange != null)
            {
                ((Item)generatedCard).EditDurability(filter.DurabilityChange.Value);
            }

            if (filter.CostModification != null)
            {
                var adjustCost = new AdjustCostObject()
                {
                    Value          = filter.CostModification.Value,
                    TargetResource = filter.ResourceModification,
                    AdjustmentType = StatModifierTypes.Modify,
                };
                generatedCard.ModifyCost(adjustCost);
            }

            if (isChoice)
            {
                generatedCards.Add(generatedCard);
            }
            else
            {
                switch (generationType)
                {
                case CardGenerationTypes.Hand:
                    AddToHand(generatedCard, createdBy);
                    break;

                case CardGenerationTypes.Deck:
                    Deck.ShuffleIntoDeck(generatedCard, createdBy, deckPosition);
                    break;

                case CardGenerationTypes.Graveyard:
                    AddToGraveyard(generatedCard, createdBy);
                    break;

                case CardGenerationTypes.Deploy:
                    CreateDeployUnits(cardData, filter.Enchantment, filter.UnitsToCreate, createdBy);
                    break;

                case CardGenerationTypes.Equip:
                    GameManager.instance.effectManager.SetItemEquip((Item)generatedCard);
                    break;

                default:
                    throw new Exception("Not a valid Generation Type");
                }
            }
        }

        if (isChoice)
        {
            switch (generationType)
            {
            case CardGenerationTypes.Hand:
                GameManager.instance.effectManager.SetAddToHandChoiceMode(generatedCards, createdBy);
                break;

            case CardGenerationTypes.Deck:
                GameManager.instance.effectManager.SetAddToDeckChoiceMode(generatedCards, createdBy, deckPosition);
                break;

            case CardGenerationTypes.Graveyard:
                GameManager.instance.effectManager.SetAddToGraveyardChoiceMode(generatedCards, createdBy);
                break;

            case CardGenerationTypes.Deploy:
                GameManager.instance.effectManager.SetDeployChoiceMode(generatedCards, createdBy);
                break;

            case CardGenerationTypes.Equip:
                GameManager.instance.effectManager.SetItemChoiceMode(generatedCards, createdBy);
                break;

            default:
                throw new Exception("Not a valid Generation Type");
            }
        }

        return(true);
    }
    /// <summary>
    ///
    /// Gets a selection of cards which are generated during a gameplay scenario
    ///
    /// </summary>
    /// <param name="generateCardFilter">The filter to select cards by</param>
    /// <param name="numToGenerate">The number of cards to generate</param>
    public List <CardData> GenerateGameplayCards(GenerateCardFilter generateCardFilter)
    {
        //Generates the filter to look through the playable list
        var cardFilter = new CardFilter();

        if (generateCardFilter.CardType != CardTypes.Default)
        {
            cardFilter.CardTypeFilter = new List <CardTypes>()
            {
                generateCardFilter.CardType
            }
        }
        ;
        cardFilter.SetFilter = generateCardFilter.SetFilter;

        //If in the setup phase, only want to generate token cards
        if (GameManager.instance.CurrentGamePhase == GameManager.GamePhases.Setup)
        {
            cardFilter.RaritiyFilter = new List <Rarity>()
            {
                Rarity.Token
            };
            generateCardFilter.IncludeUncollectables = false;
        }
        //Adds uncollectable cards if generated filter requires it
        if (generateCardFilter.IncludeUncollectables)
        {
            cardFilter.RaritiyFilter.Add(Rarity.Uncollectable);
            cardFilter.RaritiyFilter.Add(Rarity.Token);
        }

        //Gets the class playable list using the generated filter in order to ensure cards which cannot be generated outside of the players class
        var classResource = new ClassResources(generateCardFilter.ClassPlayable);
        var generatedList = GetDictionaryList(classResource, cardFilter);

        //Checks the filters not covered by the normal filtered card list
        if (!string.IsNullOrWhiteSpace(generateCardFilter.Name))
        {
            generatedList = generatedList.Where(x => x.Name.ToLower() == generateCardFilter.Name.ToLower()).ToList();
        }
        if (generateCardFilter.Resource != CardResources.Neutral)
        {
            generatedList = generatedList.Intersect(GetDictionaryList(generateCardFilter.Resource)).Where(x => x.GetResources.Count == 1).ToList();
        }
        if (generateCardFilter.Class != Classes.ClassList.Default)
        {
            generatedList = generatedList.Intersect(GetDictionaryList(generateCardFilter.Class)).ToList();
        }
        if (generateCardFilter.Tag != Tags.Default)
        {
            generatedList = generatedList.Intersect(GetDictionaryList(generateCardFilter.Tag)).ToList();
        }

        var selectedCards = new List <CardData>();

        //If the generated cards are required to be unique and there are not enough cards in the selection to be unique, does not continue with the selection
        if (!generateCardFilter.IsUnique || generateCardFilter.IsUnique && generateCardFilter.NumToGenerate <= generatedList.Count)
        {
            //Selects the number of cards required to be generated randomly from the filtered list and returns the selection
            if (generatedList.Count > 0)
            {
                for (int index = 0; index < generateCardFilter.NumToGenerate; index++)
                {
                    CardData selectedCard;
                    do
                    {
                        var randomVal = UnityEngine.Random.Range(0, generatedList.Count);
                        selectedCard = generatedList[randomVal];
                    } while (generateCardFilter.IsUnique && selectedCards.Select(x => x.Id).Contains(selectedCard.Id));
                    selectedCards.Add(selectedCard);
                }
            }
        }

        return(selectedCards);
    }