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>
|
|
|
|
|
|
private RedPointNode redPointNode;
|
|
|
|
|
|
/// <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 14:55:43 +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 14:55:43 +08:00
|
|
|
|
public ChapterInfo ChapterInfo => GroupInfo?.ChapterInfo;
|
2024-01-29 16:30:26 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
//解锁条件
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int[] UnLockCondition => cfg.Unlock;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
//消耗
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public List<cfg.item.ItemCounts> CostItems => cfg.CostItems;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int[] NomralRewardID => cfg.NormalRewardID;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int[] FirstRewardID => cfg.FristRewardID;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
//一星奖励
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int[] StarRewardID_1 => cfg.StarRewardID1;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
//二星奖励
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int[] StarRewardID_2 => cfg.StarRewardID2;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
//三星奖励
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int[] StarRewardID_3 => cfg.StarRewardID3;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int SettleExp => cfg.SettleExp;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int SettleLikability => cfg.SettleLikability;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public string LevelDataPath => cfg.LevelData;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public string Name => StringManager.Instance.GetLocalizeTextByKey(cfg.Name);
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public string Desc => StringManager.Instance.GetLocalizeTextByKey(cfg.Desc);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public string LevelScene => cfg.LevelScene;
|
2023-11-20 14:10:18 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public string MapDataPath => cfg.MapData;
|
2023-11-20 14:10:18 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public float ShadowDistance => cfg.ShadowDistance;
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public string StoryID => cfg.StoryID;
|
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
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2024-04-18 18:14:18 +08:00
|
|
|
|
public WeatherType WeatherType
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (LevelData == null)
|
|
|
|
|
|
return WeatherType.Fog;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
return cfg.LevelWeather;
|
2024-04-18 18:14:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DayNightType DayNightType
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (LevelData == null)
|
|
|
|
|
|
return DayNightType.Day;
|
|
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
return cfg.LevelTime;
|
2024-04-18 18:14:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-04-13 14:18:34 +08:00
|
|
|
|
public EnvironmentType EnvironmentType
|
|
|
|
|
|
{
|
2024-06-27 18:55:53 +08:00
|
|
|
|
get
|
2024-04-18 18:14:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (MapData == null)
|
|
|
|
|
|
return EnvironmentType.Desert;
|
|
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
return mapData.environmentType;
|
2024-04-18 18:14:18 +08:00
|
|
|
|
}
|
2024-04-13 14:18:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-07-09 13:37:27 +08:00
|
|
|
|
public bool IsLock { get; set; } = true;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
public bool CostEnough => IsConstEnough();
|
|
|
|
|
|
|
2023-11-01 13:33:20 +08:00
|
|
|
|
public bool CanEnter => !IsLock && CostEnough;
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public MapData MapData => mapData ??= MapUtils.LoadMapData(MapDataPath);
|
2023-11-21 15:04:56 +08:00
|
|
|
|
|
2024-09-02 14:55:43 +08:00
|
|
|
|
public LevelData LevelData => levelData ??= LevelUtils.LoadLevelData(cfg.Id);
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2024-01-05 20:03:45 +08:00
|
|
|
|
public bool IsStory => !string.IsNullOrWhiteSpace(StoryID);
|
2024-01-04 17:22:36 +08:00
|
|
|
|
|
2024-01-29 16:30:26 +08:00
|
|
|
|
//返回环境buff
|
2024-08-28 12:17:53 +08:00
|
|
|
|
public string EnvironmentBuffString =>
|
|
|
|
|
|
CommonUtils.GetLocalizeText(TableManager.Instance.Tables.EnviormentConfig.Get((int)EnvironmentType).DescLocal);
|
2024-01-29 16:30:26 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Server Data
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public int StarCount => (int)(serverData == null ? 0 : serverData.StarCount);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public bool[] StarResult => serverData == null ? new bool[3] : serverData.star.Select(s => s > 0).ToArray();
|
2024-02-06 13:29:01 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public bool HasPass => serverData == null ? false : serverData.isPassed;
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2024-09-02 14:08:35 +08:00
|
|
|
|
public RedPointNode RedPointNode => redPointNode;
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
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-08-13 16:04:49 +08:00
|
|
|
|
RefreshServerData(true);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsConstEnough()
|
|
|
|
|
|
{
|
|
|
|
|
|
bool result = true;
|
|
|
|
|
|
if (CostItems == null || CostItems.Count == 0)
|
|
|
|
|
|
return result;
|
|
|
|
|
|
foreach (var costItem in CostItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
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 14:55:43 +08:00
|
|
|
|
redPointNode = 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);
|
|
|
|
|
|
unLockConditionId = ConditionReactor.Instance.AddReaction(UnLockCondition, 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
|
|
|
|
}
|