载入中...
搜索中...
未找到
RPGActor.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
18#include "common/ECS.h"
19#include "rpg/AttributeTypes.h"
20#include "rpg/StatusTypes.h"
21#include "rpg/SkillTypes.h"
22
23#include <string>
24#include <string_view>
25#include <unordered_map>
26#include <vector>
27
28namespace eve::rpg {
29
30class RPGSaveSession;
31class Party;
32
34class EVENGINE_API_PLATFORM RPGActor : public ecs::Entity {
35public:
37 ENTITY(RPGActor, ecs::Entity)
38
39
40 void release() override { ecs::DestroyEntity(this); }
41
49
58 struct Statuses {
60 std::unordered_map<std::string, StatusExecutorMetadata> metadata;
61 std::unordered_map<std::string, int> legacyIdByEffect;
62 std::unordered_map<int, std::string> effectByLegacyId;
63 int nextInstanceId = 1;
64 };
65
67 struct Skills {
68 std::unordered_map<std::string, SkillRuntime> known;
70 };
71
73 struct Progression {
74 int level = 1;
75 double xp = 0.0;
76 double xpToNext = 100.0;
77 };
78
83 struct Vitals {
84 std::unordered_map<std::string, double> current;
85 };
86
89 int instanceId = 0;
90 std::string traitId;
91 std::string source;
92 };
93
95 struct Traits {
96 std::vector<TraitInstance> active;
97 int nextInstanceId = 1;
98 };
99
101 struct ClassInfo {
102 std::string classId;
103 int skillsSyncedUpTo = 0;
104 };
105
106 COMPONENT(Attributes, attributes)
107 COMPONENT(Statuses, statuses)
108 COMPONENT(Skills, skills)
109 COMPONENT(Progression, progression)
110 COMPONENT(Vitals, vitals)
111 COMPONENT(Traits, traits)
112 COMPONENT(ClassInfo, classInfo)
113
114
123 static RPGActor *createActor();
124
133 void setBaseAttribute(const std::string &attribute, double value);
134 double getBaseAttribute(const std::string &attribute);
135 void modifyBaseAttribute(const std::string &attribute, double delta);
136 bool hasAttribute(const std::string &attribute);
138 [[nodiscard]] eve::Result<ModifierId> addAttributeModifier(AttributeModifier modifier);
140 std::string addAttributeModifier(const std::string &attribute, const std::string &source, const std::string &op,
141 double value, int priority = 0);
143 [[nodiscard]] eve::Result<void> removeAttributeModifier(const ModifierId &modifierId);
144 bool removeAttributeModifier(const std::string &attribute, const std::string &modifierId);
145 int removeAttributeModifiersBySource(const std::string &attribute, const std::string &source);
146 int removeAllAttributeModifiersBySource(const std::string &source);
147 double getFinalAttribute(const std::string &attribute);
148
150 int applyEffect(const std::string &effectId, const std::string &source = "");
151 bool removeStatus(int instanceId);
152 int removeStatusByEffect(const std::string &effectId);
153 int removeStatusBySource(const std::string &source);
154 int removeStatusByTag(const std::string &tag);
155 bool hasEffect(const std::string &effectId);
156 bool hasStatusTag(const std::string &tag);
157 int getStatusCount();
158 std::string getStatusEffectId(int index);
159 int getStatusStacks(int index);
160 float getStatusRemaining(int index);
161 int getStatusInstanceId(int index);
162 std::string getStatusSource(int index);
163 std::string getStatusProp(int instanceId, const std::string &key,
164 const std::string &fallback = {});
165 bool setStatusProp(int instanceId, const std::string &key, const std::string &value);
166
168 int applyBuff(const std::string &effectId, const std::string &source = "");
169 bool removeBuff(int instanceId);
170 int removeBuffByEffect(const std::string &effectId);
171 int removeBuffBySource(const std::string &source);
172 int removeBuffByTag(const std::string &tag);
173 bool hasBuff(const std::string &effectId);
174 bool hasBuffTag(const std::string &tag);
175 int getBuffCount();
176 std::string getBuffEffectId(int index);
177 int getBuffStacks(int index);
178 float getBuffRemaining(int index);
179 int getBuffInstanceId(int index);
180 std::string getBuffSource(int index);
181 std::string getBuffProp(int instanceId, const std::string &key,
182 const std::string &fallback = {});
183 bool setBuffProp(int instanceId, const std::string &key, const std::string &value);
184
186 void learnSkill(const std::string &skillId);
187 bool knowsSkill(const std::string &skillId);
188 bool forgetSkill(const std::string &skillId);
189 float getSkillCooldown(const std::string &skillId);
190 void setSkillCooldown(const std::string &skillId, float seconds);
191 bool canCastSkill(const std::string &skillId);
193 std::string canCastSkillReason(const std::string &skillId);
195 bool beginCastSkill(const std::string &skillId, RPGActor *target = nullptr);
197 void cancelCastSkill();
199 bool isCastingSkill();
200 std::string getCastingSkillId();
201 float getCastProgress();
202
204 int getLevel();
205 double getXp();
206 double getXpToNext();
207 void setXpToNext(double value);
219 [[nodiscard]] eve::Result<void> restoreProgression(int level, double xp, double xpToNext);
221 bool gainXp(double amount);
222
224 double getCurrent(const std::string &resource);
225 double getMax(const std::string &resource);
226 void setCurrent(const std::string &resource, double value);
227 double takeDamage(const std::string &resource, double amount, const std::string &source = "");
228 double heal(const std::string &resource, double amount);
229 void revive(const std::string &resource, double amount = -1.0);
230 bool isDead(const std::string &resource);
231
233 int applyTrait(const std::string &traitId, const std::string &source = "");
235 bool removeTrait(int instanceId);
236 int removeTraitsBySource(const std::string &source);
237 int removeTraitsByTrait(const std::string &traitId);
238 bool hasTrait(const std::string &traitId);
239 int getTraitCount();
240 int getTraitInstanceIdAt(int index);
241 std::string getTraitIdAt(int index);
242 std::string getTraitSourceAt(int index);
243 double getParamRate(const std::string &param);
244 double getElementRate(const std::string &element);
245 double getStateRate(const std::string &stateId);
246 bool isStateResist(const std::string &stateId);
247 double getExParam(const std::string &exParam);
248 double getAttackSpeed();
249 int getAttackTimesAdd();
250 std::vector<std::string> getAttackElements();
251 std::vector<std::string> getAttackStates();
252
255 bool setClass(const std::string &classId);
256 std::string getClassId();
257 bool hasClass(const std::string &classId);
258 int checkLevelSkills();
259 int getClassLearnCount();
260 std::string getClassLearnSkillIdAt(int index);
261 int getClassLearnLevelAt(int index);
262
272 [[nodiscard]] eve::Result<std::string> checkpointJson() const;
273
284 [[nodiscard]] eve::Result<void> restoreCheckpointJson(std::string_view json);
285
296 static const std::vector<RPGActor *> &liveActors();
297
298private:
299 struct CheckpointCandidate {
300 Attributes attributes;
301 Skills skills;
302 Progression progression;
303 Vitals vitals;
304 ClassInfo classInfo;
305 };
306
307 [[nodiscard]] eve::Result<CheckpointCandidate> prepareCheckpointJson(std::string_view json) const;
308 void commitCheckpoint(CheckpointCandidate candidate) noexcept;
309 friend class RPGSaveSession;
310 friend class Party;
311};
312
313} // namespace eve::rpg
LogicalId target
double value
RPG compatibility names for the canonical attributes data model.
int priority
std::map< std::string, Var > values
#define EVENGINE_API_PLATFORM
Definition Export.h:107
std::uint32_t key
int level
const std::string * tag
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
std::string resource
std::string string
std::string element
std::uint32_t classId
uint32_t index
const UnitySourceAsset & source
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Generic owning collection of canonical attributes and modifiers.
Owns active effect instances and their deterministic lifecycle events.
Authoritative ordered relationship between stable party member IDs and RPG actors....
Definition Party.h:24
属性 / 状态 / 技能三表合一的 ECS 实体。
Definition RPGActor.h:34
A non-owning save boundary for the persistent classic-RPG state owners.
constexpr int Party
Definition Battle.h:31
RPG 模块的基础实体:把属性 / 状态 / 技能三张表挂到一个 ECS 实体上。
::eve::attributes::ModifierId ModifierId
One canonical runtime modifier applied to one named attribute.
施法状态:同一时间每个 actor 只有一个进行中的引导/读条(可按需扩展为多槽)。
Definition SkillTypes.h:16
属性组件:AttributeSet 是属性状态与计算的唯一权威真源。
Definition RPGActor.h:43
Attributes()
Constructs a Attributes.
Definition RPGActor.h:45
::eve::attributes::AttributeSet values
Definition RPGActor.h:47
职业:当前职业 id + 已同步学技能的等级上限。
Definition RPGActor.h:101
成长进度:等级 / 经验 / 升级所需经验。
Definition RPGActor.h:73
已学会技能的冷却状态 + 当前读条状态。
Definition RPGActor.h:67
std::unordered_map< std::string, SkillRuntime > known
Definition RPGActor.h:68
Status lifecycle component backed by the generic effects container.
Definition RPGActor.h:58
std::unordered_map< std::string, int > legacyIdByEffect
Definition RPGActor.h:61
::eve::effects::EffectContainer container
Definition RPGActor.h:59
std::unordered_map< std::string, StatusExecutorMetadata > metadata
Definition RPGActor.h:60
std::unordered_map< int, std::string > effectByLegacyId
Definition RPGActor.h:62
已施加的运行时特征实例。
Definition RPGActor.h:88
该 actor 的活动特征列表(TraitSystem 读写)。
Definition RPGActor.h:95
std::vector< TraitInstance > active
Definition RPGActor.h:96
当前资源(hp / mana ...):current 是运行时瞬时值,上限取同名最终属性。 max 由 attributes 推导(getFinalAttribute(resource)),本组件只存...
Definition RPGActor.h:83
std::unordered_map< std::string, double > current
Definition RPGActor.h:84