载入中...
搜索中...
未找到
Battle.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Result.h"
6#include "common/SubjectRef.h"
9
20#include <string>
21#include <vector>
22
23namespace eve::rpg {
24
25class RPGActor;
26class BattleTacticsCatalogue;
27struct StatusTickEvent;
28
30namespace BattleSide {
31inline constexpr int Party = 0;
32inline constexpr int Enemies = 1;
33} // namespace BattleSide
34
37
41 std::string action;
42 std::string skillId;
43 class RPGActor* caster = nullptr;
44 class RPGActor* target = nullptr;
45 double amount = 0.0;
46 bool crit = false;
47};
48
55public:
57 Battle() = default;
59 ~Battle() = default;
60
61 Battle(const Battle&) = delete;
62 Battle& operator=(const Battle&) = delete;
63
65 void addActor(RPGActor* actor, int side);
70 [[nodiscard]] eve::Result<void> configureSeed(std::uint64_t seed);
78 [[nodiscard]] eve::Result<void> configureSettlementRules(const settlement::SettlementRuleSet& rules);
91 const StatusTickEvent& tick, SubjectRef source, SimulationTick simulationTick);
93 void setAction(RPGActor* actor, const std::string& skillId, RPGActor* target = nullptr);
101 [[nodiscard]] eve::Result<void> setActionChecked(RPGActor* actor, const std::string& skillId,
102 RPGActor* target = nullptr);
109 [[nodiscard]] eve::Result<void> setActionByPolicyChecked(RPGActor* actor, const std::string& skillId,
110 BattleTargetPolicy policy);
112 void autoEnemyActions();
114 void startRound();
116 bool executeNextAction();
118 bool isFinished() const;
120 bool isVictory() const;
122 bool isDefeat() const;
124 void setPlayerSide(int side);
126 int getPlayerSide() const;
128 int getWinnerSide() const;
130 int getTurn() const;
132 bool isActorAlive(RPGActor* actor) const;
133
135 int getActorCount() const;
142 RPGActor* getActor(int index) const;
144 int getSide(int index) const;
145
147 int getEventCount() const;
149 BattleEvent getEvent(int index) const;
151 void pollEvents();
152 // 事件字段访问(脚本向)
154 std::string getEventAction(int index) const;
156 std::string getEventSkillId(int index) const;
163 RPGActor* getEventCaster(int index) const;
170 RPGActor* getEventTarget(int index) const;
172 double getEventAmount(int index) const;
174 bool getEventCrit(int index) const;
175
176private:
177 struct Participant {
178 RPGActor* actor = nullptr;
179 int side = 0;
180 SubjectRef settlementSubject;
181 };
182 struct PendingAction {
183 RPGActor* actor = nullptr;
184 std::string skillId;
185 RPGActor* target = nullptr;
186 double initiative = 0.0;
187 };
188
189 bool isDead(const Participant& p) const;
190 std::vector<RPGActor*> livingOnSide(int side) const;
191 int sideOf(RPGActor* actor) const;
192 SubjectRef settlementSubjectOf(RPGActor* actor) const noexcept;
198 RPGActor* randomOpponent(int mySide);
199 RPGActor* lowestHealthTarget(int side, bool sameSide) const;
200 int computeWinnerSide() const;
203 void execute(PendingAction& pa, unsigned& seedCounter);
204
205 std::vector<Participant> participants_;
206 std::vector<PendingAction> queue_;
207 std::vector<PendingAction> roundActions_;
208 std::vector<BattleEvent> events_;
209 std::vector<BattleEvent> polled_;
210 int turn_ = 0;
211 bool started_ = false;
212 bool finished_ = false;
213 int winner_ = -1;
214 int playerSide_ = BattleSide::Party;
215 unsigned seedCounter_ = 1;
216 std::uint64_t nextSettlementSubject_ = 1;
219};
220
221} // namespace eve::rpg
LogicalId target
glm::vec4 p[6]
#define EVENGINE_API_PLATFORM
Definition Export.h:107
const GltfImportRequest & request
Move-only, checked operation results for the common layer.
std::string_view source
Declarative, domain-neutral rules for buffs and gameplay effects.
Stable reference to a runtime gameplay subject.
SimulationTick tick
uint32_t seed
Definition TreeMesh.cpp:276
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Strong, domain-neutral reference to a runtime subject.
Definition SubjectRef.h:26
Process-local strict catalogue that selects and queues companion/AI actions.
一场回合制战斗(任意阵营数)。 @ownership 由调用方创建/销毁;Battle 不持有参与者的所有权(参与者为借用 ECS actor)。 @thread 在单一模拟线程上驱动整场战斗。
Definition Battle.h:54
Battle(const Battle &)=delete
Battle()=default
Battle.
Battle & operator=(const Battle &)=delete
~Battle()=default
Battle.
Authoritative ordered relationship between stable party member IDs and RPG actors....
Definition Party.h:24
属性 / 状态 / 技能三表合一的 ECS 实体。
Definition RPGActor.h:34
Deterministically ordered, composable settlement pipeline.
Definition Settlement.h:542
Validated immutable-style rule collection installable into pipelines.
constexpr int Enemies
Definition Battle.h:32
RPG 模块的基础实体:把属性 / 状态 / 技能三张表挂到一个 ECS 实体上。
BattleTargetPolicy
Deterministic target-selection policies for queued battle actions.
Definition Battle.h:36
Domain-neutral, deterministic settlement pipeline.
一次战斗反馈事件。
Definition Battle.h:39
std::string skillId
Definition Battle.h:42
class RPGActor * caster
Definition Battle.h:43
class RPGActor * target
Definition Battle.h:44
std::string action
roundStart | actionStart | damage | heal | miss | effect | settlementFailed | victory | defeat
Definition Battle.h:41
周期性状态触发的 tick 事件。周期效果(period > 0)不会自动修改属性, 而是每个周期产生一个 tick 事件交给上层(脚本或 C++ 结算系统)处理—— 这样伤害/治疗类周期效果可以完整地...
Definition StatusTypes.h:70
Domain-neutral input to one settlement operation.
Definition Settlement.h:107