Ejemplo n.º 1
0
        private void SendPlayerShot(int playerId, Vector3 hitPoint, Vector3 hitDirection)
        {
            MultiplayerManager mInstance = MultiplayerManager.instance;

            int playerID = GetComponent <Player>().m_playerId;

            MessagePlayerShotBullet message = new MessagePlayerShotBullet();

            message.playerId     = playerID;
            message.hitPosition  = hitPoint;
            message.hitDirection = hitDirection;

            if (mInstance.m_isServer)
            {
                List <NetConnection> sendTo = mInstance.m_server.Connections;

                if (sendTo.Count > 0)
                {
                    NetOutgoingMessage om = mInstance.m_server.CreateMessage();
                    om.Write((int)MessageFunction.PlayerShotBullet);
                    om.WriteAllFields(message);

                    mInstance.m_server.SendToAll(om, NetDeliveryMethod.ReliableOrdered);
                }
            }
            else
            {
                NetOutgoingMessage om = mInstance.m_client.CreateMessage();
                om.Write((int)MessageFunction.PlayerShotBullet);
                om.WriteAllFields(message);

                mInstance.m_client.SendMessage(om, NetDeliveryMethod.ReliableOrdered);
            }
        }
Ejemplo n.º 2
0
        public override void OnCalled(Message msg, NetIncomingMessage netMsg = null)
        {
            MessagePlayerShotBullet message = msg as MessagePlayerShotBullet;

            BulletHitParticlePrefab.Create(message.hitPosition, message.hitDirection);

            if (message.hitPlayerId != 0)
            {
                var playerHit = MultiplayerManager.instance.m_players.FirstOrDefault(x => x.ID == message.hitPlayerId);
                if (playerHit != null)
                {
                    playerHit.PlayerGameObject.GetComponent <Player>().OnDamageTaken(playerId, damage);
                }
            }
        }
Ejemplo n.º 3
0
        void Update()
        {
            m_lastJumpTimer += Time.deltaTime;

            if (PlayerInput.FireKey.GetKeyDown())
            {
                //SoundManager.PlayClipAtPoint("WeaponShot", transform.position, 0.5f);

                RayHitInfo hitInfo = RaycastHelper.Raycast(Camera.main.transform.position, Camera.main.transform.position + Camera.main.transform.forward * 300);

                if (hitInfo.rayHit)
                {
                    int hitPlayerId = 0;
                    if (hitInfo.hitType == RayFlags.Player)
                    {
                        hitPlayerId = hitInfo.raycastHit.collider.GetComponent <Player>().m_playerId;
                    }

                    MessagePlayerShotBullet message = new MessagePlayerShotBullet();
                    message.playerId     = gameObject.GetComponent <Player>().m_playerId;
                    message.hitPlayerId  = hitPlayerId;
                    message.damage       = 10;
                    message.hitPosition  = hitInfo.point;
                    message.hitDirection = (transform.position - hitInfo.point);
                    MultiplayerManager.instance.SendNetworkMessage(message, SendTo.All);
                }
            }

            m_hookCooldown -= Time.deltaTime;
            m_hookCooldown  = Math.Max(0, m_hookCooldown);

            if (PlayerInput.SecFireKey.GetKeyDown() && m_hookCooldown <= 0)
            {
                Vector3 startPointShot = Camera.main.transform.position;
                Vector3 endPointShot   = Camera.main.transform.position + Camera.main.transform.forward * 100;

                m_rayCastInfo = RaycastHelper.Raycast(startPointShot, endPointShot);

                m_hookHitPosition = m_rayCastInfo.point;

                if (m_rayCastInfo.rayHit)
                {
                    m_hookCooldown = HOOK_COOLDOWN;
                    m_hookHit      = true;

                    m_hookLineRender.SetPosition(0, transform.position);
                    m_hookLineRender.SetPosition(1, m_hookHitPosition);
                    m_hookLineRender.enabled = true;

                    SendPlayerHookUsed(m_hookHitPosition);
                }
            }

            if (PlayerInput.SecFireKey.GetKey() && m_hookHit)
            {
                if (m_rayCastInfo.hitType == RayFlags.Citizen && m_rayCastInfo.index != 0)
                {
                    var cInstance = Singleton <CitizenManager> .instance;

                    var citizenInstace = cInstance.m_instances.m_buffer[m_rayCastInfo.index];
                    var citizenInfo    = citizenInstace.Info;

                    Vector3    citizenPosition;
                    Quaternion citizenRotation;
                    citizenInstace.GetSmoothPosition((ushort)m_rayCastInfo.index, out citizenPosition, out citizenRotation);

                    m_hookHitPosition = citizenPosition;
                    m_hookLineRender.SetPosition(1, m_hookHitPosition);
                    SendPlayerHookUsed(m_hookHitPosition);
                }
                else
                {
                    if (m_rayCastInfo.hitType == RayFlags.Vehicle && m_rayCastInfo.index != 0)
                    {
                        var vInstance = Singleton <VehicleManager> .instance;

                        var citizenInstace = vInstance.m_vehicles.m_buffer[m_rayCastInfo.index];
                        var citizenInfo    = citizenInstace.Info;

                        Vector3    citizenPosition;
                        Quaternion citizenRotation;
                        citizenInstace.GetSmoothPosition((ushort)m_rayCastInfo.index, out citizenPosition, out citizenRotation);

                        m_hookHitPosition = citizenPosition;
                        m_hookLineRender.SetPosition(1, m_hookHitPosition);
                        SendPlayerHookUsed(m_hookHitPosition);
                    }
                }

                m_hookLineRender.SetPosition(0, transform.position);

                Vector3 dir = (m_hookHitPosition - transform.position).normalized;

                float hookForce = Math.Min(Vector3.Distance(transform.position, m_hookHitPosition) * 15, HOOK_FORCE);

                m_velocity           = dir * hookForce;
                m_rigidBody.velocity = m_velocity;
            }

            if (PlayerInput.SecFireKey.GetKeyUp() && m_hookHit)
            {
                OnHookReleased();
            }
        }
