Ejemplo n.º 1
0
 void remove_Photon_View_List_Player(PhotonView pv)
 {
     if (PlayerCharacterStatusHandler.Get_PVs().Contains(pv))
     {
         PlayerCharacterStatusHandler.Get_PVs().Remove(pv);
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Gets the closest photonview(character) within range.
    /// </summary>
    /// <returns>The closest within range.</returns>
    public PhotonView GetClosestPVWithinRange(float range, bool OnlyAlly = false)
    {
        PhotonView closestPV = _pv;

        foreach (PhotonView pv in PlayerCharacterStatusHandler.Get_PVs())
        {
            //skip my own character
            //or differnt team
            if (pv == _pv)
            {
                continue;
            }

            if (OnlyAlly && pv.GetComponent <CombatHandler> ().GetTeam() != _team)
            {
                continue;
            }

            if (Vector3.Distance(transform.position, pv.transform.position) < range)
            {
                if (closestPV == _pv)
                {
                    closestPV = pv;
                }
                else if (Vector3.Distance(transform.position, pv.transform.position) < Vector3.Distance(transform.position, closestPV.transform.position))
                {
                    closestPV = pv;
                }
            }
        }

        return(closestPV);
    }
Ejemplo n.º 3
0
    void updateTarget()
    {
        if (_target != null)
        {
            if (!_target.GetComponent <ObjectStatusHandler> ().Alive())
            {
                _target = null;
            }
        }

        //get lists of csh from player list
        _playerCSHs.Clear();
        foreach (var p in PlayerCharacterStatusHandler.Get_PVs())
        {
            PlayerCharacterStatusHandler psh = p.GetComponent <PlayerCharacterStatusHandler> ();
            if (psh != null)
            {
                _playerCSHs.Add(psh);
            }
        }

//		foreach (var p in AIController.AIC.GetPlayerList()) {
        foreach (var psh in _playerCSHs)
        {
//			if (transform == null)
//				print ("transform is null");
            if (psh == null)
            {
                continue;
            }

            if (_target == null)
            {
                _target = psh.transform;
            }
            else
            {
                if (Vector3.Distance(_target.position, transform.position) > Vector3.Distance(psh.transform.position, transform.position))
                {
                    _target = psh.transform;
                }
            }
        }
    }
Ejemplo n.º 4
0
    void updatePlayersText()
    {
        _text.text = "";
        if (GameController.GC.CurrentPlayerCharacter != null)
        {
//			foreach (var po in GameObject.FindGameObjectsWithTag(TagHelper.PLAYER)) {
//				if(po != null && po.GetComponent<PhotonView>() != null && po.GetComponent<PhotonView>().owner != null && po.GetComponent<PhotonView>().owner.name != null)
//					_text.text += po.GetComponent<PhotonView> ().owner.name	 + "\n";
//			}
            foreach (var p in PlayerCharacterStatusHandler.Get_PVs())
            {
                if (_text == null || _text.text == null)
                {
                    return;
                }
                _text.text += p.owner.name + "\n";
            }
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Called when a remote player left the room. This PhotonPlayer is already removed from the playerlist at this time.
    /// </summary>
    /// <remarks>When your client calls PhotonNetwork.leaveRoom, PUN will call this method on the remaining clients.
    /// When a remote client drops connection or gets closed, this callback gets executed. after a timeout
    /// of several seconds.</remarks>
    /// <param name="player">Player.</param>
    public override void OnPhotonPlayerDisconnected(PhotonPlayer player)
    {
        base.OnPhotonPlayerDisconnected(player);
        Debug.Log("Player Disconnected " + player.name + ", PlayerCharacterList : " + PlayerCharacterStatusHandler.Get_PVs().Count);
        //Destroy player character when leaving a room
        List <PhotonView> pvlist = new List <PhotonView> ();

        foreach (var pv in PlayerCharacterStatusHandler.Get_PVs())
        {
            //seems like owner is null when the player is disconnected
            //or transfered ownership to sceneview
            //or still has old owner info
            if (pv.owner == null || pv.isSceneView || pv.owner == player)
            {
                pvlist.Add(pv);
//				print ("Owner found, deleting owener objects");
            }
//			//dev
//			print("owner id : " + pv.ownerId +", owner name : " + pv.owner.name + ", disconnected player id : " + player.ID);
        }

        //new master takes control of destroying disconnect player character
        if (PhotonNetwork.isMasterClient)
        {
            foreach (var pp in pvlist)
            {
                if (pp.GetComponent <PlayerCombatHandler> () != null)
                {
                    RoomLevelHelper.SetRoomCustomPropertyPlayerClass(pp.GetComponent <PlayerCombatHandler> ().GetClass(), true, pp.GetComponent <PlayerCombatHandler> ().GetTeam());
                }
                PhotonNetwork.Destroy(pp);
                PhotonNetwork.RemoveRPCs(pp);
//				_photonView.RPC ("RPC_Remove_Photon_View_List_Player", PhotonTargets.All, pp.viewID);
                Remove_Photon_View_List_Player(pp);
            }
        }
    }
Ejemplo n.º 6
0
    protected override void checkForCoopInteraction()
    {
        base.checkForCoopInteraction();

        bool       interactableFound = false;
        PhotonView closestPV         = _pv;

        //set search start position which depends on camera direction
        Vector3 searchPos = CameraController.CC.CombatCamera.transform.position + CameraController.CC.CombatCamera.transform.forward * _searchPosOffset;

        foreach (PhotonView pv in PlayerCharacterStatusHandler.Get_PVs())
        {
            //skip my own character
            //or differnt team
            if (pv == _pv ||
                pv.GetComponent <CombatHandler> ().GetTeam() != _team)
            {
                continue;
            }

            //			if (pv.GetComponent<PlayerCombatHandler> () == null)
            //				continue;

            if (Vector3.Distance(searchPos, pv.transform.position) < _interactionDisatance)
            {
                interactableFound = true;
                if (closestPV == _pv)
                {
                    closestPV = pv;
                }
                else if (Vector3.Distance(searchPos, pv.transform.position) < Vector3.Distance(searchPos, closestPV.transform.position))
                {
                    closestPV = pv;
                }
//				print ("Found");
            }
        }

        if (interactableFound)
        {
            //			found, setup UI
//			if (closestPV.GetComponent<PlayerCombatHandler> ().GetCoopStatus () == PLAYER_COOP_STATUS.TANK_BLOCKING && RoomLevelHelper.PLAYER_CLASS == CHARACTER_CLASS.WARRIOR) {
            if (UIController.SINGLETON.PlayerUIInteractInstance.Target == null || UIController.SINGLETON.PlayerUIInteractInstance.Target != closestPV.transform)
            {
                UIController.SINGLETON.PlayerUIInteractInstance.SetEnabled(true);
                UIController.SINGLETON.PlayerUIInteractInstance.SetTarget(closestPV.transform);
                //										print ("Set target : " + closestPV.transform.name);
                foreach (var a in _abilities)
                {
                    if (a is AbilityCoopCharge)
                    {
                        if (a.GetStatus() != ABILITY_STATUS.IN_COOLDOWN)
                        {
                            AbilityCoopCharge acc = (AbilityCoopCharge)a;
                            acc.SetTarget(closestPV.transform);
                            acc.SetStatus(ABILITY_STATUS.AVAILABLE);
                        }
                    }
                }
            }
        }
        else
        {
            if (UIController.SINGLETON == null)
            {
                return;
            }

            //no interaction found, hide UI
            UIController.SINGLETON.PlayerUIInteractInstance.SetEnabled(false);
            UIController.SINGLETON.PlayerUIInteractInstance.SetTarget(null);

            //no jump is available
            foreach (var a in _abilities)
            {
                if (a is AbilityCoopJump)
                {
                    a.SetStatus(ABILITY_STATUS.UNAVAILABLE);
                }
            }
        }
    }
Ejemplo n.º 7
0
    public void SpawnPlayer()
    {
        Transform spawnArea = _spawnAreaWarrior;
        //spawn player character and set it to the GameController
        GameObject playerInstance = null;

        switch (RoomLevelHelper.PLAYER_CLASS)
        {
        case CHARACTER_CLASS.WARRIOR:
            playerInstance = PhotonNetwork.Instantiate("Warrior", new Vector3(0f, 5f, 0f), Quaternion.identity, 0);
            spawnArea      = _spawnAreaWarrior;
            break;

        case CHARACTER_CLASS.TANK:
            playerInstance = PhotonNetwork.Instantiate("Tank", new Vector3(0f, 5f, 0f), Quaternion.identity, 0);
            spawnArea      = _spawnAreaTank;
            break;

        case CHARACTER_CLASS.ARCHER:
            playerInstance = PhotonNetwork.Instantiate("Archer", new Vector3(0f, 5f, 0f), Quaternion.identity, 0);
            spawnArea      = _spawnAreaArcher;
            break;

        default:
            Debug.LogWarning("WARNING : Character not specified set when spawning");
            break;
        }
        if (playerInstance == null)
        {
            Debug.LogWarning("WARNING : Character not instantiated, aborting");
            return;
        }
        GameController.GC.CurrentPlayerCharacter = playerInstance.transform;
        //set and enable camera
        CameraController.CC.InitializeCamera();

        //if this is a revive
        playerInstance.transform.rotation = spawnArea.rotation;
        if (GameController.GC.DeathCount > 0)
        {
            if (PlayerCharacterStatusHandler.Get_PVs(true).Count > 0)
            {
                //there are alive chr to respawn to(not tested)
                int     rnd = Random.Range(0, PlayerCharacterStatusHandler.Get_PVs(true).Count);
                Vector3?pos = getNearAlivePlayerPos(PlayerCharacterStatusHandler.Get_PVs(true) [rnd].GetComponent <AIMovementHandler> ());
                if (pos != null)
                {
                    spawnArea.position = (Vector3)pos;
                }
                else
                {
                    spawnArea.position = _respawnArea.position;
                }
            }
            else
            {
                //respawn but no chr to respawn to
                spawnArea.position = _respawnArea.position;
            }
        }
        else
        {
            //spawn to original position if this is spawning for the first time when the game starts
            if ((PlayerCharacterStatusHandler.Get_PVs(true).Count > 0))
            {
                //there are alive chr to respawn to
                int     rnd = Random.Range(0, PlayerCharacterStatusHandler.Get_PVs(true).Count);
                Vector3?pos = getNearAlivePlayerPos(PlayerCharacterStatusHandler.Get_PVs(true) [rnd].GetComponent <AIMovementHandler> ());
                if (pos != null)
                {
                    spawnArea.position = (Vector3)pos;
                }
            }
        }
        playerInstance.transform.position = spawnArea.position;

        //		dev
        //		GameController.GC.SetIsControlAllowed (false);
        GameController.GC.SetIsControlAllowed(true);
    }