using System.Collections;
using System.Collections.Generic;
using cfg.LevelCfg;
using cfg.RedPoint;
using Gameplay.Level;
using Gameplay.Net;
///
/// 关卡组信息
///
public class LevelGroupInfo : IEnumerable, IRedPointTreeNode
{
///
/// 关卡信息列表
///
public List ListLevelInfo { get; private set; } = new();
///
/// 关卡组配置
///
public DataLevelGroup Cfg { get; private set; }
///
/// 章节信息
///
public ChapterInfo ChapterInfo
{
get { return LevelManager.Instance.GetChapterInfoByID(Cfg.ChapterID); }
}
public RedPointNode RedPoint { get; private set; }
///
/// 当前已经领取的奖励的最大index,从1开始
///
public int OwnRewardMaxIndex
{
get { return Actor.Instance.Level.GetChapterRewardIndex(Cfg.Id); }
}
///
/// 星星数量
///
public int StarCount
{
get
{
int count = 0;
foreach (LevelInfo levelInfo in ListLevelInfo)
{
count += levelInfo.StarCount;
}
return count;
}
}
///
/// 最大星星数量
///
public int StarMax => ListLevelInfo.Count * 3;
///
/// 是否锁住
///
public bool IsLock
{
get
{
foreach (LevelInfo levelInfo in ListLevelInfo)
{
if (!levelInfo.IsLock)
return false;
}
return true;
}
}
public LevelGroupInfo(DataLevelGroup config)
{
Cfg = config;
}
///
/// 添加关卡
///
///
public void AddLevel(LevelInfo levelInfo)
{
if (ListLevelInfo.Contains(levelInfo))
{
DebugUtil.LogError($"添加重复的关卡,关卡ID:{levelInfo.Cfg.Id}");
return;
}
ListLevelInfo.Add(levelInfo);
}
///
/// 是否可以获得某个章节奖励,index从1开始
///
///
///
public bool IsGetReward(int index)
{
int alreadyGetIndex = OwnRewardMaxIndex;
return index > 0 &&
index <= Cfg.StarList.Length &&
StarCount >= Cfg.StarList[index - 1] &&
alreadyGetIndex < index;
}
///
/// 计算红点树
///
///
public void ConstructRedPointTree(RedPointNode parent)
{
RedPoint = RedPointManager.Instance.AddDynamicNode(NodeType.Normal, parent);
foreach (LevelInfo levelInfo in ListLevelInfo)
{
levelInfo.ConstructRedPointTree(RedPoint);
}
}
public IEnumerator GetEnumerator()
{
return ListLevelInfo.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void ConstructRedPointTree(int parentID)
{
}
}