using System.Collections.Generic;
|
using System.Linq;
|
public partial class FBDJGLevelConfig : ConfigBase<int, FBDJGLevelConfig>
|
{
|
//<层数,<关卡编号,关卡ID>>
|
static Dictionary<int, Dictionary<int, int>> idDict = new Dictionary<int, Dictionary<int, int>>();
|
|
protected override void OnConfigParseCompleted()
|
{
|
if (!idDict.ContainsKey(LayerNum))
|
{
|
idDict[LayerNum] = new Dictionary<int, int>();
|
}
|
idDict[LayerNum][LevelNum] = LevelID;
|
}
|
|
public static bool TryGetLayerNumDict(int layerNum, out Dictionary<int, int> dict)
|
{
|
dict = null;
|
return idDict != null && idDict.TryGetValue(layerNum, out dict);
|
}
|
|
public static bool TryGetLevelID(int layerNum, int levelNum, out int levelID)
|
{
|
levelID = 0;
|
return idDict != null && idDict.TryGetValue(layerNum, out var dict) && dict.TryGetValue(levelNum, out levelID);
|
}
|
|
public static bool TryGetFBDJGLevelConfig(int layerNum, int levelNum, out FBDJGLevelConfig config)
|
{
|
config = null;
|
if (TryGetLevelID(layerNum, levelNum, out var levelID) && HasKey(levelID))
|
{
|
config = Get(levelID);
|
return true;
|
}
|
return false;
|
}
|
|
public static bool TryGetFBDJGLevelConfig(int levelID, out FBDJGLevelConfig config)
|
{
|
config = null;
|
if (HasKey(levelID))
|
{
|
config = Get(levelID);
|
return true;
|
}
|
return false;
|
}
|
|
public static bool TryGetMinFBDJGLevelConfig(out FBDJGLevelConfig minConfig)
|
{
|
minConfig = null;
|
if (idDict.IsNullOrEmpty())
|
return false;
|
int layerNum = idDict.Keys.Min();
|
if (!TryGetLayerNumDict(layerNum, out var dict) || dict.IsNullOrEmpty())
|
return false;
|
int levelNum = dict.Keys.Min();
|
if (!TryGetFBDJGLevelConfig(layerNum, levelNum, out minConfig) || minConfig == null)
|
return false;
|
return true;
|
}
|
public static bool TryGetMaxFBDJGLevelConfig(out FBDJGLevelConfig maxConfig)
|
{
|
maxConfig = null;
|
if (idDict.IsNullOrEmpty())
|
return false;
|
int layerNum = idDict.Keys.Max();
|
if (!TryGetLayerNumDict(layerNum, out var dict) || dict.IsNullOrEmpty())
|
return false;
|
int levelNum = dict.Keys.Max();
|
if (!TryGetFBDJGLevelConfig(layerNum, levelNum, out maxConfig) || maxConfig == null)
|
return false;
|
return true;
|
}
|
|
// 获取指定层的最大关卡编号
|
public static bool TryGetMaxLevelNumInLayer(int layerNum, out int maxLevelNum)
|
{
|
maxLevelNum = 0;
|
if (!TryGetLayerNumDict(layerNum, out var dict) || dict.IsNullOrEmpty())
|
return false;
|
maxLevelNum = dict.Keys.Max();
|
return true;
|
}
|
|
// 获取下一关
|
public static bool TryGetNextLevel(int layerNum, int levelNum, out int nextLayerNum, out int nextLevelNum)
|
{
|
nextLayerNum = 0;
|
nextLevelNum = 0;
|
if (!TryGetMaxLevelNumInLayer(layerNum, out int maxLevelNum))
|
return false;
|
|
// 层数相同,下一关
|
if (maxLevelNum > 0 && levelNum < maxLevelNum)
|
{
|
nextLayerNum = layerNum;
|
nextLevelNum = levelNum + 1;
|
return true;
|
}
|
|
// 下一层的第1关
|
nextLayerNum = layerNum + 1;
|
|
// 如果没有下一层
|
if (!idDict.ContainsKey(nextLayerNum))
|
{
|
nextLayerNum = 0;
|
nextLevelNum = 0;
|
return false;
|
}
|
|
nextLevelNum = idDict[nextLayerNum].Keys.Min();
|
return true;
|
}
|
|
}
|