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