public bool CheckCardQuantity(string CardName)
    {
        bool rv        = true;
        int  cardcount = 0;

        CardsBase.CardDescriptionClass desc = CardsBaseComponent.FindCardDescByName(CardName);
        if (desc != null)
        {
            foreach (string cardn in CardsInDeckNames)
            {
                if (cardn.Equals(desc.Name) || cardn.Equals(desc.CardID))
                {
                    cardcount++;
                }
            }

            if (cardcount >= desc.MaxQuantity)
            {
                rv = false;
            }
        }

        return(rv);
    }
Example #2
0
    private IEnumerator LoadDecksFromServerTask(GetUserDataResult result)
    {
        while (CardsBaseComponent.DataLoaded == false)
        {
            yield return(new WaitForSeconds(0.1f));
        }
        Debug.Log("Player data loaded.");
        if (result.Data.ContainsKey("DecksNumber"))
        {
            DecksNumber = int.Parse(result.Data ["DecksNumber"].Value);
            for (int i = 0; i < DecksNumber; i++)
            {
                string   cardsAll = result.Data ["Deck" + i + "Cards"].Value;
                string[] cards    = cardsAll.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                MyDecks [i].DeckName = result.Data ["Deck" + i + "Name"].Value;
                MyDecks [i].HeroName = result.Data ["Deck" + i + "Hero"].Value;

                for (int j = 0; j < Deck.deckSize; j++)
                {
                    string cardname = "[empty]";
                    if (j < cards.Length)
                    {
                        cardname = cards [j];
                    }
                    if (CardsBaseComponent.FindCardDescByName(cardname) == null)
                    {
                        MyDecks [i].CardsNames [j] = "";
                    }
                    else
                    {
                        MyDecks [i].CardsNames [j] = cardname;
                    }
                }
            }
            for (int i = 0; i < DecksNumber; i++)
            {
                if (MyDecks [i].DeckName.Equals("empty"))
                {
                    DeleteDeck(i);
                }
            }
        }
        else
        {
            DecksNumber = 0;
        }
        //Premade decks now be available always

        /*if (!result.Data.ContainsKey ("PremadeDecksLoaded")) {
         *      Debug.Log ("Load premade decks");
         *      for(int i = 0; i < PremadeDecks.Length; i++) {
         *              MyDecks [DecksNumber].DeckName = PremadeDecks[i].DeckName;
         *              MyDecks [DecksNumber].HeroName = PremadeDecks[i].HeroName;
         *              for (int j = 0; j < Deck.deckSize; j++) {
         *                      if (CardsBaseComponent.FindCardDescByName (PremadeDecks[i].CardsNames [j]) == null) {
         *                              MyDecks [DecksNumber].CardsNames [j] = "";
         *                      } else {
         *                              MyDecks [DecksNumber].CardsNames [j] = PremadeDecks[i].CardsNames [j];
         *                      }
         *              }
         *              DecksNumber++;
         *      }
         *      UpdateUserDataRequest req = new UpdateUserDataRequest ();
         *      req.Data = new Dictionary<string, string> ();
         *      req.Data.Add ("PremadeDecksLoaded", "1");
         *      PlayFabClientAPI.UpdateUserData (req, PlayerDataSaved, OnPlayFabError);
         *      SaveDecksList ();
         * }*/
        if (!result.Data.ContainsKey(LocalPlayer.TutorialFlag))
        {
            StartCoroutine(WaitForDataAndStartTutorial());
        }
        if (result.Data.ContainsKey(MyNetworkManager.RoomNameProperty))
        {
            if ((result.Data.ContainsKey(GamePlayCore.CurrentDeckProperty)) &&
                (result.Data.ContainsKey(MyNetworkManager.GameModeProperty)))
            {
                string   cardsAll = result.Data [GamePlayCore.CurrentDeckProperty].Value;
                string[] cards    = cardsAll.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                FromPrevGame.DeckName = result.Data [GamePlayCore.CurrentDeckNameProperty].Value;
                FromPrevGame.HeroName = result.Data [GamePlayCore.CurrentDeckHeroProperty].Value;

                for (int j = 0; j < Deck.deckSize; j++)
                {
                    string cardname = "[empty]";
                    if (j < cards.Length)
                    {
                        cardname = cards [j];
                    }
                    if (CardsBaseComponent.FindCardDescByName(cardname) == null)
                    {
                        FromPrevGame.CardsNames [j] = "";
                    }
                    else
                    {
                        FromPrevGame.CardsNames [j] = cardname;
                    }
                }
                StartCoroutine(WaitForDataAndBackToGame(
                                   result.Data [MyNetworkManager.RoomNameProperty].Value,
                                   result.Data [MyNetworkManager.GameModeProperty].Value));
            }
            else
            {
                Debug.LogWarning("Cannot find previous game data");
                waitForDataScreen(false);
            }
        }
        else
        {
            Debug.LogWarning("Cannot find previous game name");
            waitForDataScreen(false);
        }
        //waitForDataScreen (false);
        DataLoaded = true;
    }