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

        string failureReason;

        if (!ValidateAddCard(card, out failureReason))
        {
            if (errorMessage)
            {
                errorMessage.SetActive(true);
                StartCoroutine("HideErrorMessage");
            }
            if (errorMessageText)
            {
                errorMessageText.text = failureReason;
            }

            Debug.Log($"DeckBuilding validation failure : {failureReason}");
            return;
        }

        builtDeck.Add(card);
        UICardView uiCardView;

        if (uiPlayerDeckCards.TryGetValue(card.Name, out uiCardView))
        {
            IList <IPlayerCard> cards = builtDeck.FindAll((obj) => { return(obj.Name == card.Name); });
            uiCardView.SetNumberOwned(cards.Count);
        }
        else if (uiCardPoolCards.TryGetValue(card.Name, out uiCardView))
        {
            GameObject g    = Instantiate(uiCardView.gameObject);
            UICardView view = g.GetComponent <UICardView>();
            view.Setup(card);
            view.OnClick += OnUICardViewClicked;
            uiPlayerDeckCards.Add(card.Name, view);
            g.transform.parent = uiPlayerDeck;
        }
    }
Example #2
0
    public void Start()
    {
        //Error checks
        if (uiPlayerDeck == null)
        {
            Debug.LogError("UIPLAYERDECK NOT SETUP IN DECK BUILD MANAGER");
        }

        if (uiCardPool == null)
        {
            Debug.LogError("UICARDPOOL NOT SETUP IN DECK BUILD MANAGER");
        }

        if (cardUIPrefab == null)
        {
            Debug.LogError("CARD UI PREFAB NOT SETUP IN DECK BUILD MANAGER");
        }

        if (deckBuilderBackground == null)
        {
            Debug.LogError("DECK BUILDER BACKGROUND NOT SETUP IN DECK BUILD MANAGER");
        }

        if (initInfo == null)
        {
            Debug.LogError("CHASE START INFO NOT SETUP IN DECK BUILD MANAGER");
        }
        // ---

        if (errorMessage != null)
        {
            errorMessage.SetActive(false);
        }

        this.builtDeck    = new List <IPlayerCard>();
        uiPlayerDeckCards = new Dictionary <string, UICardView>();
        uiCardPoolCards   = new Dictionary <string, UICardView>();

        for (var i = 0; i < cardPool.Count; ++i)
        {
            IPlayerCard card         = cardPool[i];
            GameObject  uiCardObject = Instantiate(cardUIPrefab);
            UICardView  uICardView   = uiCardObject.GetComponent <UICardView>();
            uICardView.Setup(cardPool[i]);
            uICardView.transform.parent = uiCardPool;
            uICardView.OnClick         += OnUICardViewClicked;
            uiCardPoolCards.Add(uICardView.GetCard().Name, uICardView);
        }

        switch (initInfo.SelectedPlayerDriver)
        {
        case PlayerCardDriver.StuntDriver:
            ChangeDriverToStunt();
            break;

        case PlayerCardDriver.Navigator:
            ChangeDriverToNavigator();
            break;

        default:     //Intended to catch the none case
            ChangeDriverToMechanic();
            break;
        }

        if (initInfo.SelectedPlayerCards != null)
        {
            for (var i = 0; i < initInfo.SelectedPlayerCards.Length; ++i)
            {
                AddCardToDeck(initInfo.SelectedPlayerCards[i]);
            }
        }
    }