Beispiel #1
0
    public void Shot()
    {
        Debug.Log("PLAYER GOT SHOT");
        RespawnMsg respawnMsg = new RespawnMsg();

        respawnMsg.to  = this.id;
        respawnMsg.pos = gameManager.GetRespawnPoint();
        networkManager.Send(respawnMsg.GetBytes(), this.id);
    }
 static void OnRespawnRequestFailure(ref RespawnMsg msg, MyNetworkClient sender)
 {
     MyPlayerCollection.RequestLocalRespawn();
 }
        static void OnRespawnRequest(ref RespawnMsg msg, MyNetworkClient sender)
        {
            Debug.Assert(Sync.Players.RespawnComponent != null, "The respawn component is not set! Cannot handle respawn request!");
            if (Sync.Players.RespawnComponent == null)
            {
                return;
            }

            bool respawnSuccessful = Sync.Players.RespawnComponent.HandleRespawnRequest(
                msg.JoinGame,
                msg.NewIdentity,
                msg.MedicalRoom,
                msg.RespawnShipId,
                new PlayerId(sender.SteamUserId, msg.PlayerSerialId),
                msg.SpawnPosition
            );

            if (!respawnSuccessful)
            {
                MySession.Static.SyncLayer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Failure);
            }
        }
        public static void RespawnRequest(bool joinGame, bool newPlayer, long medicalId, string shipPrefabId, int playerSerialId = 0, Vector3D? spawnPosition = null)
        {
            var msg = new RespawnMsg();
            msg.JoinGame = joinGame;
            msg.MedicalRoom = medicalId;
            msg.NewIdentity = newPlayer;
            msg.RespawnShipId = shipPrefabId;
            msg.PlayerSerialId = playerSerialId;
            msg.SpawnPosition = spawnPosition;

            MySession.Static.SyncLayer.SendMessageToServer(ref msg, Engine.Multiplayer.MyTransportMessageEnum.Request);
        }
 static void OnRespawnRequestFailure(RespawnMsg msg)
 {
     if (msg.PlayerSerialId == 0)
     {
         MyPlayerCollection.RequestLocalRespawn();
     }
 }
        static void OnRespawnRequest(RespawnMsg msg)
        {
            EndpointId sender;
            if (MyEventContext.Current.IsLocallyInvoked)
                sender = new EndpointId(Sync.MyId);
            else
                sender = MyEventContext.Current.Sender;

            Debug.Assert(Sync.IsServer, "This method can only be called on the server!");
            Debug.Assert(Sync.Players.RespawnComponent != null, "The respawn component is not set! Cannot handle respawn request!");
            if (Sync.Players.RespawnComponent == null)
            {
                return;
            }

            PlayerId playerId = new PlayerId(sender.Value, msg.PlayerSerialId);

            bool respawnSuccessful = Sync.Players.RespawnComponent.HandleRespawnRequest(
                msg.JoinGame,
                msg.NewIdentity,
                msg.RespawnEntityId,
                msg.RespawnShipId,
                playerId,
                msg.SpawnPosition,
                msg.BotDefinitionId
            );

            if (respawnSuccessful)
            {
                MyIdentity identity = Sync.Players.TryGetPlayerIdentity(playerId);
                Debug.Assert(identity != null, "Could not find identity of respawning player!");
                if (identity != null && !identity.FirstSpawnDone)
                {
                    MyMultiplayer.RaiseStaticEvent(s => MyPlayerCollection.OnIdentityFirstSpawn, identity.IdentityId);
                    identity.PerformFirstSpawn();
                }
            }
            else
            {
                if (MyEventContext.Current.IsLocallyInvoked)
                    OnRespawnRequestFailure(msg);
                else
                    MyMultiplayer.RaiseStaticEvent(s => MyPlayerCollection.OnRespawnRequestFailure, msg, sender);
            }
        }
        public static void RespawnRequest(bool joinGame, bool newIdentity, long respawnEntityId, string shipPrefabId, int playerSerialId = 0, Vector3D? spawnPosition = null, VRage.ObjectBuilders.SerializableDefinitionId? botDefinitionId = null)
        {
            var msg = new RespawnMsg();
            msg.JoinGame = joinGame;
            msg.RespawnEntityId = respawnEntityId;
            msg.NewIdentity = newIdentity;
            msg.RespawnShipId = shipPrefabId;
            msg.PlayerSerialId = playerSerialId;
            msg.SpawnPosition = spawnPosition;
            msg.BotDefinitionId = botDefinitionId;

            MyMultiplayer.RaiseStaticEvent(s => MyPlayerCollection.OnRespawnRequest, msg);
        }
        static void OnRespawnRequest(ref RespawnMsg msg, MyNetworkClient sender)
        {
            Debug.Assert(Sync.IsServer, "This method can only be called on the server!");
            Debug.Assert(Sync.Players.RespawnComponent != null, "The respawn component is not set! Cannot handle respawn request!");
            if (Sync.Players.RespawnComponent == null)
            {
                return;
            }

            PlayerId playerId = new PlayerId(sender.SteamUserId, msg.PlayerSerialId);

            bool respawnSuccessful = Sync.Players.RespawnComponent.HandleRespawnRequest(
                msg.JoinGame,
                msg.NewIdentity,
                msg.RespawnEntityId,
                msg.RespawnShipId,
                playerId,
                msg.SpawnPosition,
                msg.BotDefinitionId
            );

            if (respawnSuccessful)
            {
                MyIdentity identity = Sync.Players.TryGetPlayerIdentity(playerId);
                Debug.Assert(identity != null, "Could not find identity of respawning player!");
                if (identity != null && !identity.FirstSpawnDone)
                {
                    var identitySpawnedMsg = new IdentityFirstSpawnMsg() { IdentityId = identity.IdentityId };
                    MySession.Static.SyncLayer.SendMessageToAll(ref identitySpawnedMsg, MyTransportMessageEnum.Success);
                    identity.PerformFirstSpawn();
                }
            }
            else
            {
                MySession.Static.SyncLayer.SendMessage(ref msg, sender.SteamUserId, MyTransportMessageEnum.Failure);
            }
        }
        public static void RespawnRequest(bool joinGame, bool newPlayer, long respawnEntityId, string shipPrefabId, int playerSerialId = 0, Vector3D? spawnPosition = null, VRage.ObjectBuilders.SerializableDefinitionId? botDefinitionId = null)
        {
            var msg = new RespawnMsg();
            msg.JoinGame = joinGame;
            msg.RespawnEntityId = respawnEntityId;
            msg.NewIdentity = newPlayer;
            msg.RespawnShipId = shipPrefabId;
            msg.PlayerSerialId = playerSerialId;
            msg.SpawnPosition = spawnPosition;
            msg.BotDefinitionId = botDefinitionId;

            MySession.Static.SyncLayer.SendMessageToServer(ref msg, Engine.Multiplayer.MyTransportMessageEnum.Request);
        }