aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorYour Name <you@example.com>2023-11-22 15:28:00 -0500
committerYour Name <you@example.com>2023-11-22 15:28:00 -0500
commitae68e84557a7e56fd7210c1009aa1313dcc78adf (patch)
tree60616c822927847dd078f014c514a65f764607f3 /src/cmd
parent0d32e0d3342ef2455014c8e1164977c816763317 (diff)
downloaddmtool-ae68e84557a7e56fd7210c1009aa1313dcc78adf.tar.gz
dmtool-ae68e84557a7e56fd7210c1009aa1313dcc78adf.tar.bz2
dmtool-ae68e84557a7e56fd7210c1009aa1313dcc78adf.zip
Increased capacity for creating items from command line
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/cmd_manipulate.cc41
1 files changed, 7 insertions, 34 deletions
diff --git a/src/cmd/cmd_manipulate.cc b/src/cmd/cmd_manipulate.cc
index f0d3fc4..e29fd34 100644
--- a/src/cmd/cmd_manipulate.cc
+++ b/src/cmd/cmd_manipulate.cc
@@ -224,7 +224,9 @@ namespace cmd {
}
c->setProfLevel(skill, level);
} else if(ability) {
- c->setScore(ability, utils::parseInt(toSet));
+ if(toSet == "proficient") c->setProficientSave(ability);
+ else if(toSet == "none") c->removeProficientSave(ability);
+ else c->setScore(ability, utils::parseInt(toSet));
} else {
throw std::runtime_error("Subcommand 'set' expected an ability, skill, proficiency, or name field to set, but was given " + abilityOrSkill);
}
@@ -246,17 +248,8 @@ namespace cmd {
} else {
ent = entry::Entry::create(utils::findByName(addName));
}
- // Determine if it is an item or a spell
- auto i = std::dynamic_pointer_cast<entry::Item>(ent);
- if(i) {
- c->addInventoryItem(i);
- } else {
- auto s = std::dynamic_pointer_cast<entry::Spell>(ent);
- if(s) {
- c->addSpell(s);
- } else {
- throw std::runtime_error("Could not add the " + ent->getType() + " " + ent->getName() + " to " + c->getGivenName() + " the " + c->getName() + ": Requires a weapon, armor, or spell, but received object of type " + ent->getType());
- }
+ if(! creature::addEntry(ent, *c)) {
+ throw std::runtime_error("Could not add the " + ent->getType() + " " + ent->getName() + " to " + c->getGivenName() + " the " + c->getName() + ": Requires a weapon, armor, or spell, but received object of type " + ent->getType());
}
utils::saveJson(c->serialize(), p);
text << "Added the " << ent->getType() << " " << ent->getName() << " to " << c->getGivenName() << " the " << c->getName() << std::endl;
@@ -276,32 +269,12 @@ namespace cmd {
itemName = i->getName();
}
} catch(std::exception& e) {} // eat.
- utils::lower(itemName);
- // Loop through all of c's stuff, searching for itemName
- std::shared_ptr<entry::Entry> removed;
- for(auto item : c->getInventory()) {
- std::string name = item->getName();
- if(utils::lower(name) == itemName) {
- c->removeInventoryItem(item);
- removed = item;
- break;
- }
- }
- if(! removed) {
- for(auto spell : c->getSpellcasting()->getSpells()) {
- std::string name = spell->getName();
- if(utils::lower(name) == itemName) {
- c->removeSpell(spell);
- removed = spell;
- break;
- }
- }
- }
+ auto removed = creature::removeEntry(itemName, *c);
utils::saveJson(c->serialize(), p);
if(removed) {
text << "Successfully removed the " << removed->Entry::getType() << " " << removed->getName() << std::endl;
} else {
- text << "Could not find any inventory item nor spell by that name" << std::endl;
+ text << "Could not find any entry by that name" << std::endl;
}
return text.str();
}