载入中...
搜索中...
未找到
SettlementAdapter.cpp
浏览该文件的文档.
24bool isHealingKind(std::string_view kind) noexcept { return kind == "heal" || kind == "healing"; }
29 eve::DiagnosticCode::InvariantViolation, std::string(name) + " must be finite", std::string(name)));
33eve::Result<settlement::SettlementRequest> requestFailure(eve::DiagnosticCode code, std::string message,
51 const StatusTickEvent& tick, SubjectRef source, SubjectRef target, SimulationTick simulationTick) {
53 return requestFailure(eve::DiagnosticCode::InvalidArgument, "RPG status tick identity is invalid", "tick");
55 return requestFailure(eve::DiagnosticCode::InvalidArgument, "RPG status tick target must be valid", "target");
62 return requestFailure(eve::DiagnosticCode::NotFound, "RPG effect has no settlement.tick configuration",
68 return requestFailure(eve::DiagnosticCode::InvalidArgument, "settlement.tick must be a JSON object",
70 static const std::set<std::string> fields = {"context", "kind", "magnitude", "resource", "tags"};
82 if (kind == nullptr || kind->empty() || resource == nullptr || resource->empty() || magnitudeValue == nullptr)
92 return requestFailure(eve::DiagnosticCode::InvalidArgument, "settlement.tick magnitude must be a number",
112 return requestFailure(eve::DiagnosticCode::InvalidArgument, "settlement.tick tags must be an array",
129 return requestFailure(eve::DiagnosticCode::InvalidArgument, "settlement.tick context must be an object",
143RPGSettlementAdapter::RPGSettlementAdapter(RPGActor& target, SubjectRef targetRef, Config config)
154bool RPGSettlementAdapter::isDamage(const settlement::SettlementContext& context) const noexcept {
158bool RPGSettlementAdapter::isHealing(const settlement::SettlementContext& context) const noexcept {
162const eve::Value* RPGSettlementAdapter::contextValue(const settlement::SettlementContext& context,
192 eve::DiagnosticCode::InvalidArgument, "RPG settlement attribute name must not be empty", "attribute"));
200eve::Result<double> RPGSettlementAdapter::readFinal(std::string_view name, double fallback) const {
207eve::Result<double> RPGSettlementAdapter::readSourceFinal(std::string_view name, double fallback) const {
217 eve::DiagnosticCode::Conflict, "RPG settlement request target does not match adapter target", "target"));
223 eve::DiagnosticCode::Unsupported, "RPG settlement adapter supports damage, healing and trigger kinds only",
240 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "RPG health exceeds max health", "health"));
248eve::Result<void> RPGSettlementAdapter::sourceModifiers(settlement::SettlementContext& context) {
304 eve::DiagnosticCode::InvalidArgument, "RPG critical multiplier must be finite and at least one",
359 const double penetration = std::max(0.0, numberValue(contextValue(context, "penetration")).value_or(0.0));
445 isDamage(context) ? health.value() - context.magnitude() : health.value() + context.magnitude();
491 return eve::Result<std::vector<settlement::SettlementRequest>>::success(std::move(transitions));
506 if (shield.ok() && shield.value() > 0.0 && result.absorbed >= shield.value()) append("shield_break");
511 if (!health) return eve::Result<std::vector<settlement::SettlementRequest>>::failure(health.status());
512 const bool died = config_.emitLifeTransitions && health.value() > 0.0 && result.applied >= health.value();
515 if (context.request().source.isValid() && context.request().source != context.request().target) append("kill");
517 return eve::Result<std::vector<settlement::SettlementRequest>>::success(std::move(transitions));
RPG's thin compatibility facade over the attributes module.
当前资源(hp/mana...)的受伤 / 治疗 / 复活 / 死亡。
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
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
bool isValid() const noexcept
Return whether this reference is valid and non-nil.
Definition SubjectRef.h:38
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
Value * find(const std::string &key) noexcept
Return an object member, or nullptr when absent.
Definition Value.cpp:124
Generic owning collection of canonical attributes and modifiers.
Definition AttributeSet.h:160
static const EffectDefinition * find(const std::string &id)
Find a registered effect definition by id.
Definition Effect.cpp:30
Settles damage/healing against one RPG actor's AttributeSet.
Definition SettlementAdapter.h:47
eve::Result< void > sourceModifiers(settlement::SettlementContext &context) override
Apply source-side modifiers such as critical or elemental power.
Definition SettlementAdapter.cpp:248
eve::Result< settlement::PreparedApply > prepareApply(const settlement::SettlementContext &context) override
Build an atomic candidate mutation without publishing it.
Definition SettlementAdapter.cpp:428
eve::Result< void > clamp(settlement::SettlementContext &context) override
Configure policy-specific amount bounds for the generic clamp.
Definition SettlementAdapter.cpp:404
eve::Result< void > armorShield(settlement::SettlementContext &context) override
Apply armor and shield policy, recording absorbed amount.
Definition SettlementAdapter.cpp:350
eve::Result< std::vector< settlement::SettlementRequest > > prepareTrigger(const settlement::SettlementContext &context, const settlement::SettlementResult &result) override
Produce owning derived requests without mutating domain state.
Definition SettlementAdapter.cpp:487
eve::Result< void > validate(settlement::SettlementContext &context) override
Validate request and target-owned state without mutating it.
Definition SettlementAdapter.cpp:214
RPGSettlementAdapter(RPGActor &target, SubjectRef targetRef)
Bind a target actor with default RPG attribute names.
Definition SettlementAdapter.cpp:140
eve::Result< void > targetMitigation(settlement::SettlementContext &context) override
Apply target mitigation such as resistance or penetration rules.
Definition SettlementAdapter.cpp:320
Prepared domain mutation used to make settlement application atomic.
Definition Settlement.h:281
Mutable calculation frame visible to policy and custom stage code.
Definition Settlement.h:338
eve::Result< settlement::SettlementRequest > makeStatusTickSettlementRequest(const StatusTickEvent &tick, SubjectRef source, SubjectRef target, SimulationTick simulationTick)
Project one configured RPG status tick into the canonical settlement request.
Definition SettlementAdapter.cpp:50
@ InvalidArgument
@ NotFound
@ Unsupported
@ InvariantViolation
@ Conflict
@ Pending
@ NotFound
@ Applied
Definition Container.h:602
RPG AttributeSet policy adapter for the common settlement pipeline.
Attribute names used by the RPG policy.
Definition SettlementAdapter.h:50
std::string shieldAttribute
Definition SettlementAdapter.h:55
std::string maxHealthAttribute
Final attribute supplying the resource maximum.
Definition SettlementAdapter.h:54
std::string armorAttribute
Definition SettlementAdapter.h:56
std::string sourceMultiplierAttribute
Definition SettlementAdapter.h:60
std::string criticalMultiplierAttribute
Definition SettlementAdapter.h:59
bool emitLifeTransitions
Emit death/kill transitions when this resource crosses zero.
Definition SettlementAdapter.h:62
std::string criticalChanceAttribute
Definition SettlementAdapter.h:58
std::string resistancePrefix
Definition SettlementAdapter.h:57
std::string healthAttribute
Vitals resource holding authoritative current health.
Definition SettlementAdapter.h:52
周期性状态触发的 tick 事件。周期效果(period > 0)不会自动修改属性, 而是每个周期产生一个 tick 事件交给上层(脚本或 C++ 结算系统)处理—— 这样伤害/治疗类周期效果可以完整地...
Definition StatusTypes.h:69
Domain-neutral input to one settlement operation.
Definition Settlement.h:107
std::string resource
Optional domain resource/channel key, for example hp, mana, armor, or fire.
Definition Settlement.h:113
std::string trigger
Stable re-entry key for a derived request; empty only for a root request.
Definition Settlement.h:119
std::vector< SettlementRandomDecision > decisions
Definition Settlement.h:117
Complete observable outcome of one successful settlement.
Definition Settlement.h:163