2023-10-19 15:00:19 +08:00
|
|
|
|
using cfg.LevelCfg;
|
|
|
|
|
|
using Gameplay;
|
|
|
|
|
|
using Gameplay.Level;
|
|
|
|
|
|
using Gameplay.Net;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
#region config
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public int ID => _config.Id;
|
|
|
|
|
|
|
|
|
|
|
|
public int Index => _config.Index;
|
|
|
|
|
|
|
|
|
|
|
|
public int ChapterID => _config.ChapterID;
|
|
|
|
|
|
|
|
|
|
|
|
//解锁条件
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
public string FileName => _config.FileName;
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Data
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public WeatherType WeatherType => _levelData.weatherType;
|
|
|
|
|
|
|
|
|
|
|
|
public DayNightType DayNightType => _levelData.dayNightType;
|
|
|
|
|
|
|
|
|
|
|
|
public EnvironmentType EnvironmentType => _mapData.environmentType;
|
|
|
|
|
|
|
|
|
|
|
|
public bool Lock => IsLock();
|
|
|
|
|
|
|
|
|
|
|
|
public bool CostEnough => IsConstEnough();
|
|
|
|
|
|
|
|
|
|
|
|
public bool CanEnter => !Lock && CostEnough;
|
2023-10-24 14:58:21 +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-10-19 15:00:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public LevelInfo(DataLevel config)
|
|
|
|
|
|
{
|
|
|
|
|
|
_config = config;
|
|
|
|
|
|
Load();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async void Load()
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshServerData();
|
|
|
|
|
|
_levelData = await LevelUtils.LoadLevelData(ID);
|
|
|
|
|
|
_mapData = await MapUtils.LoadMapData(_levelData.mapName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsLock()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (UnLockCondition == null || UnLockCondition.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2023-10-24 14:58:21 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
var allConditionPass = true;
|
|
|
|
|
|
foreach (var unlockID in UnLockCondition)
|
|
|
|
|
|
{
|
|
|
|
|
|
var conditionResult = Actor.Instance.Unlock.IsUnlock((uint)unlockID) == (uint)NLDPB.OpResult.Ok;
|
|
|
|
|
|
allConditionPass = allConditionPass && conditionResult;
|
|
|
|
|
|
if (!allConditionPass)
|
|
|
|
|
|
{
|
2023-10-26 20:20:11 +08:00
|
|
|
|
//Debug.Log($"关卡进入条件不满足,level id:{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 !allConditionPass;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-10-24 14:58:21 +08:00
|
|
|
|
}
|