aboutsummaryrefslogtreecommitdiff
path: root/src/spellcasting.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-05 09:44:50 -0400
committerYour Name <you@example.com>2021-05-05 09:44:50 -0400
commit2a9f262e6db5906db445d465e500d7ba8c90fab3 (patch)
tree34f850754b0c9114ede9d7b2bb8da90dffddc4fe /src/spellcasting.cc
parent8614137f7f32f2c9f3c11419110cd70dd7f3b505 (diff)
downloaddmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.tar.gz
dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.tar.bz2
dmtool-2a9f262e6db5906db445d465e500d7ba8c90fab3.zip
Implemented additional commands
Diffstat (limited to 'src/spellcasting.cc')
-rw-r--r--src/spellcasting.cc34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/spellcasting.cc b/src/spellcasting.cc
index 9b39741..2606b53 100644
--- a/src/spellcasting.cc
+++ b/src/spellcasting.cc
@@ -8,6 +8,20 @@
using namespace std;
namespace entry {
+ shared_ptr<SlotLevel> SlotLevel::create(const json& data) {
+ return shared_ptr<SlotLevel>(new SlotLevel(data));
+ }
+
+ vector<shared_ptr<Spell>> Spellcasting::getSpells() const {
+ vector<shared_ptr<Spell>> ret;
+ for(auto sl : getSlotLevels()) {
+ for(auto spell : sl->spells) {
+ ret.push_back(spell);
+ }
+ }
+ return ret;
+ }
+
string Spellcasting::getText(const creature::Creature& c) const {
return genText(*this, c);
}
@@ -21,10 +35,15 @@ namespace entry {
if(s.isInnate()) {
text << " Spellcasting is innate.";
}
- int levelNumber = 0;
- for(auto level : s.getSpellsBySlot()) {
+ int levelNumber = -1;
+ for(auto level : s.getSlotLevels()) {
+ levelNumber++;
+ // Skip if it's empty
+ if(level->numSlots == 0 && level->spells.empty()) {
+ continue;
+ }
text << endl;
- if(level.numSlots == 0) {
+ if(levelNumber == 0) {
if(s.isInnate()) {
text << " At will: ";
} else {
@@ -32,17 +51,16 @@ namespace entry {
}
} else {
if(s.isInnate()) {
- text << " " << level.numSlots << "/day each: ";
+ text << " " << level->numSlots << "/day each: ";
} else {
- text << " " << utils::toOrdinal(levelNumber) << " level (" << level.numSlots << " slots): ";
+ text << " " << utils::toOrdinal(levelNumber) << " level (" << level->numSlots << " slots): ";
}
}
vector<string> names;
- for(auto spell : level.spells) {
- names.push_back(spell.getName());
+ for(auto spell : level->spells) {
+ names.push_back(spell->getName());
}
text << utils::join(names, ", ");
- levelNumber++;
}
return text.str();