166 lines
3.9 KiB
C#
166 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
using Models;
|
|
|
|
namespace Core;
|
|
|
|
/// <summary>
|
|
/// 学科定义资源(先落地一个完整示例)
|
|
/// 设计说明:
|
|
/// 1) 为避免 .tres 过度嵌套,字段保持扁平化。
|
|
/// 2) Buff 规则通过 RuleIds 存储,数值效果可后续用 JSON 增补。
|
|
/// 注意事项:
|
|
/// - Id 与资源路径应稳定且小写下划线。
|
|
/// 未来扩展:
|
|
/// - 可补充 Modifiers/AllowedRoles 等字段,进一步丰富配置能力。
|
|
/// </summary>
|
|
[GlobalClass]
|
|
public partial class DisciplineDefinitionResource : Resource, IContentResource
|
|
{
|
|
// --- Header ---
|
|
/// <summary>
|
|
/// 学科ID
|
|
/// </summary>
|
|
[Export] public string Id { get; set; }
|
|
/// <summary>
|
|
/// 名称键值
|
|
/// </summary>
|
|
[Export] public string NameKey { get; set; }
|
|
/// <summary>
|
|
/// 名称默认值
|
|
/// </summary>
|
|
[Export] public string NameFallback { get; set; }
|
|
/// <summary>
|
|
/// 描述键值
|
|
/// </summary>
|
|
[Export] public string DescriptionKey { get; set; }
|
|
/// <summary>
|
|
/// 描述默认值
|
|
/// </summary>
|
|
[Export] public string DescriptionFallback { get; set; }
|
|
/// <summary>
|
|
/// 图标路径
|
|
/// </summary>
|
|
[Export] public string IconPath { get; set; }
|
|
/// <summary>
|
|
/// 标签列表
|
|
/// </summary>
|
|
[Export] public Array<string> Tags { get; set; } = new();
|
|
|
|
// --- Buff ---
|
|
/// <summary>
|
|
/// Buff名称键值
|
|
/// </summary>
|
|
[Export] public string BuffNameKey { get; set; }
|
|
/// <summary>
|
|
/// Buff名称默认值
|
|
/// </summary>
|
|
[Export] public string BuffNameFallback { get; set; }
|
|
/// <summary>
|
|
/// Buff描述键值
|
|
/// </summary>
|
|
[Export] public string BuffDescriptionKey { get; set; }
|
|
/// <summary>
|
|
/// Buff描述默认值
|
|
/// </summary>
|
|
[Export] public string BuffDescriptionFallback { get; set; }
|
|
/// <summary>
|
|
/// Buff规则ID列表
|
|
/// </summary>
|
|
[Export] public Array<string> BuffRuleIds { get; set; } = new();
|
|
|
|
// --- Pools ---
|
|
/// <summary>
|
|
/// 角色池ID列表
|
|
/// </summary>
|
|
[Export] public Array<string> RolePoolIds { get; set; } = new();
|
|
/// <summary>
|
|
/// 物品池ID列表
|
|
/// </summary>
|
|
[Export] public Array<string> ItemPoolIds { get; set; } = new();
|
|
/// <summary>
|
|
/// 任务关键词ID列表
|
|
/// </summary>
|
|
[Export] public Array<string> TaskKeywordIds { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// 获取定义类型
|
|
/// </summary>
|
|
/// <returns>类型</returns>
|
|
public Type GetDefinitionType() => typeof(DisciplineDefinition);
|
|
|
|
/// <summary>
|
|
/// 转换为定义对象
|
|
/// </summary>
|
|
/// <returns>定义对象</returns>
|
|
public object ToDefinition()
|
|
{
|
|
var header = new DefinitionHeader
|
|
{
|
|
Id = Id,
|
|
IconPath = IconPath,
|
|
Name = new LocalizedText
|
|
{
|
|
Key = NameKey,
|
|
Fallback = NameFallback
|
|
},
|
|
Description = new LocalizedText
|
|
{
|
|
Key = DescriptionKey,
|
|
Fallback = DescriptionFallback
|
|
}
|
|
};
|
|
|
|
foreach (var tag in Tags)
|
|
{
|
|
header.Tags.Add(tag);
|
|
}
|
|
|
|
var buff = new DisciplineBuff
|
|
{
|
|
Name = new LocalizedText
|
|
{
|
|
Key = BuffNameKey,
|
|
Fallback = BuffNameFallback
|
|
},
|
|
Description = new LocalizedText
|
|
{
|
|
Key = BuffDescriptionKey,
|
|
Fallback = BuffDescriptionFallback
|
|
},
|
|
Modifiers = new ModifierBundle()
|
|
};
|
|
|
|
foreach (var ruleId in BuffRuleIds)
|
|
{
|
|
buff.Modifiers.RuleIds.Add(ruleId);
|
|
}
|
|
|
|
var definition = new DisciplineDefinition
|
|
{
|
|
Header = header,
|
|
Buff = buff
|
|
};
|
|
|
|
AddRange(RolePoolIds, definition.RolePoolIds);
|
|
AddRange(ItemPoolIds, definition.ItemPoolIds);
|
|
AddRange(TaskKeywordIds, definition.TaskKeywordIds);
|
|
|
|
return definition;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加范围
|
|
/// </summary>
|
|
/// <param name="source">源数组</param>
|
|
/// <param name="target">目标列表</param>
|
|
private static void AddRange(Array<string> source, List<string> target)
|
|
{
|
|
foreach (var value in source)
|
|
{
|
|
target.Add(value);
|
|
}
|
|
}
|
|
} |