//===================================================== void UnlockNPC(string NPCID) { int NumNPCs = NPCItemsManager.GetNumItems(); NPCItemData FoundNPCItem = null; for (int Idx = 0; Idx < NumNPCs; Idx++) { NPCItemData CurNPCItem = NPCItemsManager.GetNPCItem(Idx); if (CurNPCItem.CardId == NPCID) { // Card we just bought matches an NPC, unlock the NPC Debug.Log("Found NPC to unlock for this card: " + CurNPCItem.Id); eNPC FoundNPCId = eNPC.NULL; try { FoundNPCId = (eNPC)Enum.Parse(typeof(eNPC), CurNPCItem.Id); } catch { Debug.Log("Warning: FoundNPCId state not recognised!"); } GameDataManager.Instance.UnlockPlayerNPC(FoundNPCId, true); return; } } }
//================================================================== // Use a specific classification/type rather than a random one public static TradingCardSpreadsheetItem GetSpecificCardType(eTradingCardClassification CardClassification, eTradingCardRarity CardRarity, eTradingCardCondition CardCondition, ref eNPC UnlockedNPC) { UnlockedNPC = eNPC.NULL; if (!isItemListLoaded) { LoadItemsList(); } if (CardRarity == eTradingCardRarity.TEACHER) { // If this is a 'teacher' card then unlock the next NPC in the list // If we can't unlock any switch it to a random 'rare' card instead // Get current population and find the first teacher above it // If teacher isn't owned then give the card int PlayerPopulation = GameDataManager.Instance.PlayerPopulation; int NumNPCs = NPCItemsManager.GetNumItems(); NPCItemData FoundNPCItem = null; bool bNPCFound = false; Debug.Log("Looking for TEACHER card - current population: " + PlayerPopulation); for (int Idx = 0; Idx < NumNPCs; Idx++) { NPCItemData CurNPCItem = NPCItemsManager.GetNPCItem(Idx); // Ignore CurNPCItem.PopulationUnlock of zero (default) if (CurNPCItem.PopulationUnlock == 0) { continue; } if (bNPCFound == false) { if (PlayerPopulation >= CurNPCItem.PopulationUnlock) { // Do we have this card already? int NumMint = 0; int NumScuffed = 0; TradingCardHeldItem CurHeldCard = GameDataManager.Instance.GetHeldTradingCard(CurNPCItem.CardId, ref NumMint, ref NumScuffed); if ((NumMint > 0) || (NumScuffed > 0)) { // Has card,keep searching } else { // Doesn't have card - add it bNPCFound = true; FoundNPCItem = CurNPCItem; Debug.Log("Found TEACHER card: " + FoundNPCItem.Id + " " + FoundNPCItem.CardId); } } } //Debug.Log( CurNPCItem.PopulationUnlock ); } // If no teacher card was given then use a random 'rare' card instead if (bNPCFound == false) { Debug.Log("No TEACHER card found - giving very rare card instead"); CardClassification = eTradingCardClassification.NULL; CardRarity = eTradingCardRarity.VERYRARE; } else { eNPC FoundNPCId = eNPC.NULL; try { FoundNPCId = (eNPC)Enum.Parse(typeof(eNPC), FoundNPCItem.Id); } catch { Debug.Log("Warning: FoundNPCId state not recognised!"); } UnlockedNPC = FoundNPCId; //GameDataManager.Instance.UnlockPlayerNPC( FoundNPCId ); return(GetTradingCardItem(FoundNPCItem.CardId)); } } if (CardClassification == eTradingCardClassification.NULL) { // Pick a random classification switch (UnityEngine.Random.Range(0, 3)) { case 0: CardClassification = eTradingCardClassification.WINX; break; case 1: CardClassification = eTradingCardClassification.WILD; break; case 2: CardClassification = eTradingCardClassification.STORY; break; } } if (CardRarity == eTradingCardRarity.NULL) { // Pick a random rarity (exclude teacher cards) CardRarity = (eTradingCardRarity)(UnityEngine.Random.Range((int)eTradingCardRarity.UNIQUE, (int)eTradingCardRarity.TEACHER)); } // Find all cards with this specification and pick a random one List <TradingCardSpreadsheetItem> CardList = new List <TradingCardSpreadsheetItem>(); foreach (TradingCardSpreadsheetItem Item in itemList) { if ((Item.classification == CardClassification) && (Item.rarity == CardRarity)) { CardList.Add(Item); } } // Pick from card list int CardIdx = UnityEngine.Random.Range(0, CardList.Count); if (CardList.Count == 0) { Debug.LogWarning("No cards to reward player!"); Debug.LogWarning("Classification: " + CardClassification + " Rarity: " + CardRarity + " Condition: " + CardCondition); return(itemList[0]); } else { return(CardList[CardIdx]); } }