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