载入中...
搜索中...
未找到
Settlement.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5// 结算系统:把伤害/治疗/命中率/掉落……等一切"多方参与、需要按顺序层层计算"的
6// 数值流程抽象成一条可插拔的流水线(SettlementPipeline),而不是把某一种
7// 伤害公式写死在引擎里。
8//
9// 用法:
10// 1. C++ 侧(游戏或插件代码)通过 registerStage() 往某个流水线(用字符串命名,
11// 如 "damage"/"heal",或游戏自定义的任意名字)里插入若干计算阶段;
12// 每个阶段是 std::function<void(SettlementContext&)>,按 priority 升序执行。
13// 2. 触发时(例如技能命中、周期性 DOT tick)构造一个 SettlementContext,
14// 塞入 source/target/values/tags,调用 SettlementPipeline::run(name, ctx);
15// 各阶段依次读写 ctx.values,其中某一步可以设置 ctx.cancelled=true 提前终止
16// (例如"闪避判定"阶段判定闪避成功后取消后续所有伤害计算)。
17// 3. 脚本侧虽然不能注册新的原生阶段(std::function 无法跨越 C++/Squirrel),
18// 但可以:a) 直接读写 SettlementContext 的字段驱动纯脚本逻辑;
19// b) 通过 setStageEnabled / setStagePriority 开关或重排已注册的
20// 阶段,实现"选用哪些内建规则、以什么顺序生效"的定制。
21//
22// 这套机制与 AttributeSystem 的自定义 op、SkillSystem 的 cast condition 是同一种
23// "C++ 提供可插拔扩展点,字符串作为跨语言、跨版本稳定的接口"的设计语言。
24
25#include <functional>
26#include <string>
27#include <unordered_map>
28#include <vector>
29
30namespace eve::rpg {
31
32class RPGActor;
33
36 RPGActor *source = nullptr;
37 RPGActor *target = nullptr;
38 std::string kind;
39 bool cancelled = false;
40
41 std::unordered_map<std::string, double> values;
42 std::vector<std::string> tags;
43
45 double get(const std::string &key, double fallback = 0.0) const;
47 void set(const std::string &key, double value);
49 bool has(const std::string &key) const;
50
52 void addTag(const std::string &tag);
54 bool hasTag(const std::string &tag) const;
55};
56
64public:
65 using Stage = std::function<void(SettlementContext &)>;
66
68 static void registerStage(const std::string &pipeline, const std::string &stage, int priority,
69 Stage fn);
71 static bool unregisterStage(const std::string &pipeline, const std::string &stage);
73 static bool setStageEnabled(const std::string &pipeline, const std::string &stage, bool enabled);
75 static bool setStagePriority(const std::string &pipeline, const std::string &stage, int priority);
77 static bool hasStage(const std::string &pipeline, const std::string &stage);
79 static int stageCount(const std::string &pipeline);
81 static void clearPipeline(const std::string &pipeline);
82
84 static void run(const std::string &pipeline, SettlementContext &ctx);
85};
86
87} // namespace eve::rpg
LogicalId target
double value
int priority
#define EVENGINE_API_PLATFORM
Definition Export.h:107
std::uint32_t key
const std::string * tag
std::weak_ptr< Run > run
Definition OnnxGpgpu.cpp:25
const UnitySourceAsset & source
属性 / 状态 / 技能三表合一的 ECS 实体。
Definition RPGActor.h:34
Compatibility-only named calculator retained for existing RPG scripts.
Definition Settlement.h:63
std::function< void(SettlementContext &)> Stage
Definition Settlement.h:65
RPG 模块的基础实体:把属性 / 状态 / 技能三张表挂到一个 ECS 实体上。
SettlementPipeline::Stage fn
bool enabled
结算上下文:通用的读写数据袋,字段完全由调用方与各阶段自行约定。
Definition Settlement.h:35
std::unordered_map< std::string, double > values
Definition Settlement.h:41
std::string kind
自由字符串,如 "damage" / "heal",供阶段内部分支使用
Definition Settlement.h:38
std::vector< std::string > tags
Definition Settlement.h:42