Ejemplo n.º 1
0
        /// <summary>
        /// 创建场景
        /// </summary>
        /// <param name="scene_type"></param>
        /// <returns></returns>
        public BaseScene CreateScene(uint scene_type)
        {
            BaseScene  new_scene = null;
            eSceneType type      = SceneID.GetSceneTypeByID(scene_type);

            if (type == eSceneType.CITY)
            {//主城场景:同类型只存在一个
                if (m_city_scenes.TryGetValue(scene_type, out new_scene))
                {
                    return(new_scene);
                }
            }
            //创建场景
            switch (type)
            {
            case eSceneType.CITY: new_scene = new CityScene(); break;

            case eSceneType.BATTLE: new_scene = new BaseScene(); break;

            default: Log.Warning("错误的场景类型:" + scene_type); return(null);
            }
            new_scene.Setup(scene_type, ++m_scene_guid);
            m_scenes.Add(new_scene.scene_obj_idx, new_scene);

            if (type == eSceneType.CITY)
            {
                m_city_scenes.Add(scene_type, new_scene);
            }
            else if (type == eSceneType.BATTLE)
            {
            }

            return(new_scene);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 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);
        }