Esempio n. 1
0
        public void RespawnPlayer(PlayerClient player)
        {
            lock (sync) {
                if (player.State != PlayerState.HasLevelLoaded && player.State != PlayerState.Dead)
                {
                    return;
                }

                Vector3 pos = new Vector3(levelHandler.EventMap.GetSpawnPositionForMultiplayer(), LevelHandler.PlayerZ);

                if (player.ProxyActor == null)
                {
                    player.ProxyActor       = new Player();
                    player.ProxyActor.Index = player.Index;
                    player.ProxyActor.OnActivated(new ActorActivationDetails {
                        LevelHandler = levelHandler,
                        Pos          = pos,
                        Params       = new[] { (ushort)player.PlayerType, (ushort)0 }
                    });
                    levelHandler.AddPlayer(player.ProxyActor);
                }
                else
                {
                    if (player.ProxyActor.Health > 0)
                    {
                        player.ProxyActor.Transform.Pos = pos;
                    }
                    else
                    {
                        player.ProxyActor.Respawn(pos.Xy);
                    }
                }

                player.State = PlayerState.Spawned;

                Send(new CreateControllablePlayer {
                    Index        = player.Index,
                    Type         = player.PlayerType,
                    Pos          = pos,
                    Health       = playerHealth,
                    Controllable = (serverState == ServerState.LevelRunning)
                }, 11, player.Connection, NetDeliveryMethod.ReliableOrdered, PacketChannels.Main);
            }

#if DEBUG
            Log.Write(LogType.Verbose, "Respawning player #" + player.Index);
#endif
        }