载入中...
搜索中...
未找到
Battle.cpp
浏览该文件的文档.
1#include "rpg/Battle.h"
2
3#include <utility>
4
6#include "rpg/BattleSystem.h"
7#include "rpg/RPGActor.h"
9#include "rpg/Skill.h"
10#include "rpg/SkillSystem.h"
11#include "rpg/StatusSystem.h"
12#include "rpg/TraitSystem.h"
13#include "rpg/VitalsSystem.h"
14
15#include <algorithm>
16#include <array>
17
18namespace eve::rpg {
19
21 if (turn_ != 0)
23 eve::DiagnosticCode::Conflict, "Battle seed must be configured before the first round"));
24 seedCounter_ = static_cast<unsigned>(seed ^ (seed >> 32));
26}
27
28void Battle::addActor(RPGActor* actor, int side) {
29 if (!actor) return;
30 std::array<std::uint8_t, 16> bytes{0x52, 0x50, 0x47, 0x42, 0x41, 0x54, 0x54, 0x4c,
31 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
32 const auto sequence = nextSettlementSubject_++;
33 for (std::size_t index = 0; index < sizeof(sequence); ++index)
34 bytes[15 - index] = static_cast<std::uint8_t>((sequence >> (index * 8u)) & 0xffu);
35 participants_.push_back(Participant{actor, side, SubjectRef::fromPersistentId(PersistentId(bytes))});
36}
37
40 auto installed = rules.install(candidate);
41 if (!installed) return installed;
42 settlement_ = std::move(candidate);
44}
45
48 const std::string rootResource = request.resource;
49 const auto actorForSubject = [&](const SubjectRef& subject) -> RPGActor* {
50 const auto found = std::find_if(participants_.begin(), participants_.end(),
51 [&](const Participant& value) { return value.settlementSubject == subject; });
52 return found == participants_.end() ? nullptr : found->actor;
53 };
55 [&](const settlement::SettlementRequest& chainRequest)
57 RPGActor* chainTarget = actorForSubject(chainRequest.target);
58 RPGActor* chainSource = actorForSubject(chainRequest.source);
59 if (chainTarget == nullptr)
61 eve::DiagnosticCode::NotFound, "RPG settlement chain target is not a battle participant", "target"));
62
63 auto normalized = chainRequest;
64 RPGSettlementAdapter::Config chainConfig;
65 chainConfig.healthAttribute = normalized.resource.empty() ? rootResource : normalized.resource;
66 chainConfig.maxHealthAttribute = chainConfig.healthAttribute;
67 chainConfig.emitLifeTransitions = chainConfig.healthAttribute == "hp";
68 Value::Object chainContext;
69 if (const auto* supplied = normalized.context.getIf<Value::Object>()) chainContext = *supplied;
70 chainContext.try_emplace("source_multiplier", 1.0);
71 chainContext.try_emplace("critical", false);
72 chainContext.try_emplace("element", std::string("damage"));
73 const double chainTargetMaximum = VitalsSystem::getMax(chainTarget, chainConfig.healthAttribute);
74 chainContext["target_hp_ratio"] =
75 chainTargetMaximum > 0.0
76 ? VitalsSystem::getCurrent(chainTarget, chainConfig.healthAttribute) / chainTargetMaximum
77 : 0.0;
78 const double chainSourceMaximum =
79 chainSource == nullptr ? 0.0 : VitalsSystem::getMax(chainSource, chainConfig.healthAttribute);
80 chainContext["source_hp_ratio"] =
81 chainSourceMaximum > 0.0
82 ? VitalsSystem::getCurrent(chainSource, chainConfig.healthAttribute) / chainSourceMaximum
83 : 0.0;
84 normalized.context = Value(std::move(chainContext));
85 RPGSettlementAdapter chainAdapter(*chainTarget, normalized.target, chainSource, normalized.source,
86 std::move(chainConfig));
87 auto chainPipeline = settlement_;
88 if (chainSource != nullptr) {
89 auto sourceRules = settlement::projectEffectRules(chainSource->statuses()->container, "rpg.source");
90 if (!sourceRules) return eve::Result<settlement::SettlementResult>::failure(sourceRules.status());
91 auto installed = sourceRules.value().install(chainPipeline);
92 if (!installed) return eve::Result<settlement::SettlementResult>::failure(installed.status());
93 }
94 auto targetRules = settlement::projectEffectRules(chainTarget->statuses()->container, "rpg.target");
95 if (!targetRules) return eve::Result<settlement::SettlementResult>::failure(targetRules.status());
96 auto installed = targetRules.value().install(chainPipeline);
97 if (!installed) return eve::Result<settlement::SettlementResult>::failure(installed.status());
98 return chainPipeline.settle(normalized, chainAdapter);
99 };
100 return settlement_.settleChain(request, executeSettlement, 8, 64);
101}
102
104 const StatusTickEvent& tick, SubjectRef source, SimulationTick simulationTick) {
105 const SubjectRef target = settlementSubjectOf(tick.actor);
106 auto request = makeStatusTickSettlementRequest(tick, std::move(source), target, simulationTick);
108 auto settled = settleRequest(request.value());
109 if (!settled) return settled;
110 for (const auto& outcome : settled.value()) {
111 if (!outcome.result) {
112 events_.push_back(BattleEvent{"settlementFailed", tick.effectId, nullptr, tick.actor, 0.0, false});
113 break;
114 }
115 RPGActor* eventTarget = nullptr;
116 RPGActor* eventSource = nullptr;
117 for (const auto& participant : participants_) {
118 if (participant.settlementSubject == outcome.request.target) eventTarget = participant.actor;
119 if (participant.settlementSubject == outcome.request.source) eventSource = participant.actor;
120 }
121 if (eventTarget == nullptr) continue;
122 if (outcome.request.kind == "trigger") {
123 events_.push_back(BattleEvent{outcome.request.trigger, tick.effectId, eventSource, eventTarget, 0.0, false});
124 continue;
125 }
126 const bool healing = outcome.request.kind == "heal" || outcome.request.kind == "healing";
127 const char* action = healing ? "heal" : "damage";
128 VitalsSystem::publishSettledChange(eventTarget, outcome.request.resource, action, outcome.result->applied,
129 tick.effectId);
130 events_.push_back(BattleEvent{action, tick.effectId, eventSource, eventTarget, outcome.result->applied,
131 !healing && outcome.result->critical});
132 }
133 return settled;
134}
135
136bool Battle::isDead(const Participant& p) const { return !p.actor || VitalsSystem::isDead(p.actor, "hp"); }
137
138bool Battle::isActorAlive(RPGActor* actor) const { return actor && !VitalsSystem::isDead(actor, "hp"); }
139
140std::vector<RPGActor*> Battle::livingOnSide(int side) const {
141 std::vector<RPGActor*> out;
142 for (const auto& p : participants_) {
143 if (p.side == side && !isDead(p)) out.push_back(p.actor);
144 }
145 return out;
146}
147
148RPGActor* Battle::randomOpponent(int mySide) {
149 std::vector<RPGActor*> opps;
150 for (const auto& p : participants_) {
151 if (p.side != mySide && !isDead(p)) opps.push_back(p.actor);
152 }
153 if (opps.empty()) return nullptr;
154 return opps[size_t((seedCounter_++) % opps.size())];
155}
156
157int Battle::sideOf(RPGActor* actor) const {
158 for (const auto& p : participants_) {
159 if (p.actor == actor) return p.side;
160 }
161 return playerSide_;
162}
163
164SubjectRef Battle::settlementSubjectOf(RPGActor* actor) const noexcept {
165 const auto found = std::find_if(participants_.begin(), participants_.end(),
166 [actor](const Participant& value) { return value.actor == actor; });
167 return found == participants_.end() ? SubjectRef::nil() : found->settlementSubject;
168}
169
170int Battle::computeWinnerSide() const {
171 int aliveSide = -1;
172 bool anyAlive = false;
173 for (const auto& p : participants_) {
174 if (isDead(p)) continue;
175 anyAlive = true;
176 if (aliveSide == -1) {
177 aliveSide = p.side;
178 } else if (aliveSide != p.side) {
179 return -1; // 多侧尚存活 → 未定
180 }
181 }
182 return anyAlive ? aliveSide : -1; // 全灭 → -1(平局)
183}
184
185void Battle::setPlayerSide(int side) { playerSide_ = side; }
186int Battle::getPlayerSide() const { return playerSide_; }
187
188bool Battle::isFinished() const { return finished_; }
189bool Battle::isVictory() const { return finished_ && winner_ == playerSide_; }
190bool Battle::isDefeat() const { return finished_ && winner_ != -1 && winner_ != playerSide_; }
191int Battle::getWinnerSide() const { return winner_; }
192int Battle::getTurn() const { return turn_; }
193
194void Battle::setAction(RPGActor* actor, const std::string& skillId, RPGActor* target) {
195 setActionChecked(actor, skillId, target).ignore();
196}
197
198RPGActor* Battle::lowestHealthTarget(int side, bool sameSide) const {
199 RPGActor* selected = nullptr;
200 double selectedRatio = 0.0;
201 for (const auto& participant : participants_) {
202 if (isDead(participant) || ((participant.side == side) != sameSide)) continue;
203 const double maximum = VitalsSystem::getMax(participant.actor, "hp");
204 if (maximum <= 0.0) continue;
205 const double ratio = VitalsSystem::getCurrent(participant.actor, "hp") / maximum;
206 if (!selected || ratio < selectedRatio) {
207 selected = participant.actor;
208 selectedRatio = ratio;
209 }
210 }
211 return selected;
212}
213
215 const auto reject = [](eve::DiagnosticCode code, std::string message, std::string path) {
217 eve::Diagnostic::error(code, std::move(message), std::move(path), {}, "rpg.battle.action"));
218 };
219 if (!actor) return reject(eve::DiagnosticCode::InvalidArgument, "actor must not be null", "actor");
220 if (finished_ || started_)
221 return reject(eve::DiagnosticCode::Conflict, "actions can only be queued before a non-finished round",
222 "battle");
223 const auto participant = std::find_if(participants_.begin(), participants_.end(),
224 [actor](const Participant& value) { return value.actor == actor; });
225 if (participant == participants_.end())
226 return reject(eve::DiagnosticCode::NotFound, "actor is not a battle participant", "actor");
227 if (isDead(*participant)) return reject(eve::DiagnosticCode::Conflict, "dead actors cannot queue actions", "actor");
228 if (std::any_of(roundActions_.begin(), roundActions_.end(),
229 [actor](const PendingAction& value) { return value.actor == actor; }))
230 return reject(eve::DiagnosticCode::Conflict, "actor already has an action queued for this round", "actor");
231 if (!skillId.empty() && !actor->knowsSkill(skillId))
232 return reject(eve::DiagnosticCode::NotFound, "actor does not know the requested skill", "skillId");
233 if (target) {
234 const auto targetParticipant =
235 std::find_if(participants_.begin(), participants_.end(),
236 [target](const Participant& value) { return value.actor == target; });
237 if (targetParticipant == participants_.end())
238 return reject(eve::DiagnosticCode::NotFound, "target is not a battle participant", "target");
239 if (isDead(*targetParticipant)) return reject(eve::DiagnosticCode::Conflict, "target is not alive", "target");
240 const std::string targetType = skillId.empty() ? "enemySingle" : SkillSystem::getTargetType(actor, skillId);
241 if (targetType == "self" && target != actor)
242 return reject(eve::DiagnosticCode::InvalidArgument, "self-target skill must target its caster", "target");
243 if (targetType == "allySingle" && targetParticipant->side != participant->side)
244 return reject(eve::DiagnosticCode::InvalidArgument, "ally-target action must target the caster side",
245 "target");
246 if (targetType != "self" && targetType != "allySingle" && targetParticipant->side == participant->side)
247 return reject(eve::DiagnosticCode::InvalidArgument, "enemy-target action must target another side",
248 "target");
249 }
250 roundActions_.push_back(PendingAction{actor, skillId, target, 0.0});
252}
253
255 BattleTargetPolicy policy) {
256 if (policy == BattleTargetPolicy::Auto) return setActionChecked(actor, skillId, nullptr);
257 const int side = sideOf(actor);
258 RPGActor* target = nullptr;
259 if (policy == BattleTargetPolicy::Self)
260 target = actor;
261 else if (policy == BattleTargetPolicy::LowestHealthAlly)
262 target = lowestHealthTarget(side, true);
263 else if (policy == BattleTargetPolicy::LowestHealthEnemy)
264 target = lowestHealthTarget(side, false);
265 if (!target)
267 "target policy found no living participant", "policy",
268 {}, "rpg.battle.action-policy"));
269 return setActionChecked(actor, skillId, target);
270}
271
273 if (finished_) return;
274 for (const auto& p : participants_) {
275 if (p.side == playerSide_ || isDead(p)) continue;
276 bool already = false;
277 for (const auto& ra : roundActions_) {
278 if (ra.actor == p.actor) {
279 already = true;
280 break;
281 }
282 }
283 if (already) continue;
284 // 随机已学技能,否则普攻(skillId 空 = 普攻)
285 std::vector<std::string> known;
286 for (const auto& [id, unused] : p.actor->skills()->known) {
287 (void)unused;
288 known.push_back(id);
289 }
290 std::string skillId;
291 if (!known.empty()) {
292 skillId = known[size_t((seedCounter_++) % known.size())];
293 }
294 roundActions_.push_back(PendingAction{p.actor, skillId, randomOpponent(p.side), 0.0});
295 }
296}
297
299 if (finished_) return;
300 ++turn_;
301 // 计算先攻:speed 属性 + 技能攻击速度修正。
302 for (auto& pa : roundActions_) {
303 double speed = AttributeSystem::getFinal(pa.actor, "speed");
304 if (speed <= 0.0) speed = AttributeSystem::getFinal(pa.actor, "agi");
305 if (speed <= 0.0) speed = 0.0;
306 pa.initiative = speed + TraitSystem::getAttackSpeed(pa.actor);
307 }
308 std::stable_sort(roundActions_.begin(), roundActions_.end(),
309 [](const PendingAction& x, const PendingAction& y) { return x.initiative > y.initiative; });
310 queue_ = std::move(roundActions_);
311 roundActions_.clear();
312 started_ = true;
313 events_.push_back(BattleEvent{"roundStart", "", nullptr, nullptr, 0.0, false});
314}
315
317 if (!started_ || finished_) return false;
318 if (queue_.empty()) {
319 started_ = false;
320 return false;
321 }
322 PendingAction pa = queue_.front();
323 queue_.erase(queue_.begin());
324
325 // 已死则跳过
326 if (VitalsSystem::isDead(pa.actor, "hp")) {
327 return true;
328 }
329
330 // 解析目标:未指定则按 targetType / 默认对手。
331 RPGActor* target = pa.target;
332 if (!target) {
333 if (pa.skillId.empty()) {
334 target = randomOpponent(sideOf(pa.actor));
335 } else if (SkillSystem::getTargetType(pa.actor, pa.skillId) == "self") {
336 target = pa.actor;
337 } else if (SkillSystem::getTargetType(pa.actor, pa.skillId) == "allySingle") {
338 target = lowestHealthTarget(sideOf(pa.actor), true);
339 } else {
340 target = randomOpponent(sideOf(pa.actor));
341 }
342 }
343 if (!target) return true;
344
345 execute(pa, seedCounter_);
346 // 每步检查结束:仅剩一方 → 胜;双方全灭 → 平;否则继续。
347 const int w = computeWinnerSide();
348 if (w != -1) {
349 finished_ = true;
350 winner_ = w;
351 events_.push_back(BattleEvent{winner_ == playerSide_ ? "victory" : "defeat", "", nullptr, nullptr, 0.0, false});
352 } else {
353 bool anyAlive = false;
354 for (const auto& p : participants_) {
355 if (!isDead(p)) {
356 anyAlive = true;
357 break;
358 }
359 }
360 if (!anyAlive) {
361 finished_ = true;
362 winner_ = -1;
363 events_.push_back(BattleEvent{"defeat", "", nullptr, nullptr, 0.0, false});
364 }
365 }
366 return true;
367}
368
369void Battle::execute(PendingAction& pa, unsigned& seedCounter) {
370 const std::string skillId = pa.skillId;
371 const std::string targetType =
372 skillId.empty() ? std::string("enemySingle") : SkillSystem::getTargetType(pa.actor, skillId);
373 RPGActor* target = pa.target;
374 if (!target) {
375 if (targetType == "self") {
376 target = pa.actor;
377 } else if (targetType == "allySingle") {
378 target = lowestHealthTarget(sideOf(pa.actor), true);
379 } else {
380 target = randomOpponent(sideOf(pa.actor));
381 }
382 }
383 if (!target) return;
384
385 events_.push_back(BattleEvent{"actionStart", skillId, pa.actor, target, 0.0, false});
386
387 // 目标已死:换一个存活对手
388 if (targetType != "self" && VitalsSystem::isDead(target, "hp")) {
389 target =
390 targetType == "allySingle" ? lowestHealthTarget(sideOf(pa.actor), true) : randomOpponent(sideOf(pa.actor));
391 if (!target) return;
392 }
393
394 const SkillDamageSpec* spec = skillId.empty() ? nullptr : BattleSystem::findSkillDamage(skillId);
395 if (!spec && !skillId.empty()) {
396 // 无伤害规格:走技能授予效果(治疗/状态等,无公式伤害)。
397 SkillSystem::beginCast(pa.actor, skillId, target);
398 return;
399 }
400 if (!spec) {
401 // 普攻默认规格
402 static const SkillDamageSpec kDefault{};
403 spec = &kDefault;
404 }
405
406 // Instant formula skills use the same affordability, cooldown and effect path as other skills.
407 if (!skillId.empty()) {
408 const auto* definition = SkillRegistry::find(skillId);
409 if (definition && definition->castTime <= 0 && !SkillSystem::beginCast(pa.actor, skillId, target)) {
410 events_.push_back(BattleEvent{"actionRejected", skillId, pa.actor, target, 0.0, false});
411 return;
412 }
413 }
414
415 DamageResult result = BattleSystem::resolveHit(pa.actor, target, *spec, seedCounter++);
416 if (!result.hit) {
417 events_.push_back(BattleEvent{"miss", skillId, pa.actor, target, 0.0, false});
418 return;
419 }
420
421 // 目标资源名任意:damageType 即资源名,"XHeal" 后缀表示治疗。
422 std::string resource = spec->damageType;
423 bool heal = false;
424 if (resource.size() >= 4 && resource.compare(resource.size() - 4, 4, "Heal") == 0) {
425 resource = resource.substr(0, resource.size() - 4);
426 heal = true;
427 }
428 const SubjectRef sourceRef = settlementSubjectOf(pa.actor);
429 const SubjectRef targetRef = settlementSubjectOf(target);
430 settlement::SettlementRequest request;
431 request.source = sourceRef;
432 request.target = targetRef;
433 request.kind = heal ? "healing" : "damage";
434 request.resource = resource;
435 request.magnitude = result.amount;
436 request.tags = {heal ? "rpg:healing" : "rpg:damage", "element:" + spec->element};
437 request.tick = SimulationTick(static_cast<std::uint64_t>(turn_));
439 context["source_multiplier"] = 1.0;
440 context["critical"] = result.crit;
441 context["critical_multiplier"] = 1.0;
442 context["element"] = spec->element.empty() ? std::string("damage") : spec->element;
443 const double sourceMaximum = VitalsSystem::getMax(pa.actor, resource);
444 const double targetMaximum = VitalsSystem::getMax(target, resource);
445 context["source_hp_ratio"] = sourceMaximum > 0.0 ? VitalsSystem::getCurrent(pa.actor, resource) / sourceMaximum
446 : 0.0;
447 context["target_hp_ratio"] = targetMaximum > 0.0 ? VitalsSystem::getCurrent(target, resource) / targetMaximum
448 : 0.0;
449 request.context = Value(std::move(context));
450 auto settled = settleRequest(request);
451 if (!settled || settled.value().empty() || !settled.value().front().result) {
452 events_.push_back(BattleEvent{"settlementFailed", skillId, pa.actor, target, 0.0, false});
453 return;
454 }
455 auto outcomes = std::move(settled).takeValue();
456 for (const auto& outcome : outcomes) {
457 if (!outcome.result) {
458 events_.push_back(BattleEvent{"settlementFailed", outcome.request.trigger, pa.actor, target, 0.0, false});
459 break;
460 }
461 RPGActor* eventTarget = nullptr;
462 RPGActor* eventSource = nullptr;
463 for (const auto& participant : participants_) {
464 if (participant.settlementSubject == outcome.request.target) eventTarget = participant.actor;
465 if (participant.settlementSubject == outcome.request.source) eventSource = participant.actor;
466 }
467 if (eventTarget == nullptr) continue;
468 if (outcome.request.kind == "trigger") {
469 events_.push_back(BattleEvent{outcome.request.trigger, outcome.request.trigger, eventSource, eventTarget,
470 0.0, false});
471 continue;
472 }
473 const bool outcomeHeal = outcome.request.kind == "heal" || outcome.request.kind == "healing";
474 const std::string action = outcomeHeal ? "heal" : "damage";
475 const std::string cause = outcome.request.trigger.empty()
476 ? (outcomeHeal || skillId.empty() ? std::string{} : skillId)
477 : outcome.request.trigger;
478 VitalsSystem::publishSettledChange(eventTarget, outcome.request.resource, action, outcome.result->applied,
479 cause);
480 events_.push_back(BattleEvent{action, outcome.request.trigger.empty() ? skillId : outcome.request.trigger,
481 eventSource, eventTarget, outcome.result->applied,
482 !outcomeHeal && outcome.result->critical});
483 }
484}
485
486int Battle::getActorCount() const { return int(participants_.size()); }
488 if (index < 0 || size_t(index) >= participants_.size()) return nullptr;
489 return participants_[size_t(index)].actor;
490}
491int Battle::getSide(int index) const {
492 if (index < 0 || size_t(index) >= participants_.size()) return 0;
493 return participants_[size_t(index)].side;
494}
495
496int Battle::getEventCount() const { return int(polled_.size()); }
498 if (index < 0 || size_t(index) >= polled_.size()) return BattleEvent{};
499 return polled_[size_t(index)];
500}
502 polled_ = std::move(events_);
503 events_.clear();
504}
505
506std::string Battle::getEventAction(int index) const {
507 if (index < 0 || size_t(index) >= polled_.size()) return {};
508 return polled_[size_t(index)].action;
509}
510std::string Battle::getEventSkillId(int index) const {
511 if (index < 0 || size_t(index) >= polled_.size()) return {};
512 return polled_[size_t(index)].skillId;
513}
515 if (index < 0 || size_t(index) >= polled_.size()) return nullptr;
516 return polled_[size_t(index)].caster;
517}
519 if (index < 0 || size_t(index) >= polled_.size()) return nullptr;
520 return polled_[size_t(index)].target;
521}
522double Battle::getEventAmount(int index) const {
523 if (index < 0 || size_t(index) >= polled_.size()) return 0.0;
524 return polled_[size_t(index)].amount;
525}
527 if (index < 0 || size_t(index) >= polled_.size()) return false;
528 return polled_[size_t(index)].crit;
529}
530
531} // namespace eve::rpg
double y
double x
LogicalId target
float w
Definition AnimClip.cpp:738
int subject
Definition AnimSmr.cpp:163
std::string selected
RPG's thin compatibility facade over the attributes module.
伤害公式 DSL 与技能伤害注册。
回合制战斗对象:参战者、行动顺序、目标选取、行动执行。
bool applied
glm::vec4 p[6]
std::string message
DiagnosticCode code
float maximum[3]
const GltfImportRequest & request
float ratio
Poco::JSON::Object::Ptr result
std::uint64_t bytes
std::unique_ptr< gpgpu::Sequence > sequence
Definition OnnxGpgpu.cpp:43
std::string action
Definition PlayHost.cpp:118
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
bool found
ScriptStructure out
std::string_view source
std::string resource
std::string element
SimulationTick tick
特征系统:施加/移除运行时特征,并提供耐性/特殊参数/攻击附加等查询。
uint32_t seed
Definition TreeMesh.cpp:276
uint32_t index
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.
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
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
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
static SubjectRef fromPersistentId(PersistentId id) noexcept
Wrap a persistent identity without changing its bytes.
Definition SubjectRef.h:32
static SubjectRef nil() noexcept
Return the invalid nil reference.
Definition SubjectRef.h:35
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
static double getFinal(RPGActor *actor, const std::string &attribute)
Compute the final value through the canonical attributes engine.
static DamageResult resolveHit(RPGActor *attacker, RPGActor *target, const SkillDamageSpec &spec, unsigned seed)
结算一次命中:命中判定、公式、元素耐性、暴击。
static const SkillDamageSpec * findSkillDamage(const std::string &skillId)
Finds skill damage.
RPGActor * getActor(int index) const
Return a participant actor by index, or null when out of range.
Definition Battle.cpp:487
void startRound()
结算所有已设行动:先攻排序、清空待行动,回合数 +1。
Definition Battle.cpp:298
eve::Result< void > configureSettlementRules(const settlement::SettlementRuleSet &rules)
Replace declarative buff/effect rules used by subsequent battle settlements.
Definition Battle.cpp:38
void addActor(RPGActor *actor, int side)
加入参战者;side 为任意阵营 id。
Definition Battle.cpp:28
void setPlayerSide(int side)
玩家阵营 id(isVictory/isDefeat 依据),默认 0。
Definition Battle.cpp:185
int getPlayerSide() const
Returns the player side.
Definition Battle.cpp:186
void autoEnemyActions()
未设行动的 AI 侧自动选一个随机已学技能(或普攻)打随机存活敌对目标。
Definition Battle.cpp:272
bool getEventCrit(int index) const
Returns the event crit.
Definition Battle.cpp:526
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:103
void setAction(RPGActor *actor, const std::string &skillId, RPGActor *target=nullptr)
为参战者设置本回合行动;target 为空由目标规则自动解析。
Definition Battle.cpp:194
double getEventAmount(int index) const
Returns the event amount.
Definition Battle.cpp:522
int getSide(int index) const
Returns the side.
Definition Battle.cpp:491
eve::Result< void > configureSeed(std::uint64_t seed)
Inject the hit/target random stream before the first round; fold the seed into the engine's 32-bit st...
Definition Battle.cpp:20
std::string getEventSkillId(int index) const
Returns the event skill id.
Definition Battle.cpp:510
int getWinnerSide() const
获胜阵营 id;未结束或平局(双方全灭)返回 -1。
Definition Battle.cpp:191
RPGActor * getEventCaster(int index) const
Return the caster of a polled event, or null when out of range.
Definition Battle.cpp:514
RPGActor * getEventTarget(int index) const
Return the target of a polled event, or null when out of range.
Definition Battle.cpp:518
std::string getEventAction(int index) const
Returns the event action.
Definition Battle.cpp:506
int getTurn() const
当前回合数(1 起)。
Definition Battle.cpp:192
bool isActorAlive(RPGActor *actor) const
True when actor alive.
Definition Battle.cpp:138
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:214
void pollEvents()
Polls events.
Definition Battle.cpp:501
BattleEvent getEvent(int index) const
Returns the event.
Definition Battle.cpp:497
int getActorCount() const
Returns the actor count.
Definition Battle.cpp:486
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:254
bool executeNextAction()
执行下一条行动(compatibility facade (脚本兼容门面));返回是否执行了一条。
Definition Battle.cpp:316
bool isDefeat() const
是否战败:已结束且获胜方 != 玩家侧。
Definition Battle.cpp:190
int getEventCount() const
Returns the event count.
Definition Battle.cpp:496
bool isFinished() const
战斗是否已结束(仅剩一方存活 / 双方全灭)。
Definition Battle.cpp:188
bool isVictory() const
是否胜利:获胜方 == 玩家侧。
Definition Battle.cpp:189
属性 / 状态 / 技能三表合一的 ECS 实体。
Definition RPGActor.h:34
bool knowsSkill(const std::string &skillId)
Definition RPGActor.cpp:181
static const SkillDefinition * find(const std::string &id)
Find a registered skill definition by id.
Definition Skill.cpp:98
EVENGINE_API_PLATFORM public API.
Definition SkillSystem.h:23
static std::string getTargetType(RPGActor *actor, const std::string &skillId)
技能的目标类型字符串("" 表示未学会/未知)。
static bool beginCast(RPGActor *actor, const std::string &skillId, RPGActor *target=nullptr, std::string *reason=nullptr)
尝试释放技能:通过 canCast 检查后立即扣除消耗并进入冷却; castTime<=0 时立即结算(授予效果 + 产生 SkillCastEvent), 否则进入读条状态,由 update() 在读...
static double getAttackSpeed(RPGActor *actor)
攻击速度修正(加值)。
Definition Trait.cpp:287
static double getCurrent(RPGActor *actor, const std::string &resource)
当前值(无 vitals/资源时 0)。
static double getMax(RPGActor *actor, const std::string &resource)
上限:取 actor 同名最终属性(getFinalAttribute),无则 0。
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.
static bool isDead(RPGActor *actor, const std::string &resource)
是否死亡:max > 0 且 current <= 0。
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.
Validated immutable-style rule collection installable into pipelines.
eve::Result< void > install(SettlementPipeline &pipeline) const
Install a stable snapshot as custom stages on a pipeline.
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
RPG 模块的基础实体:把属性 / 状态 / 技能三张表挂到一个 ECS 实体上。
BattleTargetPolicy
Deterministic target-selection policies for queued battle actions.
Definition Battle.h:36
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.
::eve::SubjectRef SubjectRef
Strong reference to a runtime subject.
Definition Targeting.h:68
eve::Result< SettlementRuleSet > projectEffectRules(const effects::EffectContainer &effects, std::string_view scope)
Project active effect payloads into an owning settlement rule snapshot.
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
StrongUuid< detail::PersistentIdTag > PersistentId
Stable instance identity for persistence, networking and process boundaries.
Definition Identity.h:253
detail::StrongUint64< detail::SimulationTickTag > SimulationTick
Deterministic simulation time step; it is not wall-clock time.
Definition Time.h:31
RPG vitals and attribute policy adapter for the common settlement pipeline.
一次战斗反馈事件。
Definition Battle.h:39
周期性状态触发的 tick 事件。周期效果(period > 0)不会自动修改属性, 而是每个周期产生一个 tick 事件交给上层(脚本或 C++ 结算系统)处理—— 这样伤害/治疗类周期效果可以完整地...
Definition StatusTypes.h:70
Domain-neutral input to one settlement operation.
Definition Settlement.h:107