载入中...
搜索中...
未找到
AttributeTypes.h
浏览该文件的文档.
1#pragma once
2
3// 属性系统的纯数据类型 + 纯函数计算核心。
4//
5// 设计要点(对应"高度灵活可定制化"目标):
6// 1. 属性名不是枚举,而是任意字符串 —— 新增属性无需修改引擎代码。
7// 2. 修改器(modifier)的运算方式(op)同样是字符串:内置几种常见语义,
8// 同时允许通过 AttributeSystem::registerOp() 注册任意自定义运算,
9// 使得游戏可以在不修改引擎源码的情况下扩展全新的数值叠加规则。
10// 3. computeAttributeValue() 是不依赖 ECS 的纯函数,方便单元测试与脚本外验证。
11
12#include <string>
13#include <vector>
14
15namespace eve::rpg {
16
31 std::string id;
32 std::string source;
33 std::string op = "add";
34 double value = 0.0;
35 int priority = 0;
36};
37
40 double base = 0.0;
41 std::vector<AttributeModifier> modifiers;
42 mutable double cached = 0.0;
43 mutable bool dirty = true;
44};
45
51 const struct AttributeOpTable *customOps = nullptr);
52
53} // namespace eve::rpg
自定义 op 注册表:opName -> f(currentResult, modifierValue) -> newResult。
RPG 模块入口:属性 / 效果 / 状态 / 技能 / 结算五套系统的脚本绑定与帧调度点。
double computeAttributeValue(const AttributeValue &attr, const AttributeOpTable *customOps)
单条修改器。附加在某个属性上,参与最终值计算。
std::string source
来源标签(如 "effect:12" / "skill:fireball" / 自定义),用于批量移除
std::string id
唯一 id(由 AttributeSystem 生成),用于精确移除
int priority
计算顺序,数值小的先应用;同优先级按插入顺序
单个属性的完整状态:基础值 + 修改器列表 + 计算结果缓存。
std::vector< AttributeModifier > modifiers