Example #1
0
    /// <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);
    }
Example #2
0
    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);
    }
Example #3
0
    /// <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);
    }
Example #4
0
    /// <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);
    }
    /// <summary>
    /// Loads gating data from XML and copies it into our
    /// save data if it does not already exist.
    /// </summary>
    private void LoadFromXML()
    {
        // init the data by filling the dictionary with xml data
        List <ImmutableDataGate> gates = DataLoaderGate.GetAllData();

        foreach (ImmutableDataGate gate in gates)
        {
            string gateID = gate.GateID;

            int hp = gate.GetMonster().MonsterHealth;

            // maps gate key to monster's max hp (i.e. no progress)
            // don't map it if it already exists; it means that the data for that key was already loaded and contains mutable save data
            if (!GatingProgress.ContainsKey(gateID))
            {
                GatingProgress[gateID] = hp;
            }
        }
    }
Example #6
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;
            }
        }
    }
Example #7
0
    protected float maxScreenSpace;     // the max screen space the gate covers with 100% HP

    protected ImmutableDataGate GetGateData()
    {
        ImmutableDataGate data = DataLoaderGate.GetData(gateID);

        return(data);
    }