//===================================================== 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; } } }
//===================================================== // ToDo: GAME UPDATE (v1.1) - Add missing special character models (Avalon, Palladium, Wizgiz) - see GameDataManager.IsPlayerNPCUnlocked private void SpawnNewNPC() { // Choose appropriate NPC depending on population level and which NPCs have been unlocked Object pfbNPC = null; _currentNumNPCs++; // Spawn special npc e.g. Faragonda or a student if (_currentNumNPCs < (int)eNPC.NUM_NPCS && NPCItemsManager.GetNPCItemPopulationUnlock((eNPC)_currentNumNPCs) < GameDataManager.Instance.PlayerPopulation && GameDataManager.Instance.IsPlayerNPCUnlocked((eNPC)_currentNumNPCs) == true) { //Debug.Log( "s.NPC" + _pfbNPCs[_currentNumNPCs].name ); //pfbNPC = _pfbNPCs[_currentNumNPCs]; pfbNPC = ResourcesNPCs.GetSpecialsPrefab(_currentNumNPCs); } else { //Debug.Log( "n.NPC" + _pfbNPCs[0].name ); //pfbNPC = _pfbNPCs[0]; pfbNPC = ResourcesNPCs.GetStudentPrefab(); } if (pfbNPC == null) { return; } // Determine random starting point for enemy var index = Random.Range(0, _wayPoints.Length); var position = _wayPoints[index].transform.position; // Create npc var npc = AddNewNPC(pfbNPC, position); if (npc == null) { return; } // Parent enemies to container npc.transform.parent = _npcContainer; npc.name = "NPC"; // Spawn enemy and set waypoints if (_wayPoints.Length > 0) { npc.OnSpawn(_wayPoints); } }
//===================================================== public static void AwardPlayer(ChestReward reward) { if (reward == null) { return; } if (reward.Gems > 0) { AddPlayerGems(reward.Gems); //Debug.Log( "Gems collected: " + reward.Gems ); } else if (string.IsNullOrEmpty(reward.Card.id) == false) { // Add card to players collection var heldCard = GameDataManager.Instance.AddTradingCard(reward.Card.id, reward.CardCondition); // If card rarity is TEACHER unlock special NPC e.g. Faragonda if (reward.Card.rarity == eTradingCardRarity.TEACHER && reward.Card.id != "NULL") { var npc = NPCItemsManager.GetNPCItemIDFromCardId(reward.Card.id); if (npc != eNPC.NULL) { GameDataManager.Instance.UnlockPlayerNPC(npc); } } // Show popup if (PopupChestReward.instance != null) { PopupChestReward.instance.Show(heldCard, 1.5f); } //Debug.Log( "Card collected: " + reward.Card._id ); } else if (reward.SwitchItem != eSwitchItem.NULL) { _currentSwitchItem = reward.SwitchItem; //Debug.Log( "Switch Item received: " + _currentSwitchItem ); } // Play player's celebrate animation PlayerManager.OnCelebrate(); }
//===================================================== public int NumStudentsAvailable() { var numStudents = 0; for (var i = 0; i < _targetNumNPCs; i++) { // Spawn special npc e.g. Faragonda or a student if ((i + 1) < (int)eNPC.NUM_NPCS && NPCItemsManager.GetNPCItemPopulationUnlock((eNPC)(i + 1)) < GameDataManager.Instance.PlayerPopulation && GameDataManager.Instance.IsPlayerNPCUnlocked((eNPC)(i + 1)) == true) { // Ignore student count } else { numStudents++; } } Debug.Log(numStudents); return(numStudents); }
//================================================================== // 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]); } }
//===================================================== void LoadLiveUpdate() { string DocPath = PreHelpers.GetFileFolderPath(); string FilePath = DocPath + "wfs2.zip"; if (System.IO.File.Exists(FilePath) == false) { return; } // Read file FileStream fs = null; try { fs = new FileStream(FilePath, FileMode.Open); } catch { Debug.Log("GameData file open exception: " + FilePath); } if (fs != null) { try { // Read zip file ZipFile zf = new ZipFile(fs); int numFiles = 0; if (zf.TestArchive(true) == false) { Debug.Log("Zip file failed integrity check!"); zf.IsStreamOwner = false; zf.Close(); fs.Close(); } else { foreach (ZipEntry zipEntry in zf) { // Ignore directories if (!zipEntry.IsFile) { continue; } String entryFileName = zipEntry.Name; // Skip .DS_Store files if (entryFileName.Contains("DS_Store")) { continue; } Debug.Log("Unpacking zip file entry: " + entryFileName); byte[] buffer = new byte[4096]; // 4K is optimum Stream zipStream = zf.GetInputStream(zipEntry); // Manipulate the output filename here as desired. string fullZipToPath = PreHelpers.GetFileFolderPath() + Path.GetFileName(entryFileName); // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size // of the file, but does not waste memory. // The "using" will close the stream even if an exception occurs. using (FileStream streamWriter = System.IO.File.Create(fullZipToPath)) { StreamUtils.Copy(zipStream, streamWriter, buffer); } numFiles++; } zf.IsStreamOwner = false; zf.Close(); fs.Close(); // If we've unpacked the local files (at least 13) then start using local spreadsheets data Debug.Log("Zip updated with " + numFiles + " files (needs 13)"); if (numFiles >= 13) { PlayerPrefs.SetInt(PreHelpers.GetLiveDataVersionString(), 1); } // Reload managers TextManager.Reload(); SettingsManager.Reload(); TradingCardItemsManager.Reload(); ClothingItemsManager.Reload(); FairyItemsManager.Reload(); WildMagicItemsManager.Reload(); NPCItemsManager.Reload(); } } catch { Debug.Log("Zip file error!"); } // Remove zip file Debug.Log("Removing zip file"); System.IO.File.Delete(FilePath); } }
//===================================================== private void Start() { // Inject this object into trigger _triggerFindTarget.GetComponent <TriggerTargetInRange>().Init(this); // Clear jobs list if (_currentJobs != null) { _currentJobs.Clear(); } // ToDo: Update this so that a reward is only given on a new day (GameDataManager should clear NPCsVisited array each new-day) // Set up simple speech bubble var isRewardAvailable = true; //_isRewardAwarded = false; if (GameDataManager.Instance.IsPlayerNPCVisited(_type)) { _guiBubbleSimple.ShowNewMeetingIcon(); isRewardAvailable = false; //_isRewardAwarded = true; //Debug.Log( "Visited" ); } else { _guiBubbleSimple.ShowAttentionIcon(); //Debug.Log( "NOT Visited" ); } // Set up reward speech bubble if (_reward == null) { _reward = new ChestReward(); } switch (_type) { case eNPC.NPC_STUDENT: // Gems _reward.Gems = Convert.ToInt32(NPCItemsManager.GetNPCItemGemReward(_type)); break; default: // Reward common card or gems if (Random.Range(0, 99) < 50) { _reward.Card = SceneManager.GetNPCReward(); } else { _reward.Gems = Convert.ToInt32(NPCItemsManager.GetNPCItemGemReward(_type)); } break; } // Set reward available / unavailable if (_guiBubbleEmoticon != null) { _guiBubbleEmoticon.SetReward(isRewardAvailable, _reward.Gems > 0); } else { Debug.Log("Warning: Emoticon bubble is probably disabled in NPC prefab."); } }