//===================================================== public static ChestReward GetChestReward(eChestType type, eTradingCardClassification cardClassification, eTradingCardRarity cardRarity, eTradingCardCondition cardCondition) { var reward = new ChestReward(); var rewardCard = (type == eChestType.LARGE && cardClassification != eTradingCardClassification.NULL && cardRarity != eTradingCardRarity.NULL); // 50% chance of awarding a card or gem if (rewardCard == false && Random.Range(0, 99) % 2 == 0) { rewardCard = true; } if (rewardCard == true) { reward.Card = TradingCardItemsManager.GetCard(type, cardClassification, cardRarity, cardCondition); reward.CardCondition = cardCondition; //Debug.Log( "SceneManager: Reward card" ); } else { // Small, medium or large number of gems var maxGems = Convert.ToInt32(SettingsManager.GetSettingsItem("AWARD_GEMS_CHEST_" + type, -1)); reward.Gems = Random.Range(maxGems / 2, maxGems); //Debug.Log( "SceneManager: Reward gems" ); } return(reward); }
//===================================================== private void SetRewardItem(eSwitchItem switchItem, eTradingCardClassification cardClassification, eTradingCardRarity cardRarity, eTradingCardCondition cardCondition) { if (switchItem == eSwitchItem.NULL) { // Reset reward to gems or a card _reward = SceneManager.GetChestReward(_type, cardClassification, cardRarity, cardCondition); } else { if (_reward == null) { _reward = new ChestReward(); } // Clear other reward items if switchItem is set _reward.Gems = 0; _reward.Card = null; _reward.SwitchItem = switchItem; } //Debug.Log( "Chest: " + _type + " : " + _reward ); // Initialise chest switchItem as reward if (_chestReward != null && _reward != null) { _chestReward.Init(_reward); } }
//================================================================== public static TradingCardSpreadsheetItem GetRandomCard(eTradingCardRarity Rarity1, float Chance1, eTradingCardRarity Rarity2, float Chance2) { if (!isItemListLoaded) { LoadItemsList(); } // Get list of cards with the passed rarity values List <TradingCardSpreadsheetItem> CardList1 = new List <TradingCardSpreadsheetItem>(); List <TradingCardSpreadsheetItem> CardList2 = new List <TradingCardSpreadsheetItem>(); foreach (TradingCardSpreadsheetItem Item in itemList) { if (Item.rarity == Rarity1) { CardList1.Add(Item); } if (Item.rarity == Rarity2) { CardList2.Add(Item); } } // Find which group of cards to pick from float CurChance = UnityEngine.Random.Range(0.0f, 100.0f); if (CurChance < Chance1) { // Pick from card list 1 int CardIdx = UnityEngine.Random.Range(0, CardList1.Count); if (CardList1.Count == 0) { Debug.LogError("No cards to reward player!"); Debug.LogError("Rarity: " + Rarity1); return(itemList[0]); } else { return(CardList1[CardIdx]); } } else { // Pick from card list 2 int CardIdx = UnityEngine.Random.Range(0, CardList2.Count); if (CardList2.Count == 0) { Debug.LogError("No cards to reward player!"); Debug.LogError("Rarity: " + Rarity2); return(itemList[0]); } else { return(CardList2[CardIdx]); } } }
public TradingCardSpreadsheetItem() { id = string.Empty; classification = eTradingCardClassification.NULL; value = 0; valueScuffed = 0; rarity = eTradingCardRarity.NULL; waitTime = 0; revealPrice = 0; page = 0; position = 0; globalPosition = 0; smallGuiTexture2D = string.Empty; largeGuiTexture2D = string.Empty; }
//================================================================== public static TradingCardSpreadsheetItem GetCard(eChestType type, eTradingCardClassification cardClassification, eTradingCardRarity cardRarity, eTradingCardCondition cardCondition) { TradingCardSpreadsheetItem card = new TradingCardSpreadsheetItem(); //if( _forceRareCardReward ) // type = eChestType.LARGE; if ((cardClassification != eTradingCardClassification.NULL) || (cardRarity != eTradingCardRarity.NULL)) { // Use a specific classification/type rather than a random one eNPC UnlockedNPC = eNPC.NULL; card = GetSpecificCardType(cardClassification, cardRarity, cardCondition, ref UnlockedNPC); return(card); } switch (type) { case eChestType.SMALL: // Return common card //card = TradingCardItemsManager.GetRandomCard( eTradingCardRarity.COMMON , 30.0f , eTradingCardRarity.VERYCOMMON , 70.0f ); card = GetRandomCard(eTradingCardRarity.COMMON, 30.0f, eTradingCardRarity.COMMON, 70.0f); break; case eChestType.MEDIUM: // Return common or uncommon card card = GetRandomCard(eTradingCardRarity.RARE, 100.0f, eTradingCardRarity.NULL, 0.0f); break; case eChestType.LARGE: // Return uncmmon or rare card //card = TradingCardItemsManager.GetRandomCard( eTradingCardRarity.VERYRARE , 80.0f , eTradingCardRarity.UNIQUE , 20.0f ); card = GetRandomCard(eTradingCardRarity.VERYRARE, 80.0f, eTradingCardRarity.VERYRARE, 20.0f); break; } return(card); }
//================================================================== // 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]); } }