Exemplo n.º 1
0
        // respawn player
        public IEnumerator Respawn()
        {
            GameManager.Instance.BloodSplash.DoFadeOutAtSpeed(0.09f);

            yield return(new WaitForSeconds(RespawnDelay));



            isDead        = false;
            CurrentHealth = startCurrentHealth;
            if (playerController)
            {
                if (photonView.isMine)
                {
                    if (playerController.CurrentWeapon)
                    {
                        playerController.CurrentWeapon.ammunition    = playerController.CurrentWeapon.StartAmmunition;
                        playerController.CurrentWeapon.cartridgeAmmo = playerController.CurrentWeapon.CartridgeAmmo;

                        GameManager.Instance.UpdateAmmoUI();
                    }

                    playerController.Model.gameObject.SetActive(false);


                    GameManager.Instance.FadeWhenSight2D.SetActive(true);
                    if (playerController.CurrentWeapon && playerController.CurrentWeapon.Sight2D)
                    {
                        playerController.CurrentWeapon.Sight2D.DoFadeOutInmmediately();
                        playerController.CurrentWeapon.Sight2D.gameObject.SetActive(true);
                    }
                    playerController.rigidBody.isKinematic = false;
                    GameManager.Instance.BloodSplash.DoFadeOutInmmediately();

                    GameManager.Instance.BloodSplash.gameObject.SetActive(true);

                    foreach (Transform child in playerController.Model.transform)
                    {
                        child.gameObject.SetActive(false);
                    }
                    playerController.RagdollDieCamera.gameObject.SetActive(false);
                    playerController.PCamera.gameObject.SetActive(true);

                    playerController.ModelAnimator.enabled = true;

                    // delete items
                    List <int> deleteThings = new List <int>();
                    foreach (var item in playerController.Items)
                    {
                        if (!playerController.StartWeaponsSpawned.Contains(item.item.GetComponent <Weapon>()))
                        {
                            deleteThings.Add(item.photonView.viewID);
                        }
                    }
                    foreach (var itemToDelete in deleteThings)
                    {
                        playerController.photonView.RPC("DropItem", PhotonTargets.All, itemToDelete);
                    }
                    // use start item
                    playerController.photonView.RPC("UseItem", PhotonTargets.AllBuffered, playerController.StartWeaponsSpawned[0].photonView.viewID, 0);
                }
                else
                {
                    playerController.rigidBody.isKinematic = false;

                    playerController.ModelAnimator.enabled = true;

                    if (playerController.CurrentWeapon)
                    {
                        playerController.CurrentWeapon.gameObject.SetActive(true);
                        playerController.CurrentWeapon.GetComponent <BoxCollider>().enabled = false;
                    }
                }
                // set position to spawn point
                transform.position = MultiplayerGameManager.Instance.GetSpawnPoint(playerController.Team1).position;
            }
            // AI Player
            else
            {
                // set position to spawn point

                transform.position = MultiplayerGameManager.Instance.GetSpawnPoint(GetComponent <AIPlayer>().Team1).position;

                AIPlayer aiPlayer = GetComponent <AIPlayer>();
                if (aiPlayer.PlayerWeapon)
                {
                    aiPlayer.PlayerWeapon.gameObject.SetActive(true);
                    aiPlayer.PlayerWeapon.GetComponent <BoxCollider>().enabled = false;
                }


                aiPlayer.Model.enabled         = true;
                aiPlayer.rigidBody.isKinematic = false;

                aiPlayer.agent.stoppingDistance = aiPlayer.startArrivedDistance;
                aiPlayer.fsm.ChangeState(AIPlayer.States.GoStartPos, AxlPlay.StateTransition.Overwrite);
            }
        }
