Esempio n. 1
0
    void PlayerDie(ServerPlayerDieMsg serverPlayerDieMsg)
    {
        int playerID = serverPlayerDieMsg.playerID;

        if (playerID == GameSettings.playerID)
        {
            PlayerHealth playerHealth = player.GetComponent <PlayerHealth>();
            playerHealth.currentHealth = 0;
            playerHealth.Death();
            GameSettings.gameOver = true;
        }
        // other player die
        else
        {
            GameObject otherDiePlayer = FindOtherPlayerWithID(playerID);
            if (otherDiePlayer != null)
            {
                OtherPlayerControl otherPlayerControl = otherDiePlayer.GetComponent <OtherPlayerControl>();
                otherPlayerControl.otherPlayerHealth = 0;
                otherPlayerControl.Die();
            }

            DeleteServerGameobjects(GameSettings.OTHER_PLAYER_TYPE, playerID);
        }
    }
Esempio n. 2
0
    void CreateOtherPlayer(ServerOtherPlayerMsg serverOtherPlayerCreateMsg)
    {
        int playerID     = serverOtherPlayerCreateMsg.playerID;
        int playerHealth = serverOtherPlayerCreateMsg.playerHealth;

        Vector3 otherPlayerPosition = new Vector3
        {
            x = serverOtherPlayerCreateMsg.location.x,
            y = serverOtherPlayerCreateMsg.location.y,
            z = serverOtherPlayerCreateMsg.location.z
        };

        Quaternion otherPlayerRotation = Quaternion.Euler(
            serverOtherPlayerCreateMsg.rotation.x,
            serverOtherPlayerCreateMsg.rotation.y,
            serverOtherPlayerCreateMsg.rotation.z
            );


        GameObject newOtherPlayer = null;

        newOtherPlayer = Instantiate(OtherPlayer, otherPlayerPosition, otherPlayerRotation);

        OtherPlayerControl otherPlayerControl = newOtherPlayer.GetComponent <OtherPlayerControl>();

        otherPlayerControl.otherPlayerID     = playerID;
        otherPlayerControl.otherPlayerHealth = playerHealth;

        AddServerGameObjects(GameSettings.OTHER_PLAYER_TYPE, playerID, newOtherPlayer);
    }
Esempio n. 3
0
    void CreateOtherPlayersByList(List <PlayerEntity> otherPlayerEntities)
    {
        foreach (PlayerEntity otherPlayerEntity in otherPlayerEntities)
        {
            int playerID     = otherPlayerEntity.entityID;
            int playerHealth = otherPlayerEntity.playerHealth;

            Vector3 otherPlayerPosition = new Vector3
            {
                x = otherPlayerEntity.location.x,
                y = otherPlayerEntity.location.y,
                z = otherPlayerEntity.location.z
            };

            Quaternion otherPlayerRotation = Quaternion.Euler(
                otherPlayerEntity.rotation.x,
                otherPlayerEntity.rotation.y,
                otherPlayerEntity.rotation.z
                );


            GameObject newOtherPlayer = null;

            newOtherPlayer = Instantiate(OtherPlayer, otherPlayerPosition, otherPlayerRotation);

            OtherPlayerControl otherPlayerControl = newOtherPlayer.GetComponent <OtherPlayerControl>();
            otherPlayerControl.otherPlayerID     = playerID;
            otherPlayerControl.otherPlayerHealth = playerHealth;

            AddServerGameObjects(GameSettings.OTHER_PLAYER_TYPE, playerID, newOtherPlayer);
        }
    }
Esempio n. 4
0
    GameObject FindOtherPlayerWithID(int entityID)
    {
        if (serverGameObjects[GameSettings.OTHER_PLAYER_TYPE].ContainsKey(entityID))
        {
            return(serverGameObjects[GameSettings.OTHER_PLAYER_TYPE][entityID]);
        }

        GameObject[] otherPlayers = GameObject.FindGameObjectsWithTag("OtherPlayer");
        for (int i = 0; i < otherPlayers.Length; i++)
        {
            OtherPlayerControl otherPlayerControl = otherPlayers[i].GetComponent <OtherPlayerControl>();
            if (otherPlayerControl != null && otherPlayerControl.otherPlayerID == entityID)
            {
                return(otherPlayers[i]);
            }
        }
        return(null);
    }
Esempio n. 5
0
    void SyncOtherPlayer(ServerOtherPlayerMsg serverSyncOtherPlayerMsg)
    {
        int entityID     = serverSyncOtherPlayerMsg.playerID;
        int playerHealth = serverSyncOtherPlayerMsg.playerHealth;

        Vector3 otherPlayerPosition = new Vector3
        {
            x = serverSyncOtherPlayerMsg.location.x,
            y = serverSyncOtherPlayerMsg.location.y,
            z = serverSyncOtherPlayerMsg.location.z
        };

        Quaternion otherPlayerRotation = Quaternion.Euler(
            serverSyncOtherPlayerMsg.rotation.x,
            serverSyncOtherPlayerMsg.rotation.y,
            serverSyncOtherPlayerMsg.rotation.z
            );

        GameObject targetPlayer = FindOtherPlayerWithID(entityID);

        if (targetPlayer != null)
        {
            OtherPlayerControl otherPlayerControl = targetPlayer.GetComponent <OtherPlayerControl>();

            otherPlayerControl.SetWalking(Location.IsDifference(targetPlayer.transform.position, otherPlayerPosition));

            //targetPlayer.transform.position = otherPlayerPosition;
            targetPlayer.transform.rotation = otherPlayerRotation;

            UpdateServerGameObjectsMovement(
                GameSettings.OTHER_PLAYER_TYPE,
                entityID,
                otherPlayerPosition - targetPlayer.transform.position
                );

            if (playerHealth < otherPlayerControl.otherPlayerHealth)
            {
                otherPlayerControl.otherPlayerHurtAduio.Play();
                otherPlayerControl.otherPlayerHealth = playerHealth;
            }
        }
    }
Esempio n. 6
0
    void SyncOtherPlayerShoot(ServerOtherPlayerShootMsg otherPlayerShootMsg)
    {
        int entityID = otherPlayerShootMsg.playerID;

        Vector3 shootPoint = new Vector3
        {
            x = otherPlayerShootMsg.shootPoint.x,
            y = otherPlayerShootMsg.shootPoint.y,
            z = otherPlayerShootMsg.shootPoint.z
        };

        GameObject targetPlayer = FindOtherPlayerWithID(entityID);

        if (targetPlayer != null)
        {
            OtherPlayerControl otherPlayerControl = targetPlayer.GetComponent <OtherPlayerControl>();

            otherPlayerControl.Shoot(shootPoint);
        }
    }