载入中...
搜索中...
未找到
Battle.cpp
浏览该文件的文档.
24 participants_.push_back(Participant{actor, side, SubjectRef::fromPersistentId(PersistentId(bytes))});
50 eve::DiagnosticCode::NotFound, "RPG settlement chain target is not a battle participant", "target"));
62 const double chainTargetMaximum = VitalsSystem::getMax(chainTarget, chainConfig.healthAttribute);
74 RPGSettlementAdapter chainAdapter(*chainTarget, normalized.target, chainSource, normalized.source,
78 auto sourceRules = settlement::projectEffectRules(chainSource->statuses()->container, "rpg.source");
79 if (!sourceRules) return eve::Result<settlement::SettlementResult>::failure(sourceRules.status());
83 auto targetRules = settlement::projectEffectRules(chainTarget->statuses()->container, "rpg.target");
84 if (!targetRules) return eve::Result<settlement::SettlementResult>::failure(targetRules.status());
96 if (!request) return eve::Result<std::vector<settlement::SettlementBatchItemResult>>::failure(request.status());
101 events_.push_back(BattleEvent{"settlementFailed", tick.effectId, nullptr, tick.actor, 0.0, false});
112 events_.push_back(BattleEvent{outcome.request.trigger, tick.effectId, eventSource, eventTarget, 0.0, false});
117 VitalsSystem::publishSettledChange(eventTarget, outcome.request.resource, action, outcome.result->applied,
119 events_.push_back(BattleEvent{action, tick.effectId, eventSource, eventTarget, outcome.result->applied,
125bool Battle::isDead(const Participant& p) const { return !p.actor || VitalsSystem::isDead(p.actor, "hp"); }
127bool Battle::isActorAlive(RPGActor* actor) const { return actor && !VitalsSystem::isDead(actor, "hp"); }
203eve::Result<void> Battle::setActionChecked(RPGActor* actor, const std::string& skillId, RPGActor* target) {
208 if (!actor) return reject(eve::DiagnosticCode::InvalidArgument, "actor must not be null", "actor");
210 return reject(eve::DiagnosticCode::Conflict, "actions can only be queued before a non-finished round",
216 if (isDead(*participant)) return reject(eve::DiagnosticCode::Conflict, "dead actors cannot queue actions", "actor");
219 return reject(eve::DiagnosticCode::Conflict, "actor already has an action queued for this round", "actor");
221 return reject(eve::DiagnosticCode::NotFound, "actor does not know the requested skill", "skillId");
228 if (isDead(*targetParticipant)) return reject(eve::DiagnosticCode::Conflict, "target is not alive", "target");
229 const std::string targetType = skillId.empty() ? "enemySingle" : SkillSystem::getTargetType(actor, skillId);
231 return reject(eve::DiagnosticCode::InvalidArgument, "self-target skill must target its caster", "target");
233 return reject(eve::DiagnosticCode::InvalidArgument, "ally-target action must target the caster side",
235 if (targetType != "self" && targetType != "allySingle" && targetParticipant->side == participant->side)
236 return reject(eve::DiagnosticCode::InvalidArgument, "enemy-target action must target another side",
340 events_.push_back(BattleEvent{winner_ == playerSide_ ? "victory" : "defeat", "", nullptr, nullptr, 0.0, false});
379 targetType == "allySingle" ? lowestHealthTarget(sideOf(pa.actor), true) : randomOpponent(sideOf(pa.actor));
383 const SkillDamageSpec* spec = skillId.empty() ? nullptr : BattleSystem::findSkillDamage(skillId);
425 context["source_hp_ratio"] = sourceMaximum > 0.0 ? VitalsSystem::getCurrent(pa.actor, resource) / sourceMaximum
427 context["target_hp_ratio"] = targetMaximum > 0.0 ? VitalsSystem::getCurrent(target, resource) / targetMaximum
438 events_.push_back(BattleEvent{"settlementFailed", outcome.request.trigger, pa.actor, target, 0.0, false});
449 events_.push_back(BattleEvent{outcome.request.trigger, outcome.request.trigger, eventSource, eventTarget,
458 VitalsSystem::publishSettledChange(eventTarget, outcome.request.resource, action, outcome.result->applied,
460 events_.push_back(BattleEvent{action, outcome.request.trigger.empty() ? skillId : outcome.request.trigger,
RPG's thin compatibility facade over the attributes module.
伤害公式 DSL 与技能伤害注册。
回合制战斗对象:参战者、行动顺序、目标选取、行动执行。
特征系统:施加/移除运行时特征,并提供耐性/特殊参数/攻击附加等查询。
当前资源(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
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:537
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
static SubjectRef fromPersistentId(PersistentId id) noexcept
Wrap a persistent identity without changing its bytes.
Definition SubjectRef.h:32
static double getFinal(RPGActor *actor, const std::string &attribute)
Compute the final value through the canonical attributes engine.
Definition AttributeSystem.cpp:103
static DamageResult resolveHit(RPGActor *attacker, RPGActor *target, const SkillDamageSpec &spec, unsigned seed)
结算一次命中:命中判定、公式、元素耐性、暴击。
Definition BattleSystem.cpp:210
static const SkillDamageSpec * findSkillDamage(const std::string &skillId)
Finds skill damage.
Definition BattleSystem.cpp:45
RPGActor * getActor(int index) const
Return a participant actor by index, or null when out of range.
Definition Battle.cpp:467
eve::Result< void > configureSettlementRules(const settlement::SettlementRuleSet &rules)
Replace declarative buff/effect rules used by subsequent battle settlements.
Definition Battle.cpp:27
eve::Result< std::vector< settlement::SettlementBatchItemResult > > settleStatusTick(const StatusTickEvent &tick, SubjectRef source, SimulationTick simulationTick)
Execute one emitted periodic status tick through this battle's canonical settlement path.
Definition Battle.cpp:92
void setAction(RPGActor *actor, const std::string &skillId, RPGActor *target=nullptr)
为参战者设置本回合行动;target 为空由目标规则自动解析。
Definition Battle.cpp:183
RPGActor * getEventCaster(int index) const
Return the caster of a polled event, or null when out of range.
Definition Battle.cpp:494
RPGActor * getEventTarget(int index) const
Return the target of a polled event, or null when out of range.
Definition Battle.cpp:498
eve::Result< void > setActionChecked(RPGActor *actor, const std::string &skillId, RPGActor *target=nullptr)
Validate and queue exactly one action for a living participant this round.
Definition Battle.cpp:203
eve::Result< void > setActionByPolicyChecked(RPGActor *actor, const std::string &skillId, BattleTargetPolicy policy)
Resolve a deterministic target policy and queue one checked action atomically.
Definition Battle.cpp:243
bool knowsSkill(const std::string &skillId)
Definition RPGActor.cpp:199
static std::string getTargetType(RPGActor *actor, const std::string &skillId)
技能的目标类型字符串("" 表示未学会/未知)。
Definition SkillSystem.cpp:77
static bool beginCast(RPGActor *actor, const std::string &skillId, RPGActor *target=nullptr, std::string *reason=nullptr)
尝试释放技能:通过 canCast 检查后立即扣除消耗并进入冷却; castTime<=0 时立即结算(授予效果 + 产生 SkillCastEvent), 否则进入读条状态,由 update() 在读...
Definition SkillSystem.cpp:117
static double getCurrent(RPGActor *actor, const std::string &resource)
当前值(无 vitals/资源时 0)。
Definition VitalsSystem.cpp:30
static double getMax(RPGActor *actor, const std::string &resource)
上限:取 actor 同名最终属性(getFinalAttribute),无则 0。
Definition VitalsSystem.cpp:36
static void publishSettledChange(RPGActor *actor, const std::string &resource, const std::string &action, double amount, const std::string &source="")
Publish resource events for a state change already committed by Settlement.
Definition VitalsSystem.cpp:74
static bool isDead(RPGActor *actor, const std::string &resource)
是否死亡:max > 0 且 current <= 0。
Definition VitalsSystem.cpp:94
Deterministically ordered, composable settlement pipeline.
Definition Settlement.h:542
std::function< eve::Result< SettlementResult >(const SettlementRequest &)> RequestExecutor
Executes one owning chain request using its request-specific policy and rule snapshot.
Definition Settlement.h:546
eve::Result< std::vector< SettlementBatchItemResult > > settleChain(const SettlementRequest &root, const RequestExecutor &execute, std::uint32_t maxDepth, std::uint32_t maxSettlements) const
Settle a root request and its policy-produced derived requests in stable breadth-first order.
Definition SettlementBatch.cpp:169
Validated immutable-style rule collection installable into pipelines.
Definition SettlementRules.h:77
eve::Result< void > install(SettlementPipeline &pipeline) const
Install a stable snapshot as custom stages on a pipeline.
Definition SettlementRules.cpp:900
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:26
Result< T > applied(T value, std::vector< Diagnostic > diagnostics={})
Construct an Applied result with an owning payload and optional diagnostics.
Definition EditingResult.h:43
BattleTargetPolicy
Deterministic target-selection policies for queued battle actions.
Definition Battle.h:36
@ LowestHealthEnemy
@ LowestHealthAlly
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
eve::Result< SettlementRuleSet > projectEffectRules(const effects::EffectContainer &effects, std::string_view scope)
Project active effect payloads into an owning settlement rule snapshot.
Definition SettlementEffectProjection.cpp:109
@ InvalidArgument
@ NotFound
@ Conflict
StrongUuid< detail::PersistentIdTag > PersistentId
Stable instance identity for persistence, networking and process boundaries.
Definition Identity.h:254
@ Applied
detail::StrongUint64< detail::SimulationTickTag > SimulationTick
Deterministic simulation time step; it is not wall-clock time.
Definition Time.h:31
RPG AttributeSet policy adapter for the common settlement pipeline.
周期性状态触发的 tick 事件。周期效果(period > 0)不会自动修改属性, 而是每个周期产生一个 tick 事件交给上层(脚本或 C++ 结算系统)处理—— 这样伤害/治疗类周期效果可以完整地...
Definition StatusTypes.h:69
Domain-neutral input to one settlement operation.
Definition Settlement.h:107