Exemplo n.º 1
0
        private void OnRecvOtherPlayerExit(IChannel channel, Message message)
        {
            SOtherPlayerExit request = message as SOtherPlayerExit;
            var entity = networkEntities[request.id];

            networkEntities.Remove(request.id);
            UnityEngine.Object.Destroy(entity.gameObject);

            World.Instance.players.Remove(request.user);
            Debug.Log(string.Format("Player {0} exit.", request.user));
        }
Exemplo n.º 2
0
        public void RemovePlayer(Player player)
        {
            if (player == null)
            {
                return;
            }
            var x = OnlinePlayers.Remove(player.player_id);

            if (!x)
            {
                return;
            }
            if (player != null)
            {
                // broundcast remove player
                SOtherPlayerExit msg = new SOtherPlayerExit();
                msg.id    = player.entityId;
                msg.user  = player.name;
                msg.scene = player.scene;
                Broundcast(msg);

                // record player position
                using (var conn = Backend.DataBase.GameDataBase.GetConnection())
                {
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "Update Player Set pos_x=@x, pos_y=@y, pos_z=@z, hp=@hp Where player_id=@player_id";
                        cmd.Parameters.AddWithValue("x", (float)player.Position.X);
                        cmd.Parameters.AddWithValue("y", (float)player.Position.Y);
                        cmd.Parameters.AddWithValue("z", (float)player.Position.Z);
                        cmd.Parameters.AddWithValue("hp", player.currentHP);
                        cmd.Parameters.AddWithValue("player_id", player.player_id);
                        var res = cmd.ExecuteNonQuery();
                        if (res != 1)
                        {
                            Console.WriteLine("Logout Fail!");
                        }
                    }
                }
            }
            RemoveEntity(player.entityId);
            Console.WriteLine("Player {0} {1} exit.", player.player_id, player.entityId);
        }