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

213 lines
4.8 KiB
C#
Raw Normal View History

2023-10-24 14:58:21 +08:00
using System.Collections.Generic;
using cfg.LevelCfg;
using cfg.RedPoint;
using Framework;
2024-01-19 14:00:42 +08:00
using Gameplay.Level;
2023-10-30 18:33:18 +08:00
using Gameplay.Net;
using UnityEngine;
2023-10-24 14:58:21 +08:00
2024-09-02 14:08:35 +08:00
/// <summary>
/// 关卡组信息
/// </summary>
2024-09-05 13:41:39 +08:00
public class LevelGroupInfo : IRedPointTreeNode
2023-10-24 14:58:21 +08:00
{
2024-09-04 16:40:19 +08:00
#region 属性
2024-09-02 14:08:35 +08:00
/// <summary>
/// 关卡信息列表
/// </summary>
2024-09-03 19:22:47 +08:00
public List<LevelInfo> ListLevelInfo { get; private set; } = new();
2024-09-02 14:08:35 +08:00
/// <summary>
2024-09-02 18:51:47 +08:00
/// 关卡组配置
2024-09-02 14:08:35 +08:00
/// </summary>
2024-09-02 18:51:47 +08:00
public DataLevelGroup Cfg { get; private set; }
2023-10-24 14:58:21 +08:00
2024-09-02 14:08:35 +08:00
/// <summary>
2024-09-02 18:51:47 +08:00
/// 章节信息
2024-09-02 14:08:35 +08:00
/// </summary>
2024-09-02 18:51:47 +08:00
public ChapterInfo ChapterInfo
{
2024-09-05 13:52:02 +08:00
get
{
if (LevelManager.Instance.TryGetChapterInfoByID(Cfg.ChapterID, out ChapterInfo chapterInfo))
return chapterInfo;
return chapterInfo;
}
2024-09-02 18:51:47 +08:00
}
2023-10-24 14:58:21 +08:00
2024-09-02 18:51:47 +08:00
public RedPointNode RedPoint { get; private set; }
2023-10-30 18:33:18 +08:00
/// <summary>
/// 当前已经领取的奖励的最大index,从1开始
/// </summary>
2024-09-05 15:48:15 +08:00
public int OwnRewardMaxIndex
{
get { return Actor.Instance.Level.GetChapterRewardIndex(Cfg.Id); }
2024-09-02 18:51:47 +08:00
}
2023-10-30 18:33:18 +08:00
2024-09-02 18:51:47 +08:00
/// <summary>
2024-09-05 15:48:15 +08:00
/// 星星数量或分数
2024-09-02 18:51:47 +08:00
/// </summary>
2024-09-05 15:48:15 +08:00
public int Score
2023-10-26 20:20:11 +08:00
{
get
{
2024-09-02 18:51:47 +08:00
int count = 0;
2024-09-03 19:22:47 +08:00
foreach (LevelInfo levelInfo in ListLevelInfo)
2023-10-26 20:20:11 +08:00
{
2024-09-05 14:17:27 +08:00
count += levelInfo.Score;
2023-10-26 20:20:11 +08:00
}
return count;
}
}
2024-09-02 18:51:47 +08:00
/// <summary>
2024-09-05 15:48:15 +08:00
/// 最大星星数量或最大评分
/// </summary>
public int ScoreMax
{
get
{
int total = 0;
foreach (LevelInfo levelInfo in ListLevelInfo)
{
total += levelInfo.ScoreMax;
}
return total;
}
}
/// <summary>
/// 关卡组评级
2024-09-02 18:51:47 +08:00
/// </summary>
2024-09-05 15:48:15 +08:00
public E_WarRating WarRating
2024-09-04 16:40:19 +08:00
{
2024-09-05 15:48:15 +08:00
get { return LevelUtils.GetWarLevelRatingByLevelGroupInfo(this); }
2024-09-04 16:40:19 +08:00
}
2023-10-26 20:20:11 +08:00
2024-09-02 18:51:47 +08:00
/// <summary>
/// 是否锁住
/// </summary>
2023-10-26 20:20:11 +08:00
public bool IsLock
{
get
{
2024-09-03 19:22:47 +08:00
foreach (LevelInfo levelInfo in ListLevelInfo)
2023-10-26 20:20:11 +08:00
{
2023-11-01 13:33:20 +08:00
if (!levelInfo.IsLock)
2023-10-26 20:20:11 +08:00
return false;
}
return true;
}
}
2024-09-04 16:40:19 +08:00
/// <summary>
/// 是否有可以领取的奖励
/// </summary>
/// <returns></returns>
2024-09-05 18:43:40 +08:00
public bool IsHasGetRewards
2024-09-04 16:40:19 +08:00
{
get
{
2024-09-05 18:43:40 +08:00
int curIndex = 0;
2024-09-04 16:40:19 +08:00
for (int i = 0; i < Cfg.StarList.Length; ++i)
{
2024-09-05 15:48:15 +08:00
if (Score < Cfg.StarList[i])
2024-09-04 16:40:19 +08:00
break;
curIndex = i + 1;
}
return curIndex > OwnRewardMaxIndex;
}
}
2024-09-04 17:23:16 +08:00
/// <summary>
2024-09-05 18:43:40 +08:00
/// 获取下一个目标星级索引
2024-09-04 17:23:16 +08:00
/// </summary>
2024-09-05 18:43:40 +08:00
public int NextTargerStarIndex
2024-09-04 17:23:16 +08:00
{
get
{
if (E_ChapterType.War == ChapterInfo.Cfg.Type)
2024-09-04 17:23:16 +08:00
{
List<float> listScoreRate = TableManager.Instance.Tables.GlobalConfig.CampaignScoreClass;
int index = listScoreRate.Count - 1;
for (int i = listScoreRate.Count - 1; i >= 0; --i)
{
if ((int)(listScoreRate[i] * ScoreMax) > Score)
index = i;
else
break;
}
return index;
}
else
{
int index = Cfg.StarList.Length - 1;
for (int i = Cfg.StarList.Length - 1; i >= 0; --i)
{
if (Cfg.StarList[i] > Score)
index = i;
else
break;
}
return index;
2024-09-04 17:23:16 +08:00
}
}
}
2024-09-04 16:40:19 +08:00
#endregion
2024-01-05 19:15:21 +08:00
public LevelGroupInfo(DataLevelGroup config)
2023-10-24 14:58:21 +08:00
{
2024-09-02 18:51:47 +08:00
Cfg = config;
2023-10-24 14:58:21 +08:00
}
2024-09-02 18:51:47 +08:00
/// <summary>
/// 添加关卡
/// </summary>
/// <param name="levelInfo"></param>
2023-10-24 14:58:21 +08:00
public void AddLevel(LevelInfo levelInfo)
{
2024-09-03 19:22:47 +08:00
if (ListLevelInfo.Contains(levelInfo))
2023-10-24 14:58:21 +08:00
{
2024-09-02 18:51:47 +08:00
DebugUtil.LogError($"添加重复的关卡关卡ID:{levelInfo.Cfg.Id}");
return;
2023-10-24 14:58:21 +08:00
}
2024-09-02 18:51:47 +08:00
2024-09-03 19:22:47 +08:00
ListLevelInfo.Add(levelInfo);
2023-10-24 14:58:21 +08:00
}
2023-10-26 20:20:11 +08:00
2024-09-05 18:43:40 +08:00
/// <summary>
/// 是否已经领取过index从1开始
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public bool IsGetReward(int index)
{
return index <= OwnRewardMaxIndex;
}
2024-09-02 18:51:47 +08:00
/// <summary>
/// 计算红点树
/// </summary>
/// <param name="parent"></param>
public void ConstructRedPointTree(RedPointNode parent)
{
2024-09-02 18:51:47 +08:00
RedPoint = RedPointManager.Instance.AddDynamicNode(NodeType.Normal, parent);
2024-09-03 19:22:47 +08:00
foreach (LevelInfo levelInfo in ListLevelInfo)
{
2024-09-02 18:51:47 +08:00
levelInfo.ConstructRedPointTree(RedPoint);
}
}
2024-01-18 16:02:45 +08:00
public void ConstructRedPointTree(int parentID)
{
2024-09-03 19:22:47 +08:00
}
2023-10-24 14:58:21 +08:00
}