diff --git a/src/map/skills/main.cpp b/src/map/skills/main.cpp index 8c45c05a42..e3fb84fb7a 100644 --- a/src/map/skills/main.cpp +++ b/src/map/skills/main.cpp @@ -1,15 +1,41 @@ #include "skill.hpp" #include "skills.hpp" -#include "swordsman/bash.hpp" -#include "swordsman/provoke.hpp" +// #include "swordsman/bash.hpp" +// #include "swordsman/provoke.hpp" + +#include "skilllist.hpp" + + int main() { - Bash bash; - Provoke provoke; - bash.castend_damage_id(); - provoke.castend_nodamage_id(); + constexpr int skill_id = SM_BASH; + + const auto &sk = skill_db.at(static_cast(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; } diff --git a/src/map/skills/skill.hpp b/src/map/skills/skill.hpp index e8f7a45d09..38cb7700e2 100644 --- a/src/map/skills/skill.hpp +++ b/src/map/skills/skill.hpp @@ -15,16 +15,20 @@ constexpr int MAX_SKILL_LEVEL = 13; template class Skill { public: - int castend_damage_id() { - return as_underlying().castend_damage_id(); + int castend_damage_id() const { + return as_underlying().castendDamageId(); }; - int castend_nodamage_id() { - return as_underlying().castend_nodamage_id(); + int castend_nodamage_id() const { + return as_underlying().castendNoDamageId(); }; - int castend_pos2() { - return as_underlying().castend_pos2(); + int castend_pos2() const { + return as_underlying().castendPos2(); }; + uint16_t getSkillID() const { + return nameid; + } + protected: explicit Skill(e_skill skillid) : nameid(static_cast(skillid)) {}; private: @@ -38,6 +42,10 @@ private: inline T& as_underlying() { return static_cast(*this); } + + inline const T& as_underlying() const { + return static_cast(*this); + } }; diff --git a/src/map/skills/skilllist.hpp b/src/map/skills/skilllist.hpp new file mode 100644 index 0000000000..0fdb4c517f --- /dev/null +++ b/src/map/skills/skilllist.hpp @@ -0,0 +1,15 @@ +#include + +#include "skill.hpp" +#include "skills.hpp" + +#include "swordsman/bash.hpp" +#include "swordsman/provoke.hpp" + + +using SkillImpl = std::variant; + +std::unordered_map skill_db = { + { e_skill::SM_BASH, Bash{} }, + { e_skill::SM_PROVOKE, Provoke{} } +}; diff --git a/src/map/skills/skills.hpp b/src/map/skills/skills.hpp index 55ddefb2f8..5ddbf4fdbd 100644 --- a/src/map/skills/skills.hpp +++ b/src/map/skills/skills.hpp @@ -5,13 +5,7 @@ #define MAP_SKILLS_HPP #include - -enum e_skill; - -template -class Skill; - -inline std::unordered_map skills; +#include "skill.hpp" /// List of Skills enum e_skill { diff --git a/src/map/skills/swordsman/bash.hpp b/src/map/skills/swordsman/bash.hpp index 090b2557f9..fcbd4e0b7c 100644 --- a/src/map/skills/swordsman/bash.hpp +++ b/src/map/skills/swordsman/bash.hpp @@ -5,9 +5,9 @@ #include "../skills.hpp" -class Bash : Skill { +class Bash : public Skill { public: - int castend_damage_id() { + int castendDamageId() const { return 0; }; diff --git a/src/map/skills/swordsman/provoke.hpp b/src/map/skills/swordsman/provoke.hpp index 8667ca7c4f..bb4e43db3a 100644 --- a/src/map/skills/swordsman/provoke.hpp +++ b/src/map/skills/swordsman/provoke.hpp @@ -4,9 +4,9 @@ #include "../skill.hpp" -class Provoke : Skill { +class Provoke : public Skill { public: - int castend_nodamage_id() { + int castendNoDamageId() const { return 0; };