#include "cmd.h" #include "utils.h" #include "creature.h" #include "dice.h" #include "weapon.h" #include namespace cmd { std::string attacks(std::vector args) { std::stringstream text; auto c = utils::instantiate(getTruePath(args[0])); for(auto w : creature::getAttacks(*c)) { text << w->getName() << std::endl; } return text.str(); } std::string roll(std::vector args) { std::stringstream text; auto c = utils::instantiate(getTruePath(args[0])); args.erase(args.begin()); std::string rollName = utils::join(args, " "); utils::lower(rollName); int rolled = dice::roll(20); auto printResults = [&text](std::string name, std::string type, int rolled, int bonus) { text << name << " " << type << ": " << rolled << " (d20) + " << bonus << " (" << name << " " << type << " bonus) = " << rolled + bonus << std::endl; }; // Search through skills, saves, and attacks to roll if(rollName == "init" or rollName == "initiative") { printResults("Initiative", "check", rolled, c->getInitiative()); } rules::Skill skill = rules::tryGetAbilityOrSkill(rollName); rules::Ability ability = rules::tryGetAbilityOrSkill(rollName); if(skill) { printResults(skill.getName(), "check", rolled, c->getSkillBonus(skill)); } else if(ability) { printResults(ability.getFull(), "save", rolled, c->getAbilitySaveBonus(ability)); } else { for(auto w : creature::getAttacks(*c)) { if(w->getName() == rollName) { text << w->getText(*c) << std::endl; int bonus = w->getToHitBonus(*c); printResults(w->getName(), "attack", rolled, bonus); text << " on hit: " << entry::formatDmg(*w, *c) << std::endl; break; } } } return text.str(); } }