Example #1
0
    void KillGuard(int guardId)
    {
        // if achievement not unlocked
        if (!PlayerPrefs.HasKey("Roadman"))
        {
            GetComponent <Achievements>()?.Roadman();
        }

        // get the guard's photon view
        PhotonView killedGuard = PhotonView.Find(guardId)?.GetComponent <PhotonView>();

        // this check is added due to the laggy nature of RPCs, if the master client had high ping and the other client shot at the guard several times before they died, multiple dead bodies would
        // appear as the guard dying would have a slight delay
        if (killedGuard != null)
        {
            GuardAIPhoton killedGuardObject = PhotonView.Find(guardId).GetComponent <GuardAIPhoton>();
            // checks if the music should be reset to normal
            killedGuardObject.CheckMusicOnGuardDeath();
            // gets the position of the guard before they died so they can be spawned in the same position
            Vector3    guardPos = killedGuard.transform.position;
            Quaternion guardRot = killedGuard.transform.rotation;
            // spawns dead guard slightly above so they don't clip through the floor
            guardPos.y += 0.5f;

            // remove the guard
            PhotonNetwork.Destroy(killedGuard);
            // create a dead body that will be draggable (allow new guard model)
            GameObject deadGuard = PhotonNetwork.Instantiate("PhotonPrefabs/dead_guard", guardPos, guardRot);
        }
    }
Example #2
0
 public IEnumerator TestGuardAIPhotonScriptHasRightFields()
 {
     foreach (var g in guards)
     {
         GuardAIPhoton script = g.GetComponent <GuardAIPhoton>();
         Assert.IsNotNull(script.guard);
         Assert.IsNotNull(script.spotlight);
         Assert.IsNotNull(script.sounds);
     }
     yield return(null);
 }
Example #3
0
    // if item falls next to guard, alert all guards to go to where it fell
    void SetGuardsToAlertedItem(Vector3 position)
    {
        Transform parent = transform.parent;

        foreach (Transform child in parent)
        {
            GuardAIPhoton temp = child.gameObject.GetComponent <GuardAIPhoton>();
            temp.guardState    = State.Alerted;
            temp.timeAlerted   = 0f;
            temp.alertPosition = position;
        }
    }
Example #4
0
    // if item falls next to guard, alert all guards to go to where it fell
    void SetGuardsToAlertedItem(Vector3 position)
    {
        Transform parent = transform.parent;

        // loops through all guards that are children of the same GameObject
        foreach (Transform child in parent)
        {
            // sets the guard to be alerted, resets their time alerted and changes their alert position to where the item had landed
            GuardAIPhoton temp = child.gameObject.GetComponent <GuardAIPhoton>();
            temp.guardState    = State.Alerted;
            temp.timeAlerted   = 0f;
            temp.alertPosition = position;
        }
    }
Example #5
0
    // sets all guards that are a child of the same GameObject to be alerted to the player
    void SetGuardsToAlerted()
    {
        Transform parent        = transform.parent;
        Transform closestPlayer = FindClosestPlayer();

        foreach (Transform child in parent)
        {
            GuardAIPhoton temp = child.gameObject.GetComponent <GuardAIPhoton>();
            // sets the guard to be alerted if they're not chasing
            if (temp.guardState != State.Chasing)
            {
                temp.guardState = State.Alerted;
            }
            // resets time alerted
            temp.timeAlerted = 0f;
            // sets alerted position to be the closest player's position
            temp.alertPosition = closestPlayer.position;
        }
    }
Example #6
0
    // sets all guards in the level to be alerted
    public void SetAllGuardsToAlerted()
    {
        GameObject[] allGuards     = GameObject.FindGameObjectsWithTag("Guard");
        Transform    closestPlayer = FindClosestPlayer();

        foreach (var guard in allGuards)
        {
            Transform     child = guard.transform;
            GuardAIPhoton temp  = child.gameObject.GetComponent <GuardAIPhoton>();
            // sets the guard to be alerted if they're not chasing
            if (temp.guardState != State.Chasing)
            {
                temp.guardState = State.DeadGuardAlerted;
            }
            // resets time alerted
            temp.timeAlerted = 0f;
            // sets alerted position to be the closest player's position
            temp.alertPosition = closestPlayer.position;
        }
    }
Example #7
0
    // used to check if all guards are patroling
    // use of this is done to check if music is able to be changed back to normal music from chase music as well as checking if player completed the achievement
    bool CheckIfAllGuardsPatroling()
    {
        GameObject[] allGuards = GameObject.FindGameObjectsWithTag("Guard");
        // loops through guards and checks if they are patroling
        foreach (var guard in allGuards)
        {
            Transform     child = guard.transform;
            GuardAIPhoton temp  = child.gameObject.GetComponent <GuardAIPhoton>();
            // sets the guard to be alerted if they're not chasing
            if (temp.guardState != State.Patroling)
            {
                return(false);
            }
        }

        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

        foreach (var player in players)
        {
            player.GetComponent <Achievements>()?.OnTheRunCompleted();
        }

        return(true);
    }