diff options
Diffstat (limited to 'src/cmd/cmd_manipulate.cc')
-rw-r--r-- | src/cmd/cmd_manipulate.cc | 41 |
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(); } |