public BaseScene GetScene(ushort scene_type)
        {
            BaseScene  _scene = null;
            eSceneType type   = SceneID.GetSceneTypeByID(scene_type);

            if (type == eSceneType.CITY)
            {
                if (m_city_scenes.TryGetValue(scene_type, out _scene))
                {
                    return(_scene);
                }
                return(null);
            }
            else if (type == eSceneType.BATTLE)
            {
                return(null);
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// 处理登出逻辑
        /// </summary>
        private void HandleLogoutAccount(ClientUID client_uid)
        {
            Player player = UnitManager.Instance.GetPlayerByClientUID(client_uid) as Player;

            if (player == null)
            {//如果在加载完角色信息前退出,则不会有unit
                return;
            }
            long   char_idx = player.char_idx;
            ushort fs_uid   = player.fs_uid;

            //从场景移除
            BaseScene scene = SceneManager.Instance.GetScene(player.scene_obj_idx);

            if (scene != null)
            {
                scene.RemoveUnit(player);
            }
            //从管理器移除
            UnitManager.Instance.RemoveUnit(player);


            //告诉fs
            ss2fs.LogoutClient fs_msg = PacketPools.Get(ss2fs.msg.LOGOUT_CLIENT) as ss2fs.LogoutClient;
            fs_msg.char_idx = char_idx;
            ServerNetManager.Instance.Send2FS(fs_uid, fs_msg);

            //告诉ws
            ss2ws.LogoutClient ws_msg = PacketPools.Get(ss2ws.msg.LOGOUT_CLIENT) as ss2ws.LogoutClient;
            ws_msg.char_idx = char_idx;
            ServerNetManager.Instance.Send2WS(ws_msg);

            //告诉gl
            ss2gl.LogoutClient gl_msg = PacketPools.Get(ss2gl.msg.LOGOUT_CLIENT) as ss2gl.LogoutClient;
            gl_msg.char_idx = char_idx;
            ServerNetManager.Instance.Send2GL(gl_msg);
        }
Example #3
0
        /// <summary>
        /// 进入场景
        /// </summary>
        private void OnEnterScene(PacketBase packet)
        {
            c2ss.EnterScene msg    = packet as c2ss.EnterScene;
            Player          player = UnitManager.Instance.GetPlayerByClientUID(msg.client_uid);

            if (player == null)
            {
                Log.Debug("OnEnterScene 未找到unit:" + msg.client_uid.srv_uid + ", " + msg.client_uid.conn_idx);
                return;
            }

            uint scene_idx = 0;

            if (msg.scene_type == 0)
            {                                      //进入游戏后的第一个消息:告诉client需要进入的场景id
                scene_idx = player.scene_type_idx; //上次所在场景
            }
            else
            {
                //相同场景跳转,直接返回
                if (msg.scene_type == player.scene_type_idx)
                {
                    return;
                }
                scene_idx = msg.scene_type;
            }
            //判断场景是否有效
            if (!SceneID.IsValidScene(scene_idx))
            {
                return;
            }

            //加入场景
            BaseScene scene = SceneManager.Instance.CreateScene(scene_idx);

            if (scene != null)
            {
                //先从旧的场景移除
                BaseScene old_scene = SceneManager.Instance.GetScene(player.scene_obj_idx);
                if (old_scene != null)
                {
                    old_scene.RemoveUnit(player);
                }
                //再加入新的场景
                scene.AddUnit(player);
                player.unit_attr.SetAttribInteger(eUnitModType.UMT_scene_type, scene_idx);
            }
            else
            {
                Log.Warning("加入场景失败:" + scene_idx);
                return;
            }

            //告诉client
            ss2c.EnterScene rep_msg = PacketPools.Get(ss2c.msg.ENTER_SCENE) as ss2c.EnterScene;
            rep_msg.scene_type        = scene_idx;
            rep_msg.scene_instance_id = 1;
            rep_msg.pos.Set(player.pos_x, player.pos_y);//TODO:获取场景出生点
            rep_msg.dir = eDirection.NONE;
            ServerNetManager.Instance.SendProxy(msg.client_uid, rep_msg, false);
        }