From 38e33d8756a5b652965be8ada478b5c4238b857c Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 18 May 2021 16:26:49 -0400 Subject: Added spellcasting command --- src/cmd_manipulate.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/cmd_manipulate.cc') 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 args) { + std::stringstream text; + auto p = getTruePath(args[0]); + auto c = utils::instantiate(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(); + } } -- cgit v1.2.3