载入中...
搜索中...
未找到
BodyPartDamage.cpp
浏览该文件的文档.
2
3#include <cmath>
4#include <utility>
5
6namespace eve::combat {
7 // namespace
8
9Result<void> BodyPartDamageRule::setMultiplier(std::string bodyPart, double multiplier) {
10 if (bodyPart.empty()) return Result<void>::failure(
11 Diagnostic::error(DiagnosticCode::InvalidArgument, "body part is empty", "bodyPart"));
12 if (!std::isfinite(multiplier) || multiplier < 0.0) return Result<void>::failure(
13 Diagnostic::error(DiagnosticCode::InvalidArgument, "body-part multiplier is invalid", "multiplier"));
14 multipliers_[std::move(bodyPart)] = multiplier;
16}
17
18double BodyPartDamageRule::multiplier(std::string_view bodyPart) const noexcept {
19 const auto found = multipliers_.find(std::string(bodyPart));
20 return found == multipliers_.end() ? 1.0 : found->second;
21}
22
24 (void)target;
25 DamageAmounts amounts;
26 amounts.healthDamage = request.healthDamage * request.incomingDamageMultiplier;
27 amounts.poiseDamage = request.poiseDamage;
28 amounts.knockbackScale = 1.0;
29 if (!std::isfinite(amounts.healthDamage) || amounts.healthDamage < 0.0 ||
30 !std::isfinite(amounts.poiseDamage) || amounts.poiseDamage < 0.0)
32 Diagnostic::error(DiagnosticCode::InvalidArgument, "body-part damage amounts are invalid", "amounts"));
33 return Result<DamageAmounts>::success(amounts);
34}
35
37 std::string_view bodyPart) const {
38 DamageRequest scaled = request;
39 scaled.incomingDamageMultiplier = request.incomingDamageMultiplier * multiplier(bodyPart);
40 return evaluate(scaled, target);
41}
42
43} // namespace eve::combat
LogicalId target
IDamageRule that scales damage by body-part tags.
const GltfImportRequest & request
bool found
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
double multiplier(std::string_view bodyPart) const noexcept
Return the multiplier for a part, or 1.0 when unregistered.
Result< DamageAmounts > evaluateForPart(const DamageRequest &request, const CombatState &target, std::string_view bodyPart) const
Evaluate with an explicit body-part key.
Result< void > setMultiplier(std::string bodyPart, double multiplier)
Register or replace one finite non-negative body-part multiplier.
Result< DamageAmounts > evaluate(const DamageRequest &request, const CombatState &target) const override
Resolve final non-negative amounts without mutating target state.
Mutable combat state owned by the gameplay domain for one subject.
Definition Damage.h:37
Provider result prepared before the authoritative state is mutated.
Definition Damage.h:67
Owning input for one damage transaction.
Definition Damage.h:49
double incomingDamageMultiplier
Target-owned effect multiplier applied in the target-mitigation settlement stage.
Definition Damage.h:57