Example #1
0
    public void AddCardToDeck(Card card)
    {
        if (currentDeckButton == null)
        {
            return;
        }

        var existingCards = currentDeckButton.deck.cards.Find(x => x.id == card.id);
        var maxCopies     = card.GetIntProperty("MaxCopies");

        if (existingCards != null && existingCards.amount == maxCopies)
        {
            OpenPopup <PopupOneButton>("PopupOneButton", popup =>
            {
                popup.text.text       = "You cannot have more than " + maxCopies + " copies of this card in your deck.";
                popup.buttonText.text = "OK";
                popup.button.onClickEvent.AddListener(() => { popup.Close(); });
            });
            return;
        }

        var itemFound = false;

        foreach (var item in cardListContent.GetComponentsInChildren <CardListItem>())
        {
            if (item.card == card)
            {
                itemFound = true;
                item.AddCard();
                break;
            }
        }

        if (!itemFound)
        {
            var go = Instantiate(cardListItemPrefab) as GameObject;
            go.transform.SetParent(cardListContent.transform, false);
            go.GetComponent <CardListItem>().deckButton        = currentDeckButton;
            go.GetComponent <CardListItem>().card              = card;
            go.GetComponent <CardListItem>().cardNameText.text = card.name;
            var cost = card.costs.Find(x => x is PayResourceCost);
            if (cost != null)
            {
                var payResourceCost = cost as PayResourceCost;
                var manaCost        = payResourceCost.value;
                go.GetComponent <CardListItem>().cardCostText.text = manaCost.ToString();
            }
        }

        currentDeckButton.deck.AddCard(card);
        currentDeckButton.UpdateDeckInfo();
    }
Example #2
0
 public void OnDeleteButtonPressed()
 {
     deckButton.deck.RemoveCards(card);
     deckButton.UpdateDeckInfo();
     Destroy(gameObject);
 }