Esempio n. 1
0
        void ObjectComponent_OnCreatableDestroyed(object sender, NetCreatableInfo creatable)
        {
            ClientPlayer player = creatable.Creatable as ClientPlayer;

            if (player != null)
            {
                // If a player was destroyed we need to remove
                // anything associated with them.
                players.Remove(creatable.Id);
                player.Dispose();

                if (player == OurPlayer)
                {
                    // Notify the player
                    OurPlayer.OnKilled();

                    // Remove the player
                    OurPlayer = null;
                }
            }
            else
            {
                GameObject gameObject = creatable.Creatable as GameObject;
                if (gameObject.HasComponent <PhysicsBodyComponent>())
                {
                    physEntities.Remove(creatable.Id);
                }

                gameObject.Dispose();
            }
        }
Esempio n. 2
0
        public void OnCreatableDestroyed(NetCreatableInfo info, WorldSnapshot ws)
        {
            ClientPlayer player;

            if (players.TryGetValue(info.Id, out player))
            {
                players.Remove(info.Id);

                if (ws != null)
                {
                    ws.RemovePlayer(player);
                }

                if (ourPlayer != null && ourPlayer.StateInfo.Id == info.Id)
                {
                    ourPlayer = null;
                }
            }
        }
Esempio n. 3
0
        public void OnCreatableInstantiated(NetCreatableInfo info, WorldSnapshot ws)
        {
            ClientPlayer player = info.Creatable as ClientPlayer;

            // Add the new player
            if (player != null)
            {
                players.Add(info.Id, player);

                if (info.IsAppOwner)
                {
                    // Setup player as our own
                    if (ourPlayer != null)
                    {
                        DashCMD.WriteError("[CSS] Received client player instantiation twice!");
                    }
                    else
                    {
                        // Setup our gamestate
                        // Copy each existing player to the worldsnapshot
                        foreach (ClientPlayer plr in players.Values)
                        {
                            if (plr == player)
                            {
                                // The new player doesn't have stateinfo setup yet
                                ws.AddPlayer(info.Id, true, false);
                            }
                            else if (!ws.PlayerFieldExists(plr.StateInfo.Id))
                            {
                                ws.AddPlayer(plr.StateInfo.Id, false, false);
                            }
                        }

                        // Set our player and our new world snapshot
                        ourPlayer = (ClientMPPlayer)player;
                    }
                }
                else
                {
                    ws.AddPlayer(info.Id, false, false);
                }
            }
        }
        void ToggleFPSUserInput(bool enabled, ClientMPPlayer ourPlayer)
        {
            if (ourPlayer != null)
            {
                ourPlayer.AllowUserInput   = enabled;
                Input.IsCursorLocked       = enabled;
                Input.IsCursorVisible      = !enabled;
                Camera.Active.HoldM2ToLook = !enabled;
                Camera.Active.SmoothCamera = !enabled;
            }
            else
            {
                // We only want to lock the cursor if we actually
                // have a player.
                Input.IsCursorLocked       = false;
                Input.IsCursorVisible      = true;
                Camera.Active.HoldM2ToLook = true;
                Camera.Active.SmoothCamera = true;
            }

            Camera.Active.AllowUserControl = enabled;
        }
        INetCreatable I_CreatePlayer(ushort id, bool isAppOwner, NetBuffer data)
        {
            // Read the packet
            float x    = data.ReadFloat();
            float y    = data.ReadFloat();
            float z    = data.ReadFloat();
            Team  team = (Team)data.ReadByte();

            ClientPlayer player;

            if (isAppOwner)
            {
                // It's our player, so create a little differently
                OurPlayer = new ClientMPPlayer(renderer, World, Camera.Active, new Vector3(x, y, z), team);
                player    = OurPlayer;
            }
            else
            {
                // Someone else's player, create normally
                player = new ReplicatedPlayer(renderer, World, new SimpleCamera(), new Vector3(x, y, z), team);
            }

            return(player);
        }
Esempio n. 6
0
        private void ObjectComponent_OnCreatableInstantiated(object sender, NetCreatableInfo creatable)
        {
            ClientPlayer player = creatable.Creatable as ClientPlayer;

            if (player != null)
            {
                players.Add(creatable.Id, player);
                if (creatable.IsAppOwner)
                {
                    OurPlayer = (ClientMPPlayer)player;
                }

                AddGameObject(player);
            }
            else
            {
                GameObject gameObject = creatable.Creatable as GameObject;
                AddGameObject(gameObject);
                if (gameObject.HasComponent <PhysicsBodyComponent>())
                {
                    physEntities.Add(creatable.Id, gameObject);
                }
            }
        }
Esempio n. 7
0
 public void Clear()
 {
     players.Clear();
     ourPlayer = null;
 }