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