2023-10-19 15:00:19 +08:00
|
|
|
|
using cfg.LevelCfg;
|
|
|
|
|
|
using Gameplay;
|
|
|
|
|
|
using Gameplay.Level;
|
|
|
|
|
|
using Gameplay.Net;
|
|
|
|
|
|
using System.Collections.Generic;
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
//解锁条件
|
|
|
|
|
|
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-04 17:22:36 +08:00
|
|
|
|
public string LevelScene => LevelUtils.GetPostProcessLevelScenePath(_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
|
|
|
|
|
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-10 13:40:07 +08:00
|
|
|
|
public async UniTask<MapData> GetMapData()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_mapData == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_mapData = await MapUtils.LoadMapData(MapDataPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _mapData;
|
|
|
|
|
|
}
|
2023-11-21 15:04:56 +08:00
|
|
|
|
|
2024-01-10 13:40:07 +08:00
|
|
|
|
public async UniTask<LevelData> GetLevelData()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_levelData == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_levelData = await LevelUtils.LoadLevelData(ID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _levelData;
|
|
|
|
|
|
}
|
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
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Server Data
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public int StarCount => (int)(_serverData == null ? 0 : _serverData.star);
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
}
|