/// <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!?");
        }
    }
Example #2
0
    /// <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;
            }
        }
    }