2024-09-02 14:08:35 +08:00
|
|
|
|
using Gameplay;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Gameplay.Level;
|
|
|
|
|
|
using Gameplay.Net;
|
|
|
|
|
|
using System.Collections.Generic;
|
2024-01-30 15:10:12 +08:00
|
|
|
|
using System.Linq;
|
2023-11-02 20:02:10 +08:00
|
|
|
|
using cfg.RedPoint;
|
2024-01-10 13:40:07 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2023-11-01 13:33:20 +08:00
|
|
|
|
using Framework;
|
|
|
|
|
|
using Framework.Condition;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Debug = DebugUtil;
|
2024-01-29 16:30:26 +08:00
|
|
|
|
using System;
|
2024-08-28 12:17:53 +08:00
|
|
|
|
using cfg.LevelCfg;
|
2024-09-02 14:55:43 +08:00
|
|
|
|
using static MapData;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关卡信息
|
|
|
|
|
|
/// </summary>
|
2024-06-27 18:55:53 +08:00
|
|
|
|
public class LevelInfo : IRedPointTreeNode
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2024-09-02 14:08:35 +08:00
|
|
|
|
#region 私有字段
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关卡配置信息
|
|
|
|
|
|
/// </summary>
|
2024-09-02 14:55:43 +08:00
|
|
|
|
private readonly DataLevel cfg;
|
2024-09-02 14:08:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关卡数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private LevelData levelData;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 地图数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private MapData mapData;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 服务器关卡数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private Gameplay.Net.LevelInfo serverData;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 章节索引
|
|
|
|
|
|
/// </summary>
|
2024-02-06 13:29:01 +08:00
|
|
|
|
private int _chapterIndex = -1;
|
2024-09-02 14:08:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关卡索引
|
|
|
|
|
|
/// </summary>
|
2024-02-06 13:29:01 +08:00
|
|
|
|
private int _levelIndex = -1;
|
2024-09-02 14:08:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 解锁条件id
|
|
|
|
|
|
/// </summary>
|
2024-08-13 16:04:49 +08:00
|
|
|
|
private int unLockConditionId;
|
2024-09-02 14:08:35 +08:00
|
|
|
|
#endregion
|
2024-08-13 16:04:49 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#region config
|
2024-09-02 14:08:35 +08:00
|
|
|
|
/// <summary>
|
2024-09-02 14:55:43 +08:00
|
|
|
|
/// 配置数据
|
2024-09-02 14:08:35 +08:00
|
|
|
|
/// </summary>
|
2024-09-02 14:55:43 +08:00
|
|
|
|
public DataLevel Cfg
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return cfg; }
|
|
|
|
|
|
}
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
/// <summary>
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// 所属关卡组信息
|
2024-09-02 14:08:35 +08:00
|
|
|
|
/// </summary>
|
2024-09-02 14:55:43 +08:00
|
|
|
|
public LevelGroupInfo GroupInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return LevelManager.Instance.GetLevelGroupInfoByID(cfg.LevelGroupID); }
|
|
|
|
|
|
}
|
2024-01-19 14:00:42 +08:00
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所属章节信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ChapterInfo ChapterInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return GroupInfo?.ChapterInfo; }
|
|
|
|
|
|
}
|
2023-11-20 14:10:18 +08:00
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关卡名
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Name
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return StringManager.Instance.GetLocalizeTextByKey(cfg.Name); }
|
|
|
|
|
|
}
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关卡描述
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Desc
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return StringManager.Instance.GetLocalizeTextByKey(cfg.Desc); }
|
|
|
|
|
|
}
|
2024-01-04 17:22:36 +08:00
|
|
|
|
|
2024-02-06 13:29:01 +08:00
|
|
|
|
//章节序号
|
|
|
|
|
|
public int ChapterIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_chapterIndex == -1)
|
|
|
|
|
|
{
|
2024-09-02 14:55:43 +08:00
|
|
|
|
if (cfg.Id < 100000)
|
2024-02-06 13:29:01 +08:00
|
|
|
|
{
|
2024-09-02 14:55:43 +08:00
|
|
|
|
DebugUtil.LogError("关卡id为{0}的关卡id没到6位", cfg.Id);
|
2024-02-06 13:29:01 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-02 14:55:43 +08:00
|
|
|
|
var resultStr = cfg.Id.ToString().Substring(1, 2);
|
2024-02-06 13:29:01 +08:00
|
|
|
|
_chapterIndex = int.Parse(resultStr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _chapterIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-13 14:18:34 +08:00
|
|
|
|
|
2024-02-06 13:29:01 +08:00
|
|
|
|
//关卡序号
|
|
|
|
|
|
public int LevelIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_levelIndex == -1)
|
|
|
|
|
|
{
|
2024-09-02 14:55:43 +08:00
|
|
|
|
if (cfg.Id < 100000)
|
2024-02-06 13:29:01 +08:00
|
|
|
|
{
|
2024-09-02 14:55:43 +08:00
|
|
|
|
DebugUtil.LogError("关卡id为{0}的关卡id没到6位", cfg.Id);
|
2024-02-06 13:29:01 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-02 14:55:43 +08:00
|
|
|
|
var resultStr = cfg.Id.ToString().Substring(3, 3);
|
2024-02-06 13:29:01 +08:00
|
|
|
|
_levelIndex = int.Parse(resultStr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _levelIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-18 16:02:45 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Data
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 环境类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public EnvironmentType Environment
|
2024-04-18 18:14:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2024-09-02 15:32:25 +08:00
|
|
|
|
if (null == MapData)
|
|
|
|
|
|
return EnvironmentType.Desert;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
return mapData.environmentType;
|
2024-04-18 18:14:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否锁住
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsLock { get; private set; } = true;
|
2024-04-18 18:14:18 +08:00
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 能否进入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool CanEnter
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return !IsLock && IsConstEnough(); }
|
2024-04-18 18:14:18 +08:00
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 地图数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public MapData MapData
|
2024-04-13 14:18:34 +08:00
|
|
|
|
{
|
2024-09-02 15:32:25 +08:00
|
|
|
|
get { return mapData ??= MapUtils.LoadMapData(cfg.MapData); }
|
2024-04-13 14:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关卡数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public LevelData LevelData
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return levelData ??= LevelUtils.LoadLevelData(cfg.Id); }
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 15:32:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否剧情
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsStory
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return !string.IsNullOrWhiteSpace(cfg.StoryID); }
|
|
|
|
|
|
}
|
2024-01-04 17:22:36 +08:00
|
|
|
|
|
2024-09-02 16:01:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 环境buff描述
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string EnvironmentBuffString
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return CommonUtils.GetLocalizeText(TableManager.Instance.Tables.EnviormentConfig.Get((int)Environment).DescLocal);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Server Data
|
2024-09-02 16:01:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 星级数量
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int StarCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (null == serverData)
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
return (int)serverData.StarCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2024-09-02 16:01:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 星级达成结果
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool[] StarResult
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (null == serverData)
|
|
|
|
|
|
return new bool[StarCount];
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 16:01:34 +08:00
|
|
|
|
return serverData.star.Select(s => s > 0).ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-02-06 13:29:01 +08:00
|
|
|
|
|
2024-09-02 16:01:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 是否通关
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool IsPass
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (null == serverData)
|
|
|
|
|
|
return false;
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2024-09-02 16:01:34 +08:00
|
|
|
|
return serverData.isPassed;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
2024-09-02 16:01:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 红点
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public RedPointNode RedPoint { get; private set; }
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public LevelInfo(DataLevel config)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2024-09-02 14:08:35 +08:00
|
|
|
|
cfg = config;
|
2024-09-02 15:32:25 +08:00
|
|
|
|
IsLock = true;
|
2024-08-13 16:04:49 +08:00
|
|
|
|
RefreshServerData(true);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsConstEnough()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool result = true;
|
2024-09-02 15:32:25 +08:00
|
|
|
|
if (cfg.CostItems == null || cfg.CostItems.Count == 0)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
return result;
|
2024-09-02 15:32:25 +08:00
|
|
|
|
foreach (var costItem in cfg.CostItems)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
var currCount = Actor.Instance.Item.GetItemCount(costItem.Id);
|
|
|
|
|
|
result = result && currCount >= costItem.Count;
|
|
|
|
|
|
if (!result)
|
|
|
|
|
|
{
|
2024-09-02 14:55:43 +08:00
|
|
|
|
Debug.LogError($"关卡消耗品不足,level id:{cfg.Id}");
|
2023-10-19 15:00:19 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-13 16:04:49 +08:00
|
|
|
|
public void RefreshServerData(bool isReset)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2024-09-02 14:55:43 +08:00
|
|
|
|
serverData = Actor.Instance.Level.GetLevelInfo((uint)cfg.Id);
|
2024-08-13 16:04:49 +08:00
|
|
|
|
if (isReset)
|
|
|
|
|
|
{
|
|
|
|
|
|
IsLock = true;
|
|
|
|
|
|
AddLockConditionReaction();
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2023-11-01 13:33:20 +08:00
|
|
|
|
|
2023-11-02 20:02:10 +08:00
|
|
|
|
public void ConstructRedPointTree(RedPointNode parent)
|
|
|
|
|
|
{
|
2024-09-02 16:01:34 +08:00
|
|
|
|
RedPoint = RedPointManager.Instance.AddDynamicNode(NodeType.Level, parent, cfg.Id);
|
2023-11-02 20:02:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-24 19:10:02 +08:00
|
|
|
|
//获得星级目标的文本
|
|
|
|
|
|
public string GetStarTargetLocalizationText(int targetIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
var starTarget = LevelData.starTarget;
|
|
|
|
|
|
if (targetIndex < 0 || targetIndex >= starTarget.Count)
|
|
|
|
|
|
return null;
|
2024-04-15 17:59:58 +08:00
|
|
|
|
|
2024-01-24 19:10:02 +08:00
|
|
|
|
return starTarget[targetIndex].GetConditionLocalization();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-01 13:33:20 +08:00
|
|
|
|
private void AddLockConditionReaction()
|
|
|
|
|
|
{
|
2024-08-13 16:04:49 +08:00
|
|
|
|
ConditionReactor.Instance.RemoveReaction(unLockConditionId);
|
2024-09-02 15:32:25 +08:00
|
|
|
|
unLockConditionId = ConditionReactor.Instance.AddReaction(cfg.Unlock, OnUnlockConditionChanged);
|
2023-11-01 13:33:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnUnlockConditionChanged(bool result, object callBackParam, int reactionID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (result)
|
|
|
|
|
|
{
|
|
|
|
|
|
IsLock = false;
|
2024-09-02 14:55:43 +08:00
|
|
|
|
DebugUtil.Log($"[Level] level unlock,id:{cfg.Id}");
|
|
|
|
|
|
EventManager.Instance.Send<int>(EventManager.EventName.LevelUnlock, cfg.Id);
|
2023-11-01 13:33:20 +08:00
|
|
|
|
ConditionReactor.Instance.RemoveReaction(reactionID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-27 18:55:53 +08:00
|
|
|
|
|
|
|
|
|
|
public void ConstructRedPointTree(int parentID)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2023-10-24 14:58:21 +08:00
|
|
|
|
}
|