예제 #1
0
        public static List <SceneObject> RefreshSceneObjects(string filePath, int mapWidth, int mapHeight, SceneFreshReason reason)
        {
            List <ScenePosData> cachedMapData = new List <ScenePosData>();

            try
            {
                LoadSceneFile(mapWidth, mapHeight, filePath, cachedMapData);
            }
            catch (Exception e)
            {
                throw;
            }


            List <SceneObject> sceneObjects = new List <SceneObject>();

            foreach (var scenePosData in cachedMapData)
            {
                SceneObject so;
                so = new SceneObject(scenePosData.Id, scenePosData.X, scenePosData.Y, scenePosData.Width, scenePosData.Height);
                sceneObjects.Add(so);
            }

            return(sceneObjects);
        }
예제 #2
0
        public static List <SceneObject> RefreshSceneObjects(int id, int mapWidth, int mapHeight, SceneFreshReason reason)
        {
            List <ScenePosData> cachedMapData = new List <ScenePosData>();
            var cachedSpecialData             = new Dictionary <int, DbSceneSpecialPosData>();
            var filePath = ConfigData.GetSceneConfig(id).TilePath;

            List <DbSceneSpecialPosData> specialDataList = new List <DbSceneSpecialPosData>();

            if (reason != SceneFreshReason.Load || UserProfile.Profile.InfoWorld.PosInfos == null || UserProfile.Profile.InfoWorld.PosInfos.Count <= 0)
            {//重新生成
                UserProfile.InfoBasic.DungeonRandomSeed = MathTool.GetRandom(int.MaxValue);
                Random r = new Random(UserProfile.InfoBasic.DungeonRandomSeed);
                SceneQuestBook.LoadSceneFile(mapWidth, mapHeight, filePath, r, cachedMapData, specialDataList);
                FilterSpecialData(specialDataList, cachedSpecialData);
                var questCellCount = cachedMapData.Count - cachedSpecialData.Count;
                GenerateSceneRandomInfo(id, questCellCount, cachedMapData, cachedSpecialData);
            }
            else
            {//从存档加载
                Random r = new Random(UserProfile.InfoBasic.DungeonRandomSeed);
                SceneQuestBook.LoadSceneFile(mapWidth, mapHeight, filePath, r, cachedMapData, specialDataList);
                foreach (var posData in UserProfile.Profile.InfoWorld.PosInfos)
                {
                    cachedSpecialData[posData.Id] = posData;
                }
            }

            List <SceneObject> sceneObjects = new List <SceneObject>();

            foreach (var scenePosData in cachedMapData)
            {
                DbSceneSpecialPosData cachedData;
                cachedSpecialData.TryGetValue(scenePosData.Id, out cachedData);

                SceneObject so;
                if (cachedData != null)
                {
                    switch (cachedData.Type)
                    {
                    case "Quest":
                        so          = new SceneQuest(scenePosData.Id, scenePosData.X, scenePosData.Y, scenePosData.Width, scenePosData.Height, cachedData.Info);
                        so.Disabled = cachedData.Disabled; break;

                    case "Warp":
                        so          = new SceneWarp(scenePosData.Id, scenePosData.X, scenePosData.Y, scenePosData.Width, scenePosData.Height, cachedData.Info);
                        so.Disabled = cachedData.Disabled;
                        if (ConfigData.GetSceneConfig(id).Type == SceneTypes.Common && reason == SceneFreshReason.Warp)
                        {
                            cachedData.Disabled = true;
                            so.Disabled         = true;//如果是切场景,切到战斗场景,所有传送门自动关闭
                        }
                        break;

                    default:
                        so = new SceneTile(scenePosData.Id, scenePosData.X, scenePosData.Y, scenePosData.Width, scenePosData.Height); break;
                    }
                    so.Flag       = cachedData.Flag;
                    so.MapSetting = cachedData.MapSetting;
                }
                else
                {
                    so          = new SceneTile(scenePosData.Id, scenePosData.X, scenePosData.Y, scenePosData.Width, scenePosData.Height); break;
                    so.Disabled = true;
                    //throw new Exception("RefreshSceneObjects error");
                }
                sceneObjects.Add(so);
            }

            return(sceneObjects);
        }