载入中...
搜索中...
未找到
ActionDamageSink.cpp
浏览该文件的文档.
2
4
5#include "common/Capability.h"
6
7#include <utility>
8
9namespace eve::combat {
10 // namespace
11
14
15CombatActionDamageSink::~CombatActionDamageSink() { cap::removeListener<action::IActionDamageSink>(this); }
16
18 for (std::size_t index = 0; index < cap::listenerCount<action::IActionDamageSink>(); ++index)
19 if (cap::listenerAt<action::IActionDamageSink>(index) == this) return true;
20 return false;
21}
22
24 const bool current = enabled();
25 if (value && !current)
26 cap::addListener<action::IActionDamageSink>(this);
27 else if (!value && current)
28 cap::removeListener<action::IActionDamageSink>(this);
29}
30
32 windowState_ = &state;
33}
34
35void CombatActionDamageSink::clearWindowState() noexcept { windowState_ = nullptr; }
36
37bool CombatActionDamageSink::supports(ecs::EntityHandle target) const {
38 return resolver_ && resolver_(target).has_value();
39}
40
43 if (!resolver_) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "combat-state resolver is unavailable", "resolver"));
44 if (binding.targetIndex >= context.targets.size())
45 return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "damage target index is unavailable", "targetIndex"));
46 auto target = resolver_(context.targets[binding.targetIndex]);
47 if (!target) return Result<void>::failure(Diagnostic::error(DiagnosticCode::NotFound, "damage target has no combat state", "target"));
48 if (windowState_ && windowState_->isInvulnerable(target->get().subject)) {
49 lastOutcome_.reset();
51 }
52
54 if (context.source) {
55 auto resolvedSource = resolver_(*context.source);
56 if (resolvedSource) source = resolvedSource->get().subject;
57 }
60 request.target = target->get().subject;
61 request.actionExecution = context.executionId;
62 request.damageType = binding.damageType;
63 request.healthDamage = binding.amount;
64 request.poiseDamage = binding.poiseAmount;
65 request.knockback = {binding.knockback.x, binding.knockback.y, binding.knockback.z};
66 auto outcome = runtime_.apply(target->get(), request);
67 if (!outcome) return Result<void>::failure(outcome.status());
68 lastOutcome_ = std::move(outcome).takeValue();
70}
71
72std::optional<DamageOutcome> CombatActionDamageSink::lastOutcome() const { return lastOutcome_; }
73
74} // namespace eve::combat
CombatState adapter for timeline damage blocks.
LogicalId target
double value
Combat-owned active hitbox and invulnerability projections.
const GltfImportRequest & request
eve::action::ActionVfxBinding binding
double current
uint32_t index
const UnitySourceAsset & source
const VegetationPresetContext & context
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
static SubjectRef nil() noexcept
Return the invalid nil reference.
Definition SubjectRef.h:35
void clearWindowState() noexcept
Clear the borrowed active-window observer.
Result< void > apply(const action::ActionDamageBinding &binding, const action::ActionNotifyContext &context) override
Atomically apply one validated damage request.
bool supports(ecs::EntityHandle target) const override
Whether this sink can resolve the supplied target handle now.
std::optional< DamageOutcome > lastOutcome() const
Return an owning copy of the latest committed damage outcome.
void setWindowState(const CombatActionWindowState &state) noexcept
Borrow active combat windows so invulnerability can reject damage. @lifetime The state owner must out...
CombatActionDamageSink(ActionCombatStateResolver resolver)
Construct with a synchronous resolver copied into the adapter.
~CombatActionDamageSink() override
Combat action damage sink.
bool enabled() const
Return whether this exact adapter is currently registered.
void setEnabled(bool enabled)
Opt this adapter into or out of Action damage dispatch.
Authoritative combat projection of active Montage hitbox and invulnerability windows.
bool isInvulnerable(SubjectRef subject) const noexcept
Return whether at least one active Montage window protects this stable subject.
Result< DamageOutcome > apply(CombatState &target, const DamageRequest &request) const
Resolve and atomically commit one damage request.
Definition Damage.cpp:200
std::function< OptionalRef< CombatState >(ecs::EntityHandle)> ActionCombatStateResolver
Resolves a borrowed mutable CombatState for one live ECS handle.
Owning validated damage request authored on an action timeline.
Context linking a routed event to its action execution.
Owning input for one damage transaction.
Definition Damage.h:49