载入中...
搜索中...
未找到
ActionDamageSink.cpp
浏览该文件的文档.
2
3#include "common/Capability.h"
4#include "rpg/RPGActor.h"
6#include "rpg/VitalsSystem.h"
8
9#include <utility>
10
11namespace eve::rpg {
12namespace {
13RPGActor* resolve(ecs::EntityHandle handle) { return dynamic_cast<RPGActor*>(ecs::try_get(handle)); }
14Result<void> failure(DiagnosticCode code, const char* message) {
16}
17} // namespace
18
24
26 impl_->resolver = std::move(resolver);
27 cap::addListener<action::IActionDamageSink>(this);
28}
29RPGActionDamageSink::~RPGActionDamageSink() { cap::removeListener<action::IActionDamageSink>(this); }
30
31bool RPGActionDamageSink::supports(ecs::EntityHandle target) const {
32 if (!impl_->resolver || !ecs::try_get(target)) return false;
33 const auto mapped = impl_->resolver(target);
34 return mapped && mapped->subject.isValid() && resolve(mapped->actor);
35}
36
39 if (context.preview || context.scrubbing) return Result<void>::success(Status::success(StatusCode::NoOp));
40 if (binding.poiseAmount != 0.0 || binding.knockback.x != 0.0 || binding.knockback.y != 0.0 ||
41 binding.knockback.z != 0.0)
42 return failure(DiagnosticCode::Unsupported, "RPG Vitals damage does not own poise or knockback");
43 if (binding.targetIndex >= context.targets.size() || !impl_->resolver)
44 return failure(DiagnosticCode::NotFound, "RPG damage target or resolver is unavailable");
45 const auto targetHandle = context.targets[binding.targetIndex];
46 if (!ecs::try_get(targetHandle)) return failure(DiagnosticCode::StaleHandle, "Action target was destroyed");
47 const auto mappedTarget = impl_->resolver(targetHandle);
48 if (!mappedTarget || !mappedTarget->subject.isValid())
49 return failure(DiagnosticCode::NotFound, "Action target has no RPG identity mapping");
50 std::optional<RPGDamageTarget> mappedSource;
51 if (context.source) {
52 if (!ecs::try_get(*context.source)) return failure(DiagnosticCode::StaleHandle, "Action source was destroyed");
53 mappedSource = impl_->resolver(*context.source);
54 if (!mappedSource || !mappedSource->subject.isValid())
55 return failure(DiagnosticCode::NotFound, "Action source has no RPG identity mapping");
56 }
57 // Resolve only after all host callbacks have returned; retain no borrowed ECS addresses.
58 auto* target = resolve(mappedTarget->actor);
59 auto* source = mappedSource ? resolve(mappedSource->actor) : nullptr;
60 if (!target || (mappedSource && !source))
61 return failure(DiagnosticCode::StaleHandle, "Mapped RPG actor was destroyed");
62
64 request.source = mappedSource ? mappedSource->subject : SubjectRef::nil();
65 request.target = mappedTarget->subject;
66 request.kind = "damage";
67 request.resource = "hp";
68 request.magnitude = binding.amount;
69 request.tags = {binding.damageType};
70 request.tick = context.tick;
72 const double before = VitalsSystem::getCurrent(target, "hp");
73 impl_->receipts.reserve(impl_->receipts.size() + 1);
74 auto settled = impl_->pipeline.settle(request, adapter);
75 if (!settled) return Result<void>::failure(settled.status());
76 const double applied = settled.value().applied;
77 impl_->receipts.push_back({request.source, request.target, context.executionId, context.tick, applied,
78 before > 0.0 && VitalsSystem::getCurrent(target, "hp") == 0.0});
80}
81
82std::vector<RPGActionDamageReceipt> RPGActionDamageSink::takeReceipts() {
83 std::vector<RPGActionDamageReceipt> result;
84 result.swap(impl_->receipts);
85 return result;
86}
87} // namespace eve::rpg
LogicalId target
bool applied
std::string message
DiagnosticCode code
const GltfImportRequest & request
Poco::JSON::Object::Ptr result
eve::action::ActionVfxBinding binding
PrimitiveHandle handle
std::string_view source
std::string_view adapter
const VegetationPresetContext & context
当前资源(hp/mana...)的受伤 / 治疗 / 复活 / 死亡。
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
static SubjectRef nil() noexcept
Return the invalid nil reference.
Definition SubjectRef.h:35
RPGActionDamageSink(RPGDamageResolver resolver)
Register a provider with an owning callback; an empty callback accepts no targets.
Result< void > apply(const action::ActionDamageBinding &binding, const action::ActionNotifyContext &context) override
Settle one timeline hit against authoritative hp and queue its committed receipt.
bool supports(ecs::EntityHandle target) const override
Query the host mapping and current ECS generation without mutation.
std::vector< RPGActionDamageReceipt > takeReceipts()
Transfer and clear all owning receipts in commit order; consume once per host step.
~RPGActionDamageSink() override
Unregister before releasing transient receipts and the resolver.
属性 / 状态 / 技能三表合一的 ECS 实体。
Definition RPGActor.h:34
Settles damage/healing against one RPG actor's Vitals and AttributeSet.
static double getCurrent(RPGActor *actor, const std::string &resource)
当前值(无 vitals/资源时 0)。
Deterministically ordered, composable settlement pipeline.
Definition Settlement.h:542
RPG 模块的基础实体:把属性 / 状态 / 技能三张表挂到一个 ECS 实体上。
std::function< std::optional< RPGDamageTarget >(ecs::EntityHandle)> RPGDamageResolver
Resolve a live action entity to an RPG actor and stable reward identity. @ownership Callback captures...
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
RPG vitals and attribute policy adapter for the common settlement pipeline.
Domain-neutral, deterministic settlement pipeline.
Owning validated damage request authored on an action timeline.
Context linking a routed event to its action execution.
settlement::SettlementPipeline pipeline
std::vector< RPGActionDamageReceipt > receipts
Domain-neutral input to one settlement operation.
Definition Settlement.h:107