载入中...
搜索中...
未找到
ClassSystem.cpp
浏览该文件的文档.
1#include "rpg/ClassSystem.h"
2
3#include "rpg/Class.h"
4#include "rpg/LevelSystem.h"
5#include "rpg/RPGActor.h"
6#include "rpg/SkillSystem.h"
7#include "rpg/TraitSystem.h"
8
9#include <algorithm>
10
11namespace eve::rpg {
12
13bool ClassSystem::setClass(RPGActor *actor, const std::string &classId) {
14 if (!actor) return false;
16 if (!def) return false;
17 auto &ci = *actor->classInfo();
18 // 撤销旧职业特征
19 if (!ci.classId.empty()) {
20 TraitSystem::removeBySource(actor, "class:" + ci.classId);
21 }
22 ci.classId = classId;
23 ci.skillsSyncedUpTo = 0;
24 // 施加新职业特征
25 for (const auto &traitId : def->traits) {
26 TraitSystem::apply(actor, traitId, "class:" + classId);
27 }
28 checkLevelSkills(actor);
29 return true;
30}
31
32std::string ClassSystem::getClassId(RPGActor *actor) {
33 return actor ? actor->classInfo()->classId : std::string{};
34}
35
36bool ClassSystem::hasClass(RPGActor *actor, const std::string &classId) {
37 return actor && actor->classInfo()->classId == classId;
38}
39
41 if (!actor) return 0;
42 const ClassDefinition *def = ClassRegistry::find(actor->classInfo()->classId);
43 if (!def) return 0;
44 auto &ci = *actor->classInfo();
45 const int level = LevelSystem::getLevel(actor);
46 int learned = 0;
47 for (const auto &ls : def->learnSkills) {
48 if (ls.level <= ci.skillsSyncedUpTo) continue; // 已处理
49 if (ls.level <= level) {
50 if (!SkillSystem::knows(actor, ls.skillId)) {
51 SkillSystem::learn(actor, ls.skillId);
52 ++learned;
53 }
54 }
55 }
56 ci.skillsSyncedUpTo = std::max(ci.skillsSyncedUpTo, level);
57 return learned;
58}
59
61 if (!actor) return 0;
62 const ClassDefinition *def = ClassRegistry::find(actor->classInfo()->classId);
63 return def ? int(def->learnSkills.size()) : 0;
64}
65
67 if (!actor) return {};
68 const ClassDefinition *def = ClassRegistry::find(actor->classInfo()->classId);
69 if (!def || index < 0 || size_t(index) >= def->learnSkills.size()) return {};
70 return def->learnSkills[size_t(index)].skillId;
71}
72
74 if (!actor) return 0;
75 const ClassDefinition *def = ClassRegistry::find(actor->classInfo()->classId);
76 if (!def || index < 0 || size_t(index) >= def->learnSkills.size()) return 0;
77 return def->learnSkills[size_t(index)].level;
78}
79
80} // namespace eve::rpg
职业系统:设定职业、施加职业基础特征、按等级自动学习技能。
职业(Class)定义:可学技能(升级解锁)与职业基础特征,进程级注册表。
角色成长:等级 / 经验 / 升级。
int level
特征系统:施加/移除运行时特征,并提供耐性/特殊参数/攻击附加等查询。
std::uint32_t classId
uint32_t index
static const ClassDefinition * find(const std::string &id)
Find a registered class definition by id.
Definition Class.cpp:32
static int getLearnLevelAt(RPGActor *actor, int index)
Returns the learn level at.
static bool hasClass(RPGActor *actor, const std::string &classId)
是否已设定指定职业。
static std::string getClassId(RPGActor *actor)
当前职业 id(无则空)。
static std::string getLearnSkillIdAt(RPGActor *actor, int index)
Returns the learn skill id at.
static int getLearnCount(RPGActor *actor)
职业定义中可学技能总数。
static int checkLevelSkills(RPGActor *actor)
按当前等级补学尚未学过的升级技能。
static bool setClass(RPGActor *actor, const std::string &classId)
设定职业并施加职业基础特征(compatibility facade (脚本兼容门面);成功返回 true)。
static int getLevel(RPGActor *actor)
当前等级(无 progression 时返回 1)。
属性 / 状态 / 技能三表合一的 ECS 实体。
Definition RPGActor.h:34
static void learn(RPGActor *actor, const std::string &skillId)
Learn.
static bool knows(RPGActor *actor, const std::string &skillId)
Knows.
static int removeBySource(RPGActor *actor, const std::string &source)
移除该 actor 上所有来自 source 的特征;返回移除数。
static int apply(RPGActor *actor, const std::string &traitId, const std::string &source="")
施加一个特征。
RPG 模块的基础实体:把属性 / 状态 / 技能三张表挂到一个 ECS 实体上。
数据驱动的职业模板。
Definition Class.h:26
std::vector< std::string > traits
职业基础特征 id(施加于 actor)
Definition Class.h:30
std::vector< ClassLearnSkill > learnSkills
Definition Class.h:29