Ejemplo n.º 4
0
        void Update()
        {
            m_lastJumpTimer += Time.deltaTime;

            if (PlayerInput.FireKey.GetKeyDown())
            {
                //SoundManager.PlayClipAtPoint("WeaponShot", transform.position, 0.5f);

                RayHitInfo hitInfo = RaycastHelper.Raycast(Camera.main.transform.position, Camera.main.transform.position + Camera.main.transform.forward * 300);

                if (hitInfo.rayHit)
                {
                    int hitPlayerId = 0;
                    if (hitInfo.hitType == RayFlags.Player)
                    {
                        hitPlayerId = hitInfo.raycastHit.collider.GetComponent<Player>().m_playerId;
                    }

                    MessagePlayerShotBullet message = new MessagePlayerShotBullet();
                    message.playerId = gameObject.GetComponent<Player>().m_playerId;
                    message.hitPlayerId = hitPlayerId;
                    message.damage = 10;
                    message.hitPosition = hitInfo.point;
                    message.hitDirection = (transform.position - hitInfo.point);
                    MultiplayerManager.instance.SendNetworkMessage(message, SendTo.All);
                }
            }

            m_hookCooldown -= Time.deltaTime;
            m_hookCooldown = Math.Max(0, m_hookCooldown);

            if (PlayerInput.SecFireKey.GetKeyDown() && m_hookCooldown <= 0)
            {
                Vector3 startPointShot = Camera.main.transform.position;
                Vector3 endPointShot = Camera.main.transform.position + Camera.main.transform.forward * 100;

                m_rayCastInfo = RaycastHelper.Raycast(startPointShot, endPointShot);

                m_hookHitPosition = m_rayCastInfo.point;

                if (m_rayCastInfo.rayHit)
                {
                    m_hookCooldown = HOOK_COOLDOWN;
                    m_hookHit = true;

                    m_hookLineRender.SetPosition(0, transform.position);
                    m_hookLineRender.SetPosition(1, m_hookHitPosition);
                    m_hookLineRender.enabled = true;

                    SendPlayerHookUsed(m_hookHitPosition);
                }
            }

            if (PlayerInput.SecFireKey.GetKey() && m_hookHit)
            {
                if (m_rayCastInfo.hitType == RayFlags.Citizen && m_rayCastInfo.index != 0)
                {
                    var cInstance = Singleton<CitizenManager>.instance;

                    var citizenInstace = cInstance.m_instances.m_buffer[m_rayCastInfo.index];
                    var citizenInfo = citizenInstace.Info;

                    Vector3 citizenPosition;
                    Quaternion citizenRotation;
                    citizenInstace.GetSmoothPosition((ushort)m_rayCastInfo.index, out citizenPosition, out citizenRotation);

                    m_hookHitPosition = citizenPosition;
                    m_hookLineRender.SetPosition(1, m_hookHitPosition);
                    SendPlayerHookUsed(m_hookHitPosition);
                }
                else
                {

                    if (m_rayCastInfo.hitType == RayFlags.Vehicle && m_rayCastInfo.index != 0)
                    {
                        var vInstance = Singleton<VehicleManager>.instance;

                        var citizenInstace = vInstance.m_vehicles.m_buffer[m_rayCastInfo.index];
                        var citizenInfo = citizenInstace.Info;

                        Vector3 citizenPosition;
                        Quaternion citizenRotation;
                        citizenInstace.GetSmoothPosition((ushort)m_rayCastInfo.index, out citizenPosition, out citizenRotation);

                        m_hookHitPosition = citizenPosition;
                        m_hookLineRender.SetPosition(1, m_hookHitPosition);
                        SendPlayerHookUsed(m_hookHitPosition);
                    }
                }

                m_hookLineRender.SetPosition(0, transform.position);

                Vector3 dir = (m_hookHitPosition - transform.position).normalized;

                float hookForce = Math.Min(Vector3.Distance(transform.position, m_hookHitPosition) * 15, HOOK_FORCE);

                m_velocity = dir * hookForce;
                m_rigidBody.velocity = m_velocity;
            }

            if (PlayerInput.SecFireKey.GetKeyUp() && m_hookHit)
            {
                OnHookReleased();
            }
        }
Ejemplo n.º 5
0
        private void SendPlayerShot(int playerId, Vector3 hitPoint, Vector3 hitDirection)
        {
            MultiplayerManager mInstance = MultiplayerManager.instance;

            int playerID = GetComponent<Player>().m_playerId;

            MessagePlayerShotBullet message = new MessagePlayerShotBullet();
            message.playerId = playerID;
            message.hitPosition = hitPoint;
            message.hitDirection = hitDirection;

            if (mInstance.m_isServer)
            {
                List<NetConnection> sendTo = mInstance.m_server.Connections;

                if (sendTo.Count > 0)
                {
                    NetOutgoingMessage om = mInstance.m_server.CreateMessage();
                    om.Write((int)MessageFunction.PlayerShotBullet);
                    om.WriteAllFields(message);

                    mInstance.m_server.SendToAll(om, NetDeliveryMethod.ReliableOrdered);
                }
            }
            else
            {
                NetOutgoingMessage om = mInstance.m_client.CreateMessage();
                om.Write((int)MessageFunction.PlayerShotBullet);
                om.WriteAllFields(message);

                mInstance.m_client.SendMessage(om, NetDeliveryMethod.ReliableOrdered);
            }
        }