aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cmd_query.cc
blob: 9c2dae6a3dc604fac7a7621ee24eb9002690546f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "cmd.h"
#include "../utils.h"
#include "../creature.h"
#include "../dice.h"
#include "../weapon.h"
#include <sstream>

namespace cmd {
    std::string attacks(std::vector<std::string> args) {
        std::stringstream text;
	auto c = utils::instantiate<creature::Creature>(getTruePath(args[0]));
	for(auto w : creature::getAttacks(*c)) {
	    text << w->getName() << std::endl;
	}
        return text.str();
    }

    std::string roll(std::vector<std::string> args) {
        std::stringstream text;
	auto c = utils::instantiate<creature::Creature>(getTruePath(args[0]));
	args.erase(args.begin());
	std::string rollName = utils::join(args, " ");
	utils::lower(rollName);
	int rolled = dice::roll(20);
	// Search through skills, saves, and attacks to roll
        if(rollName == "init" or rollName == "initiative") {
            text << formatRoll("Initiative", "check", rolled, c->getInitiative());
        }
	rules::Skill skill = rules::tryGetAbilityOrSkill<rules::Skill>(rollName);
	rules::Ability ability = rules::tryGetAbilityOrSkill<rules::Ability>(rollName);
	if(skill) {
	    text << formatRoll(skill.getName(), "check", rolled, c->getSkillBonus(skill));
	} else if(ability) {
	    text << formatRoll(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);
                    text << formatRoll(w->getName(), "attack", rolled, bonus);
		    text << "  on hit: " << entry::formatDmg(*w, *c) << std::endl;
		    break;
		}
	    }
	}
        return text.str();
    }
}