NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Level/LevelUtils.cs

189 lines
6.3 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using Framework;
2023-10-19 15:00:19 +08:00
using System.Collections.Generic;
2023-11-30 15:47:49 +08:00
using PhxhSDK.Phxh;
2023-08-22 19:08:45 +08:00
using static Gameplay.Level.LevelData;
2023-10-19 15:00:19 +08:00
using Constants = Framework.Constants;
2024-09-05 14:17:27 +08:00
using cfg.LevelCfg;
2023-08-22 19:08:45 +08:00
namespace Gameplay.Level
{
public static class LevelUtils
{
2024-01-04 17:22:36 +08:00
private const string SCENE_ORIGIN_PATH = "Assets/Scenes/Maps";
private const string SCENE_POSTPROCESS_PATH = "Assets/Art/AutoGen/Maps";
private const string SCENE_POST_PROCESS_NAME = "PostProcess";
2023-08-22 19:08:45 +08:00
2023-11-21 15:04:56 +08:00
// public static bool CheckEnterLevel(int levelId)
// {
// var configFilePath = GetLevelFilePath(levelId);
// if (AssetManager.Instance.CanLocateAsset(configFilePath))
// {
// return true;
// }
//
// else
// {
// return false;
// }
// }
2023-08-22 19:08:45 +08:00
2023-10-19 15:00:19 +08:00
public static string GetLevelFilePath(int id)
{
var cfg = TableManager.Instance.Tables.Level.DataMap.GetValueOrDefault(id);
if (cfg == null)
{
DebugUtil.LogError($"找不到level配置id:{id}");
return null;
}
2024-09-05 19:30:05 +08:00
return string.Format(Constants.LEVEL_CONFIG_FORMAT_PATH, cfg.LevelData);
2023-10-19 15:00:19 +08:00
}
public static LevelData LoadLevelData(int id)
2023-10-19 15:00:19 +08:00
{
var levelFilePath = GetLevelFilePath(id);
var levelData = JsonHelper.LoadFromAddressableSync<LevelData>(levelFilePath);
2023-10-19 15:00:19 +08:00
if (levelData == null)
{
2024-02-23 16:13:25 +08:00
DebugUtil.LogError("加载关卡配置失败,路径: {0}", levelFilePath);
2023-10-19 15:00:19 +08:00
}
return levelData;
}
2023-08-22 19:08:45 +08:00
public static float SetCharaterToward(CharacterToward npcToward)
{
switch (npcToward)
{
case CharacterToward.TopLeft:
{
return 0f;
2024-09-05 19:30:05 +08:00
2023-08-22 19:08:45 +08:00
}
case CharacterToward.TopRight:
{
return 60f;
}
case CharacterToward.Right:
{
return 120f;
}
case CharacterToward.BottomRight:
{
return 180f;
}
case CharacterToward.BottomLeft:
{
return -120f;
}
default:
{
return -60f;
}
}
}
2024-01-04 17:22:36 +08:00
2024-01-16 18:37:02 +08:00
// public static string GetPostProcessLevelScenePath(string scenePath)
// {
// var oldSceneDir = scenePath;
// var oldSceneName = Path.GetFileNameWithoutExtension(scenePath);
// var tempSceneDir = oldSceneDir.Replace( SCENE_ORIGIN_PATH, SCENE_POSTPROCESS_PATH);
// var subStr = tempSceneDir.Substring(SCENE_POSTPROCESS_PATH.Length + 1);
// var folderName = Path.GetFileNameWithoutExtension(subStr.Replace("/", "_"));
// var result = $"{SCENE_POSTPROCESS_PATH}/{folderName}/{oldSceneName}_{SCENE_POST_PROCESS_NAME}.unity";
// return result;
// }
2024-09-05 14:17:27 +08:00
/// <summary>
/// 获取战役关卡评级
/// </summary>
/// <returns></returns>
2024-09-05 15:48:15 +08:00
public static E_WarRating GetWarLevelRatingByLevelId(int levelId)
2024-09-05 14:17:27 +08:00
{
if (!LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo))
{
DebugUtil.LogError($"获取关卡信息错误,关卡id{levelId}");
2024-09-05 15:48:15 +08:00
return E_WarRating.C;
2024-09-05 14:17:27 +08:00
}
2024-09-05 15:48:15 +08:00
return GetWarLevelRatingByLevelInfo(levelInfo);
2024-09-05 14:17:27 +08:00
}
/// <summary>
/// 获取战役关卡评级
/// </summary>
/// <returns></returns>
2024-09-05 15:48:15 +08:00
public static E_WarRating GetWarLevelRatingByLevelInfo(LevelInfo levelInfo)
2024-09-05 14:17:27 +08:00
{
if (null == levelInfo)
{
DebugUtil.LogError($"获取评级错误,空数据");
2024-09-05 15:48:15 +08:00
return E_WarRating.C;
2024-09-05 14:17:27 +08:00
}
if (E_ChapterType.War != levelInfo.ChapterInfo.Cfg.Type)
{
DebugUtil.LogError($"获取评级错误,不是战役关卡,关卡id{levelInfo.Cfg.Id}");
2024-09-05 15:48:15 +08:00
return E_WarRating.C;
2024-09-05 14:17:27 +08:00
}
2024-09-05 19:30:05 +08:00
return GetRatingByScore(levelInfo.Score, levelInfo.ScoreMax);
2024-09-05 15:48:15 +08:00
}
/// <summary>
/// 获取战役关卡组评级
/// </summary>
/// <returns></returns>
public static E_WarRating GetWarLevelRatingByLeveGrouplId(int levelGroupId)
{
if (!LevelManager.Instance.TryGetLevelGroupInfoByID(levelGroupId, out LevelGroupInfo levelGroupInfo))
2024-09-05 14:48:22 +08:00
{
2024-09-05 15:48:15 +08:00
DebugUtil.LogError($"获取关卡组信息错误,关卡id{levelGroupId}");
return E_WarRating.C;
2024-09-05 14:48:22 +08:00
}
2024-09-05 15:48:15 +08:00
return GetWarLevelRatingByLevelGroupInfo(levelGroupInfo);
}
/// <summary>
/// 获取战役关卡组评级
/// </summary>
/// <returns></returns>
public static E_WarRating GetWarLevelRatingByLevelGroupInfo(LevelGroupInfo levelGroupInfo)
{
if (null == levelGroupInfo)
{
DebugUtil.LogError($"获取评级错误,空数据");
return E_WarRating.C;
}
if (E_ChapterType.War != levelGroupInfo.ChapterInfo.Cfg.Type)
{
DebugUtil.LogError($"获取评级错误,不是战役关卡组,关卡组id{levelGroupInfo.Cfg.Id}");
return E_WarRating.C;
}
2024-09-05 19:30:05 +08:00
return GetRatingByScore(levelGroupInfo.Score, levelGroupInfo.ScoreMax);
}
/// <summary>
/// 获取评级根据分数
/// </summary>
/// <param name="score"></param>
/// <param name="maxScore"></param>
/// <returns></returns>
public static E_WarRating GetRatingByScore(int score, int maxScore)
{
float percentage = 0 >= maxScore ? 0f : (float)score / maxScore;
2024-09-05 14:17:27 +08:00
List<float> listRating = TableManager.Instance.Tables.GlobalConfig.CampaignScoreClass;
2024-09-05 15:48:15 +08:00
for (int i = listRating.Count - 1; i >= 0; --i)
2024-09-05 14:48:22 +08:00
{
if (percentage < listRating[i])
continue;
2024-09-05 15:48:15 +08:00
return (E_WarRating)i;
2024-09-05 14:48:22 +08:00
}
2024-09-05 14:17:27 +08:00
2024-09-05 15:48:15 +08:00
return E_WarRating.C;
2024-09-05 14:17:27 +08:00
}
2023-08-22 19:08:45 +08:00
}
}