117 lines
2.7 KiB
C#
117 lines
2.7 KiB
C#
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<LevelInfo>, IRedPointTreeNode
|
||
{
|
||
private DataLevelGroup _config;
|
||
|
||
private List<LevelInfo> _levelList = new();
|
||
|
||
private RedPointNode _redPointNode;
|
||
|
||
public int ID => _config.Id;
|
||
|
||
public int ChapterID => _config.ChapterID;
|
||
|
||
public ChapterInfo ChapterInfo => LevelManager.Instance.GetChapterInfoByID(ChapterID);
|
||
|
||
public LevelType LevelType => _config.Type;
|
||
|
||
public int[] StarList => _config.StarList;
|
||
|
||
public int[] Rewards => _config.Rewards;
|
||
|
||
public RedPointNode RedPointNode => _redPointNode;
|
||
|
||
/// <summary>
|
||
/// 当前已经领取的奖励的最大index,从1开始
|
||
/// </summary>
|
||
public int OwnRewardMaxIndex => Actor.Instance.Level.GetChapterRewardIndex(ID);
|
||
|
||
public int StarCount
|
||
{
|
||
get
|
||
{
|
||
var count = 0;
|
||
foreach (var levelInfo in _levelList)
|
||
{
|
||
count += levelInfo.StarCount;
|
||
}
|
||
|
||
return count;
|
||
}
|
||
}
|
||
|
||
public int StarMax => _levelList.Count * 3;
|
||
|
||
public bool IsLock
|
||
{
|
||
get
|
||
{
|
||
foreach (var levelInfo in _levelList)
|
||
{
|
||
if (!levelInfo.IsLock)
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
}
|
||
|
||
public LevelGroupInfo(DataLevelGroup config)
|
||
{
|
||
_config = config;
|
||
}
|
||
|
||
public void AddLevel(LevelInfo levelInfo)
|
||
{
|
||
if (!_levelList.Contains(levelInfo))
|
||
{
|
||
_levelList.Add(levelInfo);
|
||
}
|
||
else
|
||
{
|
||
DebugUtil.LogError($"cant add level,level id:{levelInfo.ID}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否可以获得某个章节奖励,index从1开始
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
/// <returns></returns>
|
||
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 _levelList)
|
||
{
|
||
levelInfo.ConstructRedPointTree(_redPointNode);
|
||
}
|
||
}
|
||
|
||
public IEnumerator<LevelInfo> GetEnumerator()
|
||
{
|
||
return _levelList.GetEnumerator();
|
||
}
|
||
|
||
IEnumerator IEnumerable.GetEnumerator()
|
||
{
|
||
return GetEnumerator();
|
||
}
|
||
|
||
public void ConstructRedPointTree(int parentID)
|
||
{
|
||
throw new System.NotImplementedException();
|
||
}
|
||
} |