NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/ChapterInfo.cs

90 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Collections;
using System.Collections.Generic;
using cfg.LevelCfg;
using Gameplay.Net;
using UnityEngine;
public class ChapterInfo : IEnumerable
{
private DataChapter _config;
private List<LevelInfo> _levelList = new();
public int ID => _config.Id;
public int GroupID => _config.GroupID;
public LevelType LevelType => _config.Type;
public int[] StarList => _config.StarList;
public int[] Rewards => _config.Rewards;
/// <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.Lock)
return false;
}
return true;
}
}
public ChapterInfo(DataChapter 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 indexMax = OwnRewardMaxIndex;
return StarCount >= StarList[index - 1] && indexMax < index;
}
public IEnumerator GetEnumerator()
{
return _levelList.GetEnumerator();
}
}