95 lines
4.9 KiB
C#
95 lines
4.9 KiB
C#
using UnityEngine;
|
||
using PhxhSDK.Editor.FileChecker.Data;
|
||
using Gameplay.Level;
|
||
using PhxhSDK.Phxh;
|
||
using Framework;
|
||
using Gameplay.Character;
|
||
|
||
namespace PhxhSDK.Editor.FileChecker
|
||
{
|
||
/// <summary>
|
||
/// 关卡文件npc检查器
|
||
/// 检查关卡json文件的npc配置是否正确
|
||
/// </summary>
|
||
public class LevelFileNpcChecker : BaseLevelChecker
|
||
{
|
||
public override string CheckerName => "关卡文件npc检查";
|
||
public override string RecommendedHandling => "修改关卡文件npc配置";
|
||
public override CheckerTabType belongTab => CheckerTabType.Level;
|
||
public override bool HasAutoProgress => false;
|
||
|
||
public override string CheckLevel(string filePath, TextAsset textAsset)
|
||
{
|
||
string res = string.Empty;
|
||
|
||
if (null == textAsset)
|
||
return "文件加载失败";
|
||
|
||
LevelData levelData = JsonHelper.LoadJsonFromText<LevelData>(textAsset.text);
|
||
if(null == levelData)
|
||
return $"关卡json反序列化为{nameof(LevelData)}失败";
|
||
|
||
foreach (var npcInfo in levelData.npcInfos)
|
||
{
|
||
var monsterCfg = TableManager.Instance.Tables.Monster.Get(npcInfo.id);
|
||
if (null == monsterCfg)
|
||
res += $"敌方npc在配置表中不存在,id:{npcInfo.id}\n";
|
||
|
||
if (ETroopsId.Enemy != npcInfo.troopId)
|
||
res += $"敌方npc:{npcInfo.id},阵营错误,正确阵营:{ETroopsId.Enemy},当前阵营:{npcInfo.troopId}\n";
|
||
|
||
if (0 <= npcInfo.patrolRoadID && !levelData.patrolRoadData.Exists(data => data.id == npcInfo.patrolRoadID))
|
||
res += $"敌方npc:{npcInfo.id},使用巡逻路径不存在,巡逻路径id:{npcInfo.patrolRoadID}\n";
|
||
|
||
if (0 <= npcInfo.presetPathId && !levelData.patrolRoadData.Exists(data => data.id == npcInfo.presetPathId))
|
||
res += $"敌方npc:{npcInfo.id},使用预设路径不存在,预设路径id:{npcInfo.presetPathId}\n";
|
||
|
||
if (0 <= npcInfo.specifyRegionID && !levelData.patrolRegionData.Exists(data => data.id == npcInfo.specifyRegionID))
|
||
res += $"敌方npc:{npcInfo.id},使用区域不存在,区域id:{npcInfo.specifyRegionID}\n";
|
||
}
|
||
|
||
foreach (var npcInfo in levelData.selfNpcInfos)
|
||
{
|
||
var monsterCfg = TableManager.Instance.Tables.Monster.Get(npcInfo.id);
|
||
if (null == monsterCfg)
|
||
res += $"我方npc在配置表中不存在,id:{npcInfo.id}\n";
|
||
|
||
if (ETroopsId.Self != npcInfo.troopId)
|
||
res += $"我方npc:{npcInfo.id},阵营错误,正确阵营:{ETroopsId.Self},当前阵营:{npcInfo.troopId}\n";
|
||
|
||
if (0 <= npcInfo.patrolRoadID && !levelData.patrolRoadData.Exists(data => data.id == npcInfo.patrolRoadID))
|
||
res += $"我方npc:{npcInfo.id},使用巡逻路径不存在,巡逻路径id:{npcInfo.patrolRoadID}\n";
|
||
|
||
if (0 <= npcInfo.presetPathId && !levelData.patrolRoadData.Exists(data => data.id == npcInfo.presetPathId))
|
||
res += $"我方npc:{npcInfo.id},使用预设路径不存在,预设路径id:{npcInfo.presetPathId}\n";
|
||
|
||
if (0 <= npcInfo.specifyRegionID && !levelData.patrolRegionData.Exists(data => data.id == npcInfo.specifyRegionID))
|
||
res += $"我方npc:{npcInfo.id},使用区域不存在,区域id:{npcInfo.specifyRegionID}\n";
|
||
}
|
||
|
||
foreach (var npcInfo in levelData.midNpcInfos)
|
||
{
|
||
var monsterCfg = TableManager.Instance.Tables.Monster.Get(npcInfo.id);
|
||
if (null == monsterCfg)
|
||
res += $"中立npc在配置表中不存在,id:{npcInfo.id}\n";
|
||
|
||
if (ETroopsId.Neutral != npcInfo.troopId)
|
||
res += $"中立npc:{npcInfo.id},阵营错误,正确阵营:{ETroopsId.Neutral},当前阵营:{npcInfo.troopId}\n";
|
||
|
||
if (0 <= npcInfo.patrolRoadID && !levelData.patrolRoadData.Exists(data => data.id == npcInfo.patrolRoadID))
|
||
res += $"中立npc:{npcInfo.id},使用巡逻路径不存在,巡逻路径id:{npcInfo.patrolRoadID}\n";
|
||
|
||
if (0 <= npcInfo.presetPathId && !levelData.patrolRoadData.Exists(data => data.id == npcInfo.presetPathId))
|
||
res += $"中立npc:{npcInfo.id},使用预设路径不存在,预设路径id:{npcInfo.presetPathId}\n";
|
||
|
||
if (0 <= npcInfo.specifyRegionID && !levelData.patrolRegionData.Exists(data => data.id == npcInfo.specifyRegionID))
|
||
res += $"中立npc:{npcInfo.id},使用区域不存在,区域id:{npcInfo.specifyRegionID}\n";
|
||
}
|
||
|
||
if (res.Equals(string.Empty))
|
||
return null;
|
||
else
|
||
return res;
|
||
}
|
||
}
|
||
} |