aboutsummaryrefslogtreecommitdiff
path: root/src/spellcasting.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-04-15 15:23:23 -0400
committerYour Name <you@example.com>2021-04-15 15:23:23 -0400
commitdfce4d0398a8bafbb7ad7a31345af181c0269c09 (patch)
tree695162ff8cc25e146f52d9e26fe19ffa9934b3d6 /src/spellcasting.h
parent9034c3d2533177f7cb7a7ce939ec53f7fa63f60e (diff)
downloaddmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.tar.gz
dmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.tar.bz2
dmtool-dfce4d0398a8bafbb7ad7a31345af181c0269c09.zip
Added spells
Diffstat (limited to 'src/spellcasting.h')
-rw-r--r--src/spellcasting.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/spellcasting.h b/src/spellcasting.h
new file mode 100644
index 0000000..f996322
--- /dev/null
+++ b/src/spellcasting.h
@@ -0,0 +1,46 @@
+#pragma once
+#include "feature.h"
+#include "json.hpp"
+#include "spell.h"
+#include "jsonable.h"
+
+typedef nlohmann::json json;
+
+namespace feature {
+ struct SlotLevel : public Jsonable {
+ SlotLevel(const json& data) : numSlots(data["slots"]), spells(jsonList2vec<spell::Spell>("spellcasting", data["spells"])) {}
+ virtual ~SlotLevel() {}
+ const int numSlots;
+ const std::vector<spell::Spell> spells;
+
+ json toJson(void) const {
+ return json({
+ {"slots", numSlots},
+ {"spells", spells}
+ });
+ }
+ };
+
+ class Spellcasting : public Feature {
+ public:
+ Spellcasting(const json& data, const json& base) : Feature(base), innate(data["innate"]), ability(data["spellcasting_ability"]), spellsBySlot(json2vec<SlotLevel>(data["levels"])) {}
+ virtual ~Spellcasting() {}
+
+ bool isInnate(void) const {return innate;}
+ std::string getAbility(void) const {return ability;}
+ std::vector<SlotLevel> getSpellsBySlot(void) const {return spellsBySlot;}
+
+ virtual json toJson(void) const {
+ auto data = Feature::toJson();
+ data["innate"] = innate;
+ data["ability"] = ability;
+ data["levels"] = spellsBySlot;
+ return data;
+ }
+
+ private:
+ const bool innate;
+ const std::string ability;
+ const std::vector<SlotLevel> spellsBySlot;
+ };
+}