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