LevelTable = {} LevelTable.ELevelType = { Random = 0, -- 随机地图 Level1 = 1, Level2 = 2, Level3 = 3, } --- 配置的地图数据 ---@type table LevelTable.LevelInfo = { [LevelTable.ELevelType.Random] = { Icon = UGCGameSystem.GetUGCResourcesFullPath('Asset/Art/UITexture/T_RandomMap.T_RandomMap'), ShowName = "随机关卡", }, [LevelTable.ELevelType.Level1] = { ShowName = "遗迹", MapName = "Map_Ruins", Rate = 100; MiniMapInfo = { MapPath = UGCGameSystem.GetUGCResourcesFullPath('Asset/Levels/Minimap/T_MiniRuins1.T_MiniRuins1'), --- (X=50.000000,Y=-100.000000,Z=300.000000) MapCentre = { X = 50., Y = -100., Z = 300. }, MapSize = 13000.0, MapScale = 30., } }, [LevelTable.ELevelType.Level2] = { ShowName = "沙漠", MapName = "Level3", Rate = 0; MiniMapInfo = { MapPath = UGCGameSystem.GetUGCResourcesFullPath('Asset/Levels/Minimap/T_Desserty.T_Desserty'), --- (X=207721.187500,Y=281974.781250,Z=568.751587) MapCentre = { X = 207721.187500, Y = 281974.781250, Z = 568.751587 }, MapSize = 30000.0, MapScale = 30., } }, [LevelTable.ELevelType.Level3] = { Icon = UGCGameSystem.GetUGCResourcesFullPath('Asset/Texture/MapTex/T_Level2.T_Level2'), IconSelect = UGCGameSystem.GetUGCResourcesFullPath('Asset/Texture/MapTex/T_Level2Select.T_Level2Select'), ShowName = "新年广场", MapName = "Map_NewYear_Small", Rate = 0; --MiniMapInfo = { -- MapPath = UGCGameSystem.GetUGCResourcesFullPath('T_Level2MiniMap.T_Level2MiniMap'), -- MapCentre = {X=1100.000000,Y=-47600.000000,Z=100.000000}, -- MapSize = 20000.0, -- MapScale = 30., --} }, } --- 是否启用地图 ---@type table LevelTable.LevelEnable = { [LevelTable.ELevelType.Random] = true; [LevelTable.ELevelType.Level1] = true; [LevelTable.ELevelType.Level2] = true; [LevelTable.ELevelType.Level3] = false; } ---@param IsUseRate bool 是否使用比例进行随机 ---@param MapNum int 需要地图的数量 ---@return table 获取随机地图的 index function LevelTable.GetRandomLevel(IsUseRate) if IsUseRate then local Total = 0; for i = 1, #LevelTable.LevelInfo do local Info = LevelTable.LevelInfo[i] if Info and Info.Rate then Total = Total + Info.Rate; end end local MapIndies = {}; local RandomNum = math.pop() * Total UGCLogSystem.Log("[LevelTable.GetRandomLevel] RandomNum = %f", RandomNum) for i = 1, #LevelTable.LevelInfo do local Info = LevelTable.LevelInfo[i]; UGCLogSystem.Log("[LevelTable.GetRandomLevel] RandomNum = %f", RandomNum) if Info and Info.Rate then RandomNum = RandomNum - Info.Rate; if RandomNum <= 0 then table.insert(MapIndies, i); break ; end end end return MapIndies; end local Count = table.getCount(LevelTable.LevelInfo); -- 默认 Random 是 0; if Count == 2 then return { 1 }; end return math.random(Count); end