Exemplo n.º 2
0
        IEnumerator Die()
        {
            if (!PhotonNetwork.offlineMode && MultiplayerGameManager.Instance.GameMode != MultiplayerGameManager.GameModes.FreeForAll)
            {
                if (damager || !photonView.isMine)
                {
                    // network team scores
                    if (playerController.Team1)
                    {
                        MultiplayerGameManager.Instance.Team2Score++;
                    }
                    else
                    {
                        MultiplayerGameManager.Instance.Team1Score++;
                    }
                }
            }

            MultiplayerGameManager.Instance.UpdateTeamScoresUI();


            isDead = true;
            if (playerController)
            {
                // add deaths and kills in players
                playerController.Deaths++;


                if (photonView.isMine)
                {
                    if (playerController.grabbedItem)
                    {
                        playerController.grabbedItem.transform.SetParent(playerController.itemLastParent);

                        Rigidbody currentDraggingItemRg = playerController.grabbedItem.GetComponent <Rigidbody>();
                        if (currentDraggingItemRg)
                        {
                            currentDraggingItemRg.isKinematic = false;
                        }

                        playerController.grabbedItem = null;
                    }

                    if (damager && damager.GetComponent <PlayerController>())
                    {
                        damager.GetComponent <PlayerController>().Kills++;

                        // if free for all show different scores, my kills and the kills of the top player
                        if (MultiplayerGameManager.Instance.GameMode == MultiplayerGameManager.GameModes.FreeForAll)
                        {
                            var playerListWithoutMe = new List <PlayerController>(MultiplayerGameManager.Instance.Players);
                            playerListWithoutMe.Remove(MultiplayerGameManager.Instance.LocalPlayer);

                            var playerList = playerListWithoutMe.OrderByDescending(player => player.Kills).ToList();
                            MultiplayerGameManager.Instance.Team2Score = playerList[0].Kills;
                            MultiplayerGameManager.Instance.UpdateTeamScoresUI();
                        }
                        if (damager && damager.GetComponent <AIPlayer>())
                        {
                            damager.GetComponent <AIPlayer>().fsm.ChangeState(AIPlayer.States.Search);
                        }


                        damager.GetComponent <PlayerController>().photonView.RPC("KilledSomebody", PhotonTargets.Others);
                    }
                    // KILL CAM
                    // activate my model for kill cam
                    playerController.Model.gameObject.SetActive(true);
                    GameManager.Instance.FadeWhenSight2D.SetActive(false);
                    if (playerController.CurrentWeapon && playerController.CurrentWeapon.Sight2D)
                    {
                        playerController.CurrentWeapon.Sight2D.DoFadeOutInmmediately();
                        playerController.CurrentWeapon.Sight2D.gameObject.SetActive(false);
                    }
                    // fade out damage indicator
                    gameManager.DamageIndicator.DoFadeOut();

                    playerController.rigidBody.isKinematic = true;

                    foreach (Transform child in playerController.Model.transform)
                    {
                        child.gameObject.SetActive(true);
                    }
                    playerController.RagdollDieCamera.gameObject.SetActive(true);
                    playerController.PCamera.gameObject.SetActive(false);
                    yield return(new WaitForSeconds(0.2f));

                    playerController.ModelAnimator.enabled = false;
                }
                else
                {
                    // THROW WEAPON (SO OTHER PEOPLE CAN TAKE MY WEAPON)
                    if (playerController.CurrentWeapon)
                    {
                        GameObject newWeaponClone = PhotonNetwork.Instantiate(playerController.CurrentWeapon.gameObject.name, playerController.CurrentWeapon.transform.position, playerController.CurrentWeapon.transform.rotation, 0);
                        Rigidbody  newWpRigidBody = newWeaponClone.GetComponent <Rigidbody>();

                        newWpRigidBody.isKinematic = false;


                        newWpRigidBody.GetComponent <Pickup>().enabled      = true;
                        newWpRigidBody.GetComponent <BoxCollider>().enabled = true;

                        newWpRigidBody.AddForce(new Vector3(1, 1) * 5f, ForceMode.Impulse);
                        newWpRigidBody.AddTorque(new Vector3(1, 1) * 5f, ForceMode.Impulse);
                        newWpRigidBody.GetComponent <Pickup>().TriggerPickup.enabled = true;
                        newWpRigidBody.GetComponent <Pickup>().PickupByTrigger       = true;

                        playerController.CurrentWeapon.gameObject.SetActive(false);
                        photonView.RPC("ThrowWeaponInOthers", PhotonTargets.Others, newWeaponClone.GetComponent <PhotonView>().viewID);
                    }

                    playerController.rigidBody.isKinematic = true;
                    yield return(new WaitForSeconds(0.01f));

                    playerController.ModelAnimator.enabled = false;
                }
            }
            else
            {
                AIPlayer aiPlayer = GetComponent <AIPlayer>();
                // THROW WEAPON IN AI (SO OTHER PEOPLE CAN TAKE MY WEAPON)

                if (aiPlayer.PlayerWeapon)
                {
                    GameObject newWeaponClone = PhotonNetwork.Instantiate(aiPlayer.PlayerWeapon.gameObject.name, aiPlayer.PlayerWeapon.transform.position, aiPlayer.PlayerWeapon.transform.rotation, 0);
                    Rigidbody  newWpRigidBody = newWeaponClone.GetComponent <Rigidbody>();

                    newWpRigidBody.isKinematic = false;
                    newWpRigidBody.GetComponent <BoxCollider>().enabled = true;
                    newWpRigidBody.AddForce(new Vector3(1, 1) * 5f, ForceMode.Impulse);
                    newWpRigidBody.AddTorque(new Vector3(1, 1) * 5f, ForceMode.Impulse);
                    newWpRigidBody.GetComponent <Pickup>().enabled = true;


                    newWpRigidBody.GetComponent <Pickup>().TriggerPickup.enabled = true;
                    newWpRigidBody.GetComponent <Pickup>().PickupByTrigger       = true;

                    aiPlayer.PlayerWeapon.gameObject.SetActive(false);
                }

                aiPlayer.rigidBody.isKinematic = true;
                aiPlayer.fsm.ChangeState(AIPlayer.States.Idle, AxlPlay.StateTransition.Overwrite);
                yield return(new WaitForSeconds(0.01f));

                aiPlayer.Model.enabled = false;
            }


            photonView.RPC("Respawn", PhotonTargets.All);
        }