NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/GameWrapper/Level/LevelData.cs

303 lines
10 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using System;
using UnityEngine;
2024-06-04 16:50:16 +08:00
using Sirenix.OdinInspector;
using System.Collections.Generic;
using System.Runtime.Serialization;
2023-08-22 19:08:45 +08:00
namespace Gameplay.Level
{
[Serializable]
public class LevelData
{
[Serializable]
2025-05-28 15:55:33 +08:00
public class Task
2023-08-22 19:08:45 +08:00
{
2025-05-28 15:55:33 +08:00
[LabelText("任务ID")] public int taskId;
[LabelText("任务类型")] public TaskType taskType;
[LabelText("任务名称")] public string taskNameKey;
[LabelText("任务描述")] public string taskDescKey;
[LabelText("任务目标")] [ListDrawerSettings(CustomAddFunction = "OnAddCondition")]
public List<ConditionModifier> taskConditions = new();
[LabelText("前置任务ID")] public int preTaskId = -1;
[LabelText("后置任务ID")] public int postTaskId = -1;
[LabelText("阻拦区域ID")] public int blockRegionId = -1;
private void OnAddCondition()
{
ConditionModifier conditionModifier = new();
2025-05-28 16:24:06 +08:00
conditionModifier.SetFilterTypes(ConditionUtil.AllLevelConditionFilter);
2025-05-28 15:55:33 +08:00
taskConditions.Add(conditionModifier);
}
2024-11-12 20:31:06 +08:00
2025-05-28 15:55:33 +08:00
[OnDeserialized]
public void OnAfterDeserialize(StreamingContext context)
{
foreach (var conditionModifier in taskConditions)
{
2025-05-28 16:24:06 +08:00
conditionModifier.SetFilterTypes(ConditionUtil.AllLevelConditionFilter);
2025-05-28 15:55:33 +08:00
}
}
}
[Serializable]
public class Stage
{
// TODO 舍弃
[HideInInspector] [LabelText("胜利条件")]
2023-11-21 15:04:56 +08:00
public ConditionModifier successCondition = new(ConditionUtil.LevelSuccessConditionFilter);
2024-11-12 20:31:06 +08:00
2025-05-28 16:24:06 +08:00
// TODO 舍弃
[HideInInspector] [LabelText("失败条件")] [ListDrawerSettings(CustomAddFunction = "OnAddFailCondition")]
2023-11-06 18:20:55 +08:00
public List<ConditionModifier> failConditions = new();
2025-05-28 16:24:06 +08:00
[LabelText("胜利目标")] public int successTaskID;
2025-05-28 16:24:06 +08:00
[LabelText("失败目标")] public int failTaskID;
2024-11-12 20:31:06 +08:00
2025-05-28 15:55:33 +08:00
[LabelText("任务列表")] [ListDrawerSettings(CustomAddFunction = "OnAddTask")]
public List<Task> tasks = new();
2023-11-06 18:20:55 +08:00
private void OnAddFailCondition()
{
2023-11-06 19:18:24 +08:00
ConditionModifier conditionModifier = new();
conditionModifier.SetFilterTypes(ConditionUtil.LevelFailConditionFilter);
2023-11-06 18:20:55 +08:00
failConditions.Add(conditionModifier);
}
2024-11-12 20:31:06 +08:00
2025-05-28 15:55:33 +08:00
private void OnAddTask()
{
var task = new Task
{
taskId = tasks.Count + 1 // 任务ID从1开始
};
tasks.Add(task);
}
2023-11-06 19:18:24 +08:00
[OnDeserialized]
public void OnAfterDeserialize(System.Runtime.Serialization.StreamingContext context)
{
successCondition.SetFilterTypes(ConditionUtil.LevelSuccessConditionFilter);
foreach (var failCondition in failConditions)
{
failCondition.SetFilterTypes(ConditionUtil.LevelFailConditionFilter);
}
}
2023-08-22 19:08:45 +08:00
}
2024-11-12 20:31:06 +08:00
2023-08-22 19:08:45 +08:00
[Serializable]
public class NPCInfo
2024-11-12 20:31:06 +08:00
{
2024-11-13 13:21:36 +08:00
[HideInInspector] public int index;
2024-11-12 20:31:06 +08:00
[HideInInspector] public int id;
2025-05-28 15:55:33 +08:00
2025-04-07 14:34:27 +08:00
// 仅供展示
2024-11-12 20:31:06 +08:00
[ReadOnly] public int level;
[ReadOnly] [LabelText("位置")] public Vector2Int position;
[LabelText("初始护盾")] public float shield;
[LabelText("初始血量")] public float ph;
[LabelText("初始士气")] public float morale;
[LabelText("Buff")] public List<int> buff = new List<int>();
[LabelText("DeBuff")] public List<int> deBuff = new List<int>();
[LabelText("AI类型")] public AIType aIType = AIType.None;
[LabelText("特殊触发AI")] public AttachAIType attachAIType;
[HideInInspector] public CharacterToward npcToward;
[LabelText("巡逻信息")] public List<PatrolInfo> patrolInfos = new List<PatrolInfo>(4);
2024-07-22 14:46:20 +08:00
[LabelText("编组")] public List<int> groups = new List<int>(4);
2024-12-04 18:49:20 +08:00
[LabelText("防守距离")] public int defensiveDistance;
2025-02-17 17:11:38 +08:00
[HideInInspector] public string configName;
2025-02-24 19:26:18 +08:00
[LabelText("是否为中途生成AI")] public bool isHideOnLoad;
[LabelText("所属波数")] public int waveIndex;
[LabelText("所属防守区域")] public int defenseRegionIndex;
2023-10-19 15:00:19 +08:00
}
[Serializable]
public class PatrolInfo
{
2024-11-12 20:31:06 +08:00
[HorizontalGroup("PatrolInfo")] [LabelText("巡逻点位")]
2023-10-19 15:00:19 +08:00
public Vector2Int patrolPoint;
2024-11-12 20:31:06 +08:00
[HorizontalGroup("PatrolInfo")] [LabelText("等待时间")]
public float waitTime = 0f;
2023-08-22 19:08:45 +08:00
}
[Serializable]
2025-05-30 16:42:07 +08:00
public class SpawnMonsterData
{
[LabelText("刷新方式")] public ELevelUnitGenType refreshType = ELevelUnitGenType.Default;
[LabelText("间隔时间")] [ShowIf("@refreshType==ELevelUnitGenType.TimeLoop")]
public int refreshInterval;
[LabelText("最大次数 (-1无限循环)")] [ShowIf("@refreshType==ELevelUnitGenType.TimeLoop")]
public int maxCount;
[LabelText("最大波次 (-1无限循环)")]
[ShowIf("@refreshType==ELevelUnitGenType.KillLoop")]
public int waveMaxCount;
}
2023-08-22 19:08:45 +08:00
2025-02-21 17:03:56 +08:00
[Serializable]
public class PrescribedRoadInfo
{
public int roadID;
public List<int> cellIndex = new List<int>();
}
[Serializable]
public class LevelTriggerData
{
[LabelText("触发类型")] public ELevelTriggerType levelTriggerType = ELevelTriggerType.Default;
[LabelText("刷怪波次")] public int wave;
[LabelText("参数 (时间/区域ID)")] public int triggerTime = 0;
}
2025-05-28 15:55:33 +08:00
public enum TaskType
{
MainTask,
SideTask,
}
2023-08-22 19:08:45 +08:00
public enum CharacterToward
{
TopLeft,
TopRight,
Right,
BottomRight,
BottomLeft,
Left,
}
public enum AIType
{
BasicAI,
FallBackAI,
2023-10-19 15:00:19 +08:00
FallBackIntensifyAI,
2023-08-22 19:08:45 +08:00
OutflankAI,
2024-12-04 18:49:20 +08:00
DefendAI,
2025-02-21 17:03:56 +08:00
StupidDefendAI,
2024-11-12 20:31:06 +08:00
None,
2023-08-22 19:08:45 +08:00
}
public enum AttachAIType
{
None,
ChainAI,
ProvokeAI,
SpecialBehaviorAI,
2024-12-05 16:05:12 +08:00
AttackProtectUnitAI,
2023-08-22 19:08:45 +08:00
}
2023-11-21 15:04:56 +08:00
public LevelData()
{
2023-08-22 19:08:45 +08:00
}
2024-11-12 20:31:06 +08:00
[LabelText("出战区")] [HideInInspector] public int preparingRegionId;
2023-08-22 19:08:45 +08:00
2024-11-12 20:31:06 +08:00
[LabelText("出战区朝向")] [HideInInspector] public CharacterToward preparingRegionToward;
2023-08-22 19:08:45 +08:00
2024-11-12 20:31:06 +08:00
[LabelText("撤退区")] [HideInInspector] public int fallbackRegionId;
2023-08-22 19:08:45 +08:00
2024-11-12 20:31:06 +08:00
[LabelText("敌方撤退区")] [HideInInspector] public int enemyFallbackRegionId;
[LabelText("PVP防守区")] [HideInInspector]
2023-12-26 18:19:05 +08:00
public int pvpDefendRegionId;
2024-11-12 20:31:06 +08:00
[LabelText("PVP防守方朝向")] [HideInInspector]
2023-12-26 18:19:05 +08:00
public CharacterToward pvpDefendToward;
2023-10-19 15:00:19 +08:00
2025-05-28 15:55:33 +08:00
// TODO 暂时舍弃
[HideInInspector] [LabelText("阶段")] public List<Stage> stages = new List<Stage>(8);
[BoxGroup("主线")] [LabelText("关卡任务")] public Stage stage;
2023-08-22 19:08:45 +08:00
[BoxGroup("支线")] [LabelText("设置该关卡为评分关卡")]
public bool scoreLevel = false;
2024-08-27 14:18:39 +08:00
2025-05-28 17:49:04 +08:00
[BoxGroup("支线")]
[LabelText("星级目标"), HideIf("scoreLevel")]
[ListDrawerSettings(HideAddButton = true, HideRemoveButton = true)]
public List<ConditionModifier> starTarget = new()
{
new ConditionModifier(ConditionUtil.LevelStarConditionFilter),
new ConditionModifier(ConditionUtil.LevelStarConditionFilter),
new ConditionModifier(ConditionUtil.LevelStarConditionFilter)
};
2024-08-27 14:18:39 +08:00
[BoxGroup("支线")]
[LabelText("评分目标"), ShowIf("scoreLevel")]
[ListDrawerSettings(CustomAddFunction = "OnAddScoreCondition")]
2024-08-27 14:18:39 +08:00
public List<ConditionModifier> scoreTarget = new List<ConditionModifier>(15);
private void OnAddScoreCondition()
{
ConditionModifier conditionModifier = new();
conditionModifier.SetFilterTypes(ConditionUtil.LevelScoreConditionFilter, true);
scoreTarget.Add(conditionModifier);
}
2024-06-04 16:50:16 +08:00
[BoxGroup("防守相关设置")] [LabelText("防守关卡数据")]
2025-05-30 16:42:07 +08:00
public List<SpawnMonsterData> spawnMonsterDatas;
[BoxGroup("防守相关设置")] [LabelText("关卡触发器")]
public List<LevelTriggerData> levelTriggerDatas;
2025-02-21 17:03:56 +08:00
/// <summary>
/// 刷新生成点位
/// </summary>
[HideInInspector] public List<int> refreshPoints = new List<int>();
/// <summary>
/// 指定路线
/// </summary>
[HideInInspector] public List<PrescribedRoadInfo> roadInfos = new List<PrescribedRoadInfo>(4);
[HideInInspector] public List<NPCInfo> npcInfos = new();
2024-11-12 20:31:06 +08:00
[HideInInspector] public List<NPCInfo> selfNpcInfos = new();
2024-11-12 20:31:06 +08:00
2024-11-25 13:39:03 +08:00
[Serializable]
public class CaptureInfo
{
2024-11-12 20:31:06 +08:00
[LabelText("占领点位")] public int CapturePoint;
[LabelText("占领时间")] public int CaptureProgress = 0;
}
2024-11-12 20:31:06 +08:00
[HideInInspector] public List<CaptureInfo> CapturePoints = new(8);
2024-11-12 20:31:06 +08:00
2024-11-07 15:05:36 +08:00
[HideInInspector] public List<int> flagStartPoints = new List<int>();
2024-11-12 20:31:06 +08:00
[HideInInspector] public List<int> flagEndPoints = new List<int>();
2024-11-12 20:31:06 +08:00
2024-11-11 13:46:47 +08:00
[HideInInspector] public List<int> fallbackSinglePoints = new List<int>();
2024-11-12 20:31:06 +08:00
2024-11-11 13:46:47 +08:00
[HideInInspector] public List<int> fallbackReusablePoints = new List<int>();
2024-11-12 20:31:06 +08:00
2024-11-26 16:58:42 +08:00
[HideInInspector] public int fallBackCount;
2023-11-08 15:05:19 +08:00
[OnDeserialized]
public void OnAfterDeserialize(StreamingContext context)
{
2023-11-21 15:04:56 +08:00
if (starTarget.Count != 3)
{
starTarget.Clear();
starTarget.Add(new ConditionModifier());
starTarget.Add(new ConditionModifier());
starTarget.Add(new ConditionModifier());
}
2024-11-12 20:31:06 +08:00
2023-11-08 15:05:19 +08:00
foreach (var starCondition in starTarget)
{
starCondition.SetFilterTypes(ConditionUtil.LevelStarConditionFilter);
}
2024-11-12 20:31:06 +08:00
2024-11-01 18:33:42 +08:00
foreach (var scoreCondition in scoreTarget)
{
scoreCondition.SetFilterTypes(ConditionUtil.LevelScoreConditionFilter, scoreLevel);
}
2023-11-08 15:05:19 +08:00
}
2023-08-22 19:08:45 +08:00
}
}