Double visitor?
This commit is contained in:
parent
28383ee332
commit
95ee5d04e6
@ -1,15 +1,41 @@
|
|||||||
|
|
||||||
#include "skill.hpp"
|
#include "skill.hpp"
|
||||||
#include "skills.hpp"
|
#include "skills.hpp"
|
||||||
#include "swordsman/bash.hpp"
|
// #include "swordsman/bash.hpp"
|
||||||
#include "swordsman/provoke.hpp"
|
// #include "swordsman/provoke.hpp"
|
||||||
|
|
||||||
|
#include "skilllist.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Bash bash;
|
|
||||||
Provoke provoke;
|
|
||||||
|
|
||||||
bash.castend_damage_id();
|
constexpr int skill_id = SM_BASH;
|
||||||
provoke.castend_nodamage_id();
|
|
||||||
|
const auto &sk = skill_db.at(static_cast<e_skill>(skill_id));
|
||||||
|
|
||||||
|
const SkillImpl sk2 = Bash{};
|
||||||
|
|
||||||
|
std::visit([](auto &skill) {
|
||||||
|
skill.getSkillID();
|
||||||
|
|
||||||
|
skill.castend_damage_id(); // error
|
||||||
|
// skill.hpp:19:26: error: ‘const class Provoke’ has no member named ‘castendDamageId’; did you mean ‘castendNoDamageId’?
|
||||||
|
// 19 | return as_underlying().castendDamageId();
|
||||||
|
// | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
|
||||||
|
// | castendNoDamageId
|
||||||
|
|
||||||
|
}, sk2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (auto &it : skill_db) {
|
||||||
|
std::visit([](auto &skill) {
|
||||||
|
skill.getSkillID();
|
||||||
|
|
||||||
|
// skill.castend_damage_id();
|
||||||
|
}, it.second);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,16 +15,20 @@ constexpr int MAX_SKILL_LEVEL = 13;
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class Skill {
|
class Skill {
|
||||||
public:
|
public:
|
||||||
int castend_damage_id() {
|
int castend_damage_id() const {
|
||||||
return as_underlying().castend_damage_id();
|
return as_underlying().castendDamageId();
|
||||||
};
|
};
|
||||||
int castend_nodamage_id() {
|
int castend_nodamage_id() const {
|
||||||
return as_underlying().castend_nodamage_id();
|
return as_underlying().castendNoDamageId();
|
||||||
};
|
};
|
||||||
int castend_pos2() {
|
int castend_pos2() const {
|
||||||
return as_underlying().castend_pos2();
|
return as_underlying().castendPos2();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint16_t getSkillID() const {
|
||||||
|
return nameid;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Skill(e_skill skillid) : nameid(static_cast<uint16_t>(skillid)) {};
|
explicit Skill(e_skill skillid) : nameid(static_cast<uint16_t>(skillid)) {};
|
||||||
private:
|
private:
|
||||||
@ -38,6 +42,10 @@ private:
|
|||||||
inline T& as_underlying() {
|
inline T& as_underlying() {
|
||||||
return static_cast<T&>(*this);
|
return static_cast<T&>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const T& as_underlying() const {
|
||||||
|
return static_cast<const T&>(*this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
15
src/map/skills/skilllist.hpp
Normal file
15
src/map/skills/skilllist.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <variant>
|
||||||
|
|
||||||
|
#include "skill.hpp"
|
||||||
|
#include "skills.hpp"
|
||||||
|
|
||||||
|
#include "swordsman/bash.hpp"
|
||||||
|
#include "swordsman/provoke.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
using SkillImpl = std::variant<Bash, Provoke>;
|
||||||
|
|
||||||
|
std::unordered_map<e_skill, SkillImpl> skill_db = {
|
||||||
|
{ e_skill::SM_BASH, Bash{} },
|
||||||
|
{ e_skill::SM_PROVOKE, Provoke{} }
|
||||||
|
};
|
||||||
@ -5,13 +5,7 @@
|
|||||||
#define MAP_SKILLS_HPP
|
#define MAP_SKILLS_HPP
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include "skill.hpp"
|
||||||
enum e_skill;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class Skill;
|
|
||||||
|
|
||||||
inline std::unordered_map<e_skill, Skill> skills;
|
|
||||||
|
|
||||||
/// List of Skills
|
/// List of Skills
|
||||||
enum e_skill {
|
enum e_skill {
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
#include "../skills.hpp"
|
#include "../skills.hpp"
|
||||||
|
|
||||||
|
|
||||||
class Bash : Skill<Bash> {
|
class Bash : public Skill<Bash> {
|
||||||
public:
|
public:
|
||||||
int castend_damage_id() {
|
int castendDamageId() const {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -4,9 +4,9 @@
|
|||||||
#include "../skill.hpp"
|
#include "../skill.hpp"
|
||||||
|
|
||||||
|
|
||||||
class Provoke : Skill<Provoke> {
|
class Provoke : public Skill<Provoke> {
|
||||||
public:
|
public:
|
||||||
int castend_nodamage_id() {
|
int castendNoDamageId() const {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user