/// <summary> /// Stores the gate in a hash of areas to partition ids to the actual data. /// </summary> /// <param name="dataGate">Data gate.</param> private void SortGate(ImmutableDataGate dataGate) { if (zoneDictionary == null) { zoneDictionary = new Hashtable(); } string zoneID = dataGate.Zone; int localPartition = dataGate.LocalPartition; // if the area isn't in the hash yet, create it if (!zoneDictionary.ContainsKey(zoneID)) { zoneDictionary[zoneID] = new Hashtable(); } Hashtable zone = (Hashtable)zoneDictionary[zoneID]; if (zone.ContainsKey(localPartition)) { Debug.LogError("Duplicate gate for room " + localPartition + " in area " + zone); } else { zone[localPartition] = dataGate; } }
private int GetLatestUnlockedAbsolutePartition(){ ImmutableDataGate latestGate = GatingManager.Instance.GetLatestLockedGate(); if(latestGate != null){ // All gates unlocked return latestGate.AbsolutePartition - 1; // Get latest gate and subtract 1 } else{ // All gates unlocked List<ImmutableDataPartition> list = DataLoaderPartitions.GetDataList(); return DataLoaderPartitions.GetDataList().Count - 1; // Get the gates list count, off by 1 } }
/// <summary> /// Determines whether area roomPartition has active gate. /// </summary> /// <returns><c>true</c> if there is active gate at the specified area roomPartition; otherwise, <c>false</c>.</returns> public bool HasActiveGate(string zone, int localParition) { bool isActive = false; ImmutableDataGate data = DataLoaderGate.GetData(zone, localParition); if (data != null) { isActive = DataManager.Instance.GameData.GatingProgress.IsGateActive(data.GateID); } return(isActive); }
/// <summary> /// Refreshes the gate. /// </summary> public void RefreshGate(ImmutableDataGate data) { string gateID = data.GateID; if (GatingProgress.ContainsKey(gateID)) { int hp = data.GetMonster().MonsterHealth; GatingProgress[gateID] = hp; } else { Debug.LogError("Trying to refresh a gate not in data...is this even possible!?"); } }
protected override void XMLNodeHandler(string id, IXMLNode xmlNode, Hashtable hashData, string errorMessage) { ImmutableDataGate data = new ImmutableDataGate(id, xmlNode, errorMessage); if (hashData.ContainsKey(id)) { Debug.LogError(errorMessage + "Duplicate keys!"); } else { // add to dictionary of all gates hashData.Add(id, data); // we also want to store the gates in a more elaborate hashtable for easy access SortGate(data); } }
/// <summary> /// Gets the gate data. Will be null if there is no gate /// </summary> /// <returns>The data.</returns> /// <param name="area">Area.</param> /// <param name="roomPartition">Room partition.</param> public static ImmutableDataGate GetData(string zoneID, int localPartition) { instance.InitXMLLoader(); instance.ForceSetup(); ImmutableDataGate dataGate = null; if (zoneID != null && zoneDictionary.ContainsKey(zoneID)) { Hashtable zone = (Hashtable)zoneDictionary[zoneID]; if (zone.ContainsKey(localPartition)) { dataGate = (ImmutableDataGate)zone[localPartition]; } } return(dataGate); }
public ImmutableDataGate GetLatestLockedGate() { List <ImmutableDataGate> gateList = DataLoaderGate.GetAllData(); int minLockedGateNumberSoFar = 999; ImmutableDataGate minLockedGateSoFar = null; foreach (ImmutableDataGate gate in gateList) { if (gate.GateNumber < minLockedGateNumberSoFar && DataManager.Instance.GameData.GatingProgress.IsGateActive(gate.GateID)) { minLockedGateNumberSoFar = gate.GateNumber; minLockedGateSoFar = gate; } } latestUnlockedGate = minLockedGateSoFar; // Cache it return(minLockedGateSoFar); }
/// <summary> /// Calculates the latest unlocked gate. /// This should be called everytime that a gate is unlocked /// 'Null' if no unlocked gates yet /// </summary> private ImmutableDataGate GetLatestUnlockedGate() { List <ImmutableDataGate> gateList = DataLoaderGate.GetAllData(); int maxGateNumberSoFar = -1; ImmutableDataGate latestGateSoFar = null; foreach (ImmutableDataGate gate in gateList) { if (gate.GateNumber > maxGateNumberSoFar && !DataManager.Instance.GameData.GatingProgress.IsGateActive(gate.GateID)) { maxGateNumberSoFar = gate.GateNumber; latestGateSoFar = gate; } } latestUnlockedGate = latestGateSoFar; // Cache it return(latestGateSoFar); }
/// <summary> /// Determines whether the player can enter room. /// </summary> /// <returns><c>true</c> if player can enter room ie player is moving from a smog room; otherwise, <c>false</c>.</returns> /// <param name="currentRoom">Current room.</param> /// <param name="eSwipeDirection">E swipe direction.</param> public bool CanEnterRoom(int currentLocalPartition, RoomDirection swipeDirection) { // start off optimistic bool isAllowed = true; // if there is an active gate in this room, check to see if it is blocking the direction the player is trying to go in ImmutableDataGate dataGate = DataLoaderGate.GetData(currentZone, currentLocalPartition); if (dataGate != null && DataManager.Instance.GameData.GatingProgress.IsGateActive(dataGate.GateID) && dataGate.DoesBlock(swipeDirection)) { isAllowed = false; } return(isAllowed); }
private void CreateMiniPet(string miniPetId) { GameObject goMiniPet = null; // Unlock in data manager DataManager.Instance.GameData.MiniPets.UnlockMiniPet(miniPetId); DataManager.Instance.GameData.MiniPetLocations.UnlockMiniPet(miniPetId); ImmutableDataMiniPet data = DataLoaderMiniPet.GetData(miniPetId); GameObject prefab = Resources.Load(data.PrefabName) as GameObject; switch (data.Type) { case MiniPetTypes.Retention: // Check if mp needs new locations if (isSpawnNewLocations) { DataManager.Instance.GameData.Wellapad.ResetMissions(); } // Only spawn the retention pet in the bedroom if (SceneManager.GetActiveScene().name == SceneUtils.BEDROOM) { // Calculate the MP location LgTuple <Vector3, string> retentionLocation = PartitionManager.Instance.GetBasePositionInBedroom(); Vector3 locationPosition = retentionLocation.Item1; string locationId = retentionLocation.Item2; int partitionNumber = 0; DataManager.Instance.GameData.MiniPets.SetIsHatched(miniPetId, true); DataManager.Instance.GameData.MiniPetLocations.SaveLocationId(miniPetId, locationId); // locationId from tuple DataManager.Instance.GameData.MiniPets.SaveHunger(miniPetId, true); // Set to always full goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partitionNumber).gameObject, prefab); goMiniPet.transform.localPosition = locationPosition; // vector3 from tuple goMiniPet.name = prefab.name; MiniPetRetentionPet retentionScript = goMiniPet.GetComponent <MiniPetRetentionPet>(); retentionScript.Init(data); retentionScript.FigureOutMissions(); if (!DataManager.Instance.GameData.Wellapad.CurrentTasks.ContainsKey("DailyInhaler")) { retentionScript.GiveOutMission(); } // Add the pet into the dictionary to keep track MiniPetTable.Add(miniPetId, goMiniPet); } break; case MiniPetTypes.GameMaster: // Check if mp needs new locations ImmutableDataGate latestGate = GatingManager.Instance.GetLatestLockedGate(); // if(latestGate == null) // Debug.Log("-----Spawning GameMaster: " + (latestGate == null) + " gate null"); // else // Debug.Log("-----Spawning GameMaster: " + (latestGate.AbsolutePartition - 1 >= 1) + " || latest gate " + latestGate.AbsolutePartition); if (latestGate == null || (latestGate.AbsolutePartition - 1 >= 1)) { // NOTE: Besides spawning new locations, there may not be any data for a minipet when coming back to same PP, do or check if (isSpawnNewLocations || GetPartitionNumberForMinipet(miniPetId) == -1) { // Calculate the MP location MinigameTypes type = PartitionManager.Instance.GetRandomUnlockedMinigameType(); LgTuple <Vector3, string> gameMasterLocation = PartitionManager.Instance.GetPositionNextToMinigame(type); Vector3 locationPosition = gameMasterLocation.Item1; string locationId = gameMasterLocation.Item2; int partitionNumber = DataLoaderPartitionLocations.GetAbsolutePartitionNumberFromLocationId(locationId); // Save information for minipet DataManager.Instance.GameData.MiniPetLocations.SaveLocationId(miniPetId, locationId); DataManager.Instance.GameData.MiniPets.SaveHunger(miniPetId, false); // Spawn the minipet if it is in current scene if (PartitionManager.Instance.IsPartitionInCurrentZone(partitionNumber)) { goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partitionNumber).gameObject, prefab); goMiniPet.transform.localPosition = locationPosition; goMiniPet.name = prefab.name; MiniPetGameMaster gameMasterScript = goMiniPet.GetComponent <MiniPetGameMaster>(); gameMasterScript.minigameType = type; gameMasterScript.Init(data); gameMasterScript.isFinishEating = false; // Add the pet into the dictionary to keep track MiniPetTable.Add(miniPetId, goMiniPet); } } // Spawn based on its saved location else { // If the saved minipet location is in the current zone if (PartitionManager.Instance.IsPartitionInCurrentZone(GetPartitionNumberForMinipet(miniPetId))) { string locationId = DataManager.Instance.GameData.MiniPetLocations.GetLocationId(miniPetId); // Get relevant info to populate with given saved location ID int partition = DataLoaderPartitionLocations.GetAbsolutePartitionNumberFromLocationId(locationId); Vector3 pos = DataLoaderPartitionLocations.GetOffsetFromLocationId(locationId); MinigameTypes minigameType = DataLoaderPartitionLocations.GetMinigameTypeFromLocationId(locationId); goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partition).gameObject, prefab); goMiniPet.transform.localPosition = pos; goMiniPet.name = prefab.name; MiniPetGameMaster gameMasterScript = goMiniPet.GetComponent <MiniPetGameMaster>(); gameMasterScript.minigameType = minigameType; gameMasterScript.Init(data); // Add the pet into the dictionary to keep track MiniPetTable.Add(miniPetId, goMiniPet); } } } break; case MiniPetTypes.Merchant: ImmutableDataGate latestGate2 = GatingManager.Instance.GetLatestLockedGate(); // if(latestGate2 == null) // Debug.Log("-----Spawning merchant: " + (latestGate2 == null) + " gate null"); // else // Debug.Log("-----Spawning merchant: " + (latestGate2.AbsolutePartition - 1 >= 2) + " || latest gate " + latestGate2.AbsolutePartition); if (DataManager.Instance.GameData.MiniPetLocations.IsMerchantSpawning()) { if (latestGate2 == null || (latestGate2.AbsolutePartition - 1 >= 2)) { // Check if mp needs new locations // NOTE: Besides spawning new locations, there may not be any data for a minipet when coming back to same PP, do or check if (isSpawnNewLocations || GetPartitionNumberForMinipet(miniPetId) == -1) { // Calculate the MP location LgTuple <Vector3, string> merchantLocation = PartitionManager.Instance.GetRandomUnusedPosition(); Vector3 locationPosition = merchantLocation.Item1; string locationId = merchantLocation.Item2; int partitionNumber = DataLoaderPartitionLocations.GetAbsolutePartitionNumberFromLocationId(locationId); // Save information for minipet DataManager.instance.GameData.MiniPetLocations.SaveLocationId(miniPetId, locationId); DataManager.Instance.GameData.MiniPets.SaveHunger(miniPetId, false); // Set new merchant item here only List <ImmutableDataMerchantItem> merchantItemsList = DataLoaderMerchantItem.GetDataList(); int rand = UnityEngine.Random.Range(0, merchantItemsList.Count); DataManager.Instance.GameData.MiniPets.SetItem(miniPetId, rand); DataManager.Instance.GameData.MiniPets.SetItemBoughtInPP(miniPetId, false); // Spawn the minipet if it is in current scene if (PartitionManager.Instance.IsPartitionInCurrentZone(partitionNumber)) { goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partitionNumber).gameObject, prefab); goMiniPet.transform.localPosition = locationPosition; goMiniPet.name = prefab.name; MiniPetMerchant merchantScript = goMiniPet.GetComponent <MiniPetMerchant>(); merchantScript.Init(data); merchantScript.isFinishEating = false; // Add the pet into the dictionary to keep track MiniPetTable.Add(miniPetId, goMiniPet); } } // Spawn based on its saved location else { // If the saved minipet location is in the current zone if (PartitionManager.Instance.IsPartitionInCurrentZone(GetPartitionNumberForMinipet(miniPetId))) { string locationId = DataManager.Instance.GameData.MiniPetLocations.GetLocationId(miniPetId); // Get relevant info to populate with given saved location ID int partition = DataLoaderPartitionLocations.GetAbsolutePartitionNumberFromLocationId(locationId); Vector3 pos = DataLoaderPartitionLocations.GetOffsetFromLocationId(locationId); //MinigameTypes minigameType = DataLoaderPartitionLocations.GetMinigameTypeFromLocationId(locationId); goMiniPet = GameObjectUtils.AddChild(PartitionManager.Instance.GetInteractableParent(partition).gameObject, prefab); goMiniPet.transform.localPosition = pos; goMiniPet.name = prefab.name; MiniPetMerchant merchantScript = goMiniPet.GetComponent <MiniPetMerchant>(); merchantScript.Init(data); // Add the pet into the dictionary to keep track MiniPetTable.Add(miniPetId, goMiniPet); } } } } break; default: Debug.LogError("Bad minipet type specified: " + data.Type.ToString()); break; } }
/// <summary> /// Spawns the gates. /// </summary> private void SpawnGates() { Hashtable hashGates = DataLoaderGate.GetZoneGates(currentZone); foreach (DictionaryEntry entry in hashGates) { ImmutableDataGate dataGate = (ImmutableDataGate)entry.Value; int partition = dataGate.LocalPartition; // if the gate is activate, spawn the monster at an offset bool isGateActive = DataManager.Instance.GameData.GatingProgress.IsGateActive(dataGate.GateID); // check if gate is still in the scene. SpawnGates is also called after // game is paused so need to check the status of each gate. This is mainly // for the recurring gate to be spawned correctly bool isGateInSceneAlready = false; if (activeGates.ContainsKey(partition)) { try { GameObject gateObject = activeGates[partition].gameObject; if (gateObject) { isGateInSceneAlready = true; } } // Gate object has already been destroyed. catch (MissingReferenceException e) { Debug.LogException(e); isGateInSceneAlready = false; } catch (NullReferenceException e) { Debug.LogException(e); isGateInSceneAlready = false; } } if (isGateActive && !isGateInSceneAlready) { int startingCurrentPartition = scriptPan.currentLocalPartition; // room the player is in float roomPartitionOffset = scriptPan.partitionOffset; // the distance between each room int partitionCountFromStartingPartition = dataGate.LocalPartition - startingCurrentPartition; // the distance between the starting room and this gate's room float distanceFromStartingPartition = partitionCountFromStartingPartition * roomPartitionOffset; // offset of the gate // how much screen space should the gate be moved by float screenOffset = Screen.width * dataGate.ScreenPercentage; Vector3 newScreenPosition = new Vector3(screenOffset, startingScreenPosition.y, startingScreenPosition.z); float maxScreenSpace = Screen.width - screenOffset; // convert screen space back to world space Vector3 worldLocation = Camera.main.ScreenToWorldPoint(newScreenPosition); //we only want the x position from worldLocation. y and z should stay the same Vector3 gateLocation = new Vector3(worldLocation.x, startingLocation.y, startingLocation.z); // move the offsetted gate to the proper partition gateLocation.x += distanceFromStartingPartition; // create the gate at the location and set its id string strPrefab = dataGate.GetMonster().ResourceKey; GameObject prefab = Resources.Load(strPrefab) as GameObject; GameObject goGate = Instantiate(prefab, gateLocation, Quaternion.identity) as GameObject; Gate scriptGate = goGate.GetComponent <Gate>(); string gateID = dataGate.GateID; scriptGate.Init(gateID, dataGate.GetMonster(), maxScreenSpace); // hash the gate based on the room, for easier access activeGates[partition] = scriptGate; } } }
protected float maxScreenSpace; // the max screen space the gate covers with 100% HP protected ImmutableDataGate GetGateData() { ImmutableDataGate data = DataLoaderGate.GetData(gateID); return(data); }