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

153 lines
5.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Framework;
using System.Collections.Generic;
using PhxhSDK.Phxh;
using static Gameplay.Level.LevelData;
using Constants = Framework.Constants;
using cfg.LevelCfg;
namespace Gameplay.Level
{
public static class LevelUtils
{
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";
// public static bool CheckEnterLevel(int levelId)
// {
// var configFilePath = GetLevelFilePath(levelId);
// if (AssetManager.Instance.CanLocateAsset(configFilePath))
// {
// return true;
// }
//
// else
// {
// return false;
// }
// }
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;
}
return string.Format(Constants.LEVEL_CONFIG_FORMAT_PATH,cfg.LevelData);
}
public static LevelData LoadLevelData(int id)
{
var levelFilePath = GetLevelFilePath(id);
var levelData = JsonHelper.LoadFromAddressableSync<LevelData>(levelFilePath);
if (levelData == null)
{
DebugUtil.LogError("加载关卡配置失败,路径: {0}", levelFilePath);
}
return levelData;
}
public static float SetCharaterToward(CharacterToward npcToward)
{
switch (npcToward)
{
case CharacterToward.TopLeft:
{
return 0f;
}
case CharacterToward.TopRight:
{
return 60f;
}
case CharacterToward.Right:
{
return 120f;
}
case CharacterToward.BottomRight:
{
return 180f;
}
case CharacterToward.BottomLeft:
{
return -120f;
}
default:
{
return -60f;
}
}
}
// 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;
// }
/// <summary>
/// 获取战役关卡评级
/// </summary>
/// <returns></returns>
public static string GetWarLevelRatingById(int levelId)
{
if (!LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo))
{
DebugUtil.LogError($"获取关卡信息错误,关卡id{levelId}");
return "C";
}
return GetWarLevelRatingByInfo(levelInfo);
}
/// <summary>
/// 获取战役关卡评级
/// </summary>
/// <returns></returns>
public static string GetWarLevelRatingByInfo(LevelInfo levelInfo)
{
if (null == levelInfo)
{
DebugUtil.LogError($"获取评级错误,空数据");
return "C";
}
if (E_ChapterType.War != levelInfo.ChapterInfo.Cfg.Type)
{
DebugUtil.LogError($"获取评级错误,不是战役关卡,关卡id{levelInfo.Cfg.Id}");
return "C";
}
int total = 0;
foreach (ConditionModifier conditionModifier in levelInfo.LevelData.scoreTarget)
{
total += conditionModifier.score;
}
float percentage = 0 >= total ? 1f : (float)levelInfo.Score / total;
List<float> listRating = TableManager.Instance.Tables.GlobalConfig.CampaignScoreClass;
for (int i = listRating.Count-1; i >= 0; ++i)
{
if (percentage < listRating[i])
continue;
return i switch
{
1 => "B",
2 => "A",
3 => "S",
_ => "C",
};
}
return "C";
}
}
}