using System.Collections;
using System.Collections.Generic;
using cfg.LevelCfg;
using cfg.RedPoint;
using Gameplay.Level;
using Gameplay.Net;
///
/// 关卡组信息
///
public class LevelGroupInfo : IRedPointTreeNode
{
#region 属性
///
/// 关卡信息列表
///
public List ListLevelInfo { get; private set; } = new();
///
/// 关卡组配置
///
public DataLevelGroup Cfg { get; private set; }
///
/// 章节信息
///
public ChapterInfo ChapterInfo
{
get
{
if (LevelManager.Instance.TryGetChapterInfoByID(Cfg.ChapterID, out ChapterInfo chapterInfo))
return chapterInfo;
return chapterInfo;
}
}
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.Score;
}
return count;
}
}
///
/// 最大星星数量
///
public int StarMax
{
get { return ListLevelInfo.Count * (int)NLDPB.GlobalDefine.MaxLevelStar; }
}
///
/// 是否锁住
///
public bool IsLock
{
get
{
foreach (LevelInfo levelInfo in ListLevelInfo)
{
if (!levelInfo.IsLock)
return false;
}
return true;
}
}
///
/// 是否有可以领取的奖励
///
///
public bool IsHasGetReward
{
get
{
int curIndex = 1;
for (int i = 0; i < Cfg.StarList.Length; ++i)
{
if (StarCount < Cfg.StarList[i])
break;
curIndex = i + 1;
}
return curIndex > OwnRewardMaxIndex;
}
}
///
/// 获取下一个目标星级
///
public int NextTargerStar
{
get
{
int target = StarCount;
for (int i = Cfg.StarList.Length - 1; i >= 0; --i)
{
if (Cfg.StarList[i] > StarCount)
target = Cfg.StarList[i];
else
break;
}
return target;
}
}
#endregion
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)
{
return index > 0 &&
index <= Cfg.StarList.Length &&
StarCount >= Cfg.StarList[index - 1] &&
OwnRewardMaxIndex < index;
}
///
/// 计算红点树
///
///
public void ConstructRedPointTree(RedPointNode parent)
{
RedPoint = RedPointManager.Instance.AddDynamicNode(NodeType.Normal, parent);
foreach (LevelInfo levelInfo in ListLevelInfo)
{
levelInfo.ConstructRedPointTree(RedPoint);
}
}
public void ConstructRedPointTree(int parentID)
{
}
}