2024-01-29 16:30:26 +08:00
|
|
|
|
using cfg.LevelCfg;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Gameplay;
|
|
|
|
|
|
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 UnityEngine;
|
|
|
|
|
|
using static Gameplay.Level.LevelData;
|
|
|
|
|
|
using static MapData;
|
|
|
|
|
|
using Debug = DebugUtil;
|
2024-01-29 16:30:26 +08:00
|
|
|
|
using System;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
public class LevelInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
private DataLevel _config;
|
|
|
|
|
|
|
|
|
|
|
|
private LevelData _levelData;
|
|
|
|
|
|
|
|
|
|
|
|
private MapData _mapData;
|
|
|
|
|
|
|
|
|
|
|
|
private Gameplay.Net.LevelInfo _serverData;
|
|
|
|
|
|
|
2023-11-02 20:02:10 +08:00
|
|
|
|
private RedPointNode _redPointNode;
|
|
|
|
|
|
|
2024-02-06 13:29:01 +08:00
|
|
|
|
private int _chapterIndex = -1;
|
|
|
|
|
|
|
|
|
|
|
|
private int _levelIndex = -1;
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#region config
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public int ID => _config.Id;
|
|
|
|
|
|
|
2024-01-05 19:15:21 +08:00
|
|
|
|
public int LevelGroupID => _config.LevelGroupID;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-01-19 14:00:42 +08:00
|
|
|
|
public LevelGroupInfo LevelGroupInfo => LevelManager.Instance.GetLevelGroupInfoByID(LevelGroupID);
|
|
|
|
|
|
|
|
|
|
|
|
public ChapterInfo ChapterInfo => LevelGroupInfo?.ChapterInfo;
|
2024-01-29 16:30:26 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
//解锁条件
|
|
|
|
|
|
public int[] UnLockCondition => _config.Unlock;
|
|
|
|
|
|
|
|
|
|
|
|
//消耗
|
|
|
|
|
|
public List<cfg.item.ItemCounts> CostItems => _config.CostItems;
|
|
|
|
|
|
|
|
|
|
|
|
public int[] NomralRewardID => _config.NormalRewardID;
|
|
|
|
|
|
|
|
|
|
|
|
public int[] FirstRewardID => _config.FristRewardID;
|
|
|
|
|
|
|
|
|
|
|
|
//一星奖励
|
|
|
|
|
|
public int[] StarRewardID_1 => _config.StarRewardID1;
|
|
|
|
|
|
|
|
|
|
|
|
//二星奖励
|
|
|
|
|
|
public int[] StarRewardID_2 => _config.StarRewardID2;
|
|
|
|
|
|
|
|
|
|
|
|
//三星奖励
|
|
|
|
|
|
public int[] StarRewardID_3 => _config.StarRewardID3;
|
|
|
|
|
|
|
|
|
|
|
|
public int SettleExp => _config.SettleExp;
|
|
|
|
|
|
|
|
|
|
|
|
public int SettleLikability => _config.SettleLikability;
|
|
|
|
|
|
|
2023-11-21 15:04:56 +08:00
|
|
|
|
public string LevelDataPath => _config.LevelData;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-10-24 14:58:21 +08:00
|
|
|
|
public string Name => StringManager.Instance.GetLocalizeTextByKey(_config.Name);
|
|
|
|
|
|
|
|
|
|
|
|
public string Desc => StringManager.Instance.GetLocalizeTextByKey(_config.Desc);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-01-17 17:17:39 +08:00
|
|
|
|
public string LevelScene => _config.LevelScene;
|
2023-11-20 14:10:18 +08:00
|
|
|
|
|
|
|
|
|
|
public string MapDataPath => _config.MapData;
|
|
|
|
|
|
|
|
|
|
|
|
public float ShadowDistance => _config.ShadowDistance;
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2024-01-05 20:03:45 +08:00
|
|
|
|
public string StoryID => _config.StoryID;
|
2024-01-04 17:22:36 +08:00
|
|
|
|
|
2024-02-06 13:29:01 +08:00
|
|
|
|
//章节序号
|
|
|
|
|
|
public int ChapterIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_chapterIndex == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ID < 100000)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("关卡id为{0}的关卡id没到6位", ID);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var resultStr = ID.ToString().Substring(1, 2);
|
|
|
|
|
|
_chapterIndex = int.Parse(resultStr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _chapterIndex;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//关卡序号
|
|
|
|
|
|
public int LevelIndex
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_levelIndex == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ID < 100000)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError("关卡id为{0}的关卡id没到6位", ID);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var resultStr = ID.ToString().Substring(3, 3);
|
|
|
|
|
|
_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-01-04 17:22:36 +08:00
|
|
|
|
public WeatherType WeatherType => _levelData?.weatherType ?? WeatherType.Fog;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-01-04 17:22:36 +08:00
|
|
|
|
public DayNightType DayNightType => _levelData?.dayNightType ?? DayNightType.Day;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-01-04 17:22:36 +08:00
|
|
|
|
public EnvironmentType EnvironmentType => _mapData?.environmentType ?? EnvironmentType.Desert;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2023-11-01 13:33:20 +08:00
|
|
|
|
public bool IsLock { get; private 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-01-17 16:49:32 +08:00
|
|
|
|
public MapData MapData => _mapData ??= MapUtils.LoadMapData(MapDataPath);
|
2023-11-21 15:04:56 +08:00
|
|
|
|
|
2024-01-17 16:49:32 +08:00
|
|
|
|
public LevelData LevelData => _levelData ??= LevelUtils.LoadLevelData(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-02-06 13:29:01 +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-01-30 13:01:40 +08:00
|
|
|
|
public int StarCount => (int)(_serverData == null ? 0 : _serverData.StarCount);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
2024-01-30 15:10:12 +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
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public bool HasPass => _serverData == null ? false : _serverData.isPassed;
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2023-11-02 20:02:10 +08:00
|
|
|
|
public RedPointNode RedPointNode => _redPointNode;
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public LevelInfo(DataLevel config)
|
|
|
|
|
|
{
|
|
|
|
|
|
_config = config;
|
|
|
|
|
|
Load();
|
2023-11-01 13:33:20 +08:00
|
|
|
|
AddLockConditionReaction();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void Load()
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshServerData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"关卡消耗品不足,level id:{ID}");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RefreshServerData()
|
|
|
|
|
|
{
|
|
|
|
|
|
_serverData = Actor.Instance.Level.GetLevelInfo((uint)ID);
|
|
|
|
|
|
}
|
2023-11-01 13:33:20 +08:00
|
|
|
|
|
2023-11-02 20:02:10 +08:00
|
|
|
|
public void ConstructRedPointTree(RedPointNode parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
_redPointNode = RedPointManager.Instance.AddDynamicNode(NodeType.Level, parent, ID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
return starTarget[targetIndex].GetConditionLocalization();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-01 13:33:20 +08:00
|
|
|
|
private void AddLockConditionReaction()
|
|
|
|
|
|
{
|
|
|
|
|
|
ConditionReactor.Instance.AddReaction(UnLockCondition, OnUnlockConditionChanged);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnUnlockConditionChanged(bool result, object callBackParam, int reactionID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (result)
|
|
|
|
|
|
{
|
|
|
|
|
|
IsLock = false;
|
|
|
|
|
|
DebugUtil.Log($"[Level] level unlock,id:{ID}");
|
|
|
|
|
|
EventManager.Instance.Send<int>(EventManager.EventName.LevelUnlock, ID);
|
|
|
|
|
|
ConditionReactor.Instance.RemoveReaction(reactionID);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-10-24 14:58:21 +08:00
|
|
|
|
}
|