diff options
author | Your Name <you@example.com> | 2021-05-18 16:26:49 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-05-18 16:26:49 -0400 |
commit | 38e33d8756a5b652965be8ada478b5c4238b857c (patch) | |
tree | d4e3b166103c4c0cc8d3a4ed963333a2982bb366 /src/cmd_manipulate.cc | |
parent | e044fc4255aa64ef1dbc3d20ed87ed6e2f61a6bd (diff) | |
download | dmtool-38e33d8756a5b652965be8ada478b5c4238b857c.tar.gz dmtool-38e33d8756a5b652965be8ada478b5c4238b857c.tar.bz2 dmtool-38e33d8756a5b652965be8ada478b5c4238b857c.zip |
Added spellcasting command
Diffstat (limited to 'src/cmd_manipulate.cc')
-rw-r--r-- | src/cmd_manipulate.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/cmd_manipulate.cc b/src/cmd_manipulate.cc index 1300008..9fc019e 100644 --- a/src/cmd_manipulate.cc +++ b/src/cmd_manipulate.cc @@ -204,4 +204,46 @@ namespace cmd { utils::saveJson(*e, p); return ""; } + + std::string spellcasting(std::vector<std::string> args) { + std::stringstream text; + auto p = getTruePath(args[0]); + auto c = utils::instantiate<creature::Creature>(p); + auto subcommand = args[1]; + if(subcommand != "init" && subcommand != "ability" && subcommand != "level") { + throw std::runtime_error("Unknown option \"" + subcommand + "\""); + } + if(subcommand == "init") { + c->addSpellcasting(); + } else { + auto sc = c->getSpellcasting(); + if(! sc) { + throw std::runtime_error("Creature " + c->getName() + " has no spellcasting"); + } + text << "Added spellcasting to " << c->getName() << std::endl; + if(subcommand == "ability") { + if(args.size() != 3) { + throw std::runtime_error("Subcommand \"spellcasting ability\" requires an additional parameter, but none was given"); + } + sc->setAbility(args[2]); + text << "Set " << c->getName() << " spellcasting ability to " << args[2] << std::endl; + } else { // subcommand == "level" + if(args.size() != 4) { + throw std::runtime_error("Subcommand \"spellcasting level\" requires more parameters"); + } + int level = utils::parseInt(args[2]); + int slots = utils::parseInt(args[3]); + if(level <= 0 || slots < 0) { + throw std::runtime_error("Spellcasting target out of range"); + } + while(sc->getSlotLevels().size() <= (std::size_t) level) { + sc->addSlotLevel(); + } + sc->getSlotLevels()[level]->numSlots = slots; + text << "Gave " << c->getName() << " " << slots << " " << utils::toOrdinal(level) << " level spell slots" << std::endl; + } + } + utils::saveJson(*c, p); + return text.str(); + } } |