/// <summary> /// Gets a random card of a required theme. Later, have this only give unlocked cards. /// </summary> /// <param name="theme"> 0 = all, 1 = draconic</param> /// <param name="includeHanafuda"></param> /// <returns></returns> public static Card GetRandomCard(string requiredTheme = "", bool includeHanafuda = false) { CardThemeHolder theme = GetCardTheme(requiredTheme); if (theme != null) { return(theme.GetRandomCardInTheme()); } else { int totalCards = CardFactory.GetTotalCards() - CardFactory.GetCardTheme("hanafuda").CountCardsInTheme(); int pickedCard = UnityEngine.Random.Range(4, totalCards); return(GetCardByID(pickedCard)); } }
public static void CreateCardDictionaryXML() { CardDictionary = new Dictionary <string, Card>(); ThemeDictionary = new Dictionary <string, CardThemeHolder>(); var fileName = Application.dataPath + "/StreamingAssets/cardinfo.xml"; try { XmlDocument doc = new XmlDocument(); doc.Load(fileName); foreach (XmlNode node in doc.GetElementsByTagName("card")) { // This is for each card. Card newCard = ParseCardXML(node); CardDictionary.Add(newCard.CardInfo.Name.ToLower(), newCard); Debug.Log("Card parsed: " + newCard.CardInfo.Name + ", which is in theme: " + newCard.CardInfo.ThemeName); // Also make sure to add it in the theme dictionary if it has a theme // If that theme already exists, add it. if (newCard.CardInfo.ThemeName != null) { if (ThemeDictionary.TryGetValue(newCard.CardInfo.ThemeName.ToLower(), out CardThemeHolder cth)) { cth.AddCardToTheme(newCard); } else { // Theme does not exist. Add a new theme. Debug.Log("Adding a new theme called " + newCard.CardInfo.ThemeName + " for card named " + newCard.CardInfo.Name); CardThemeHolder newTheme = new CardThemeHolder(newCard.CardInfo.ThemeName.ToLower()); newTheme.AddCardToTheme(newCard); ThemeDictionary.Add(newTheme.ThemeName.ToLower(), newTheme); } } } } catch (Exception e) { Debug.Log("Error caught: " + e.Message); throw new Exception("Unable to open card info file.", e); } }