#include <vector>
#include <utility>
#include <exception>
+#include <algorithm>
namespace sm::data
{
return d->life;
}
-Character::SkillTest Character::testSkill (Skill _skill, unsigned int against) const
+Character::SkillTest Character::testSkill (Skill _skill, unsigned int against, TestKind kind) const
{
std::uniform_int_distribution<int> d10 (1, 10);
std::random_device gen;
Attribute attr2 = skillAttributes.at (_skill).second;
unsigned int a1 = d->attributes.at (attr1);
unsigned int a2 = d->attributes.at (attr2);
+ unsigned int d1;
+ unsigned int d2;
+ ResultKind rk;
+
+ switch (kind) {
+ case TestKind::safe:
+ d1 = std::max (unsigned (d10 (gen) ), unsigned (d10 (gen) ) );
+ d2 = 0;
+ rk = ResultKind::normal;
+ break;
+ case TestKind::normal:
+ d1 = unsigned (d10 (gen) );
+ d2 = unsigned (d10 (gen) );
+ if (d1 + d2 <= 3) rk = ResultKind::catastrophic_failure;
+ else if (d1 + d2 >= 19) rk = ResultKind::excelent_pass;
+ else rk = ResultKind::normal;
+ break;
+ case TestKind::risk:
+ std::vector<unsigned int> vals;
+ for (int i = 0; i < 4; i++) {
+ vals.push_back (unsigned (d10 (gen) ) );
+ }
+ std::sort (vals.begin(), vals.end() );
+ if (vals[0] + vals[1] <= 3) rk = ResultKind::catastrophic_failure;
+ else if (vals[2] + vals[3] >= 19) rk = ResultKind::excelent_pass;
+ else rk = ResultKind::normal;
+ d1 = vals[2];
+ d2 = vals[3];
+
+ }
- unsigned int d1 = unsigned (d10 (gen) );
- unsigned int d2 = unsigned (d10 (gen) );
unsigned int accumulated = d1 + d2 + s + a1 + a2;
int delta = signed (accumulated) - signed (against);
- bool passed = delta >= 0;
- unsigned int grade = unsigned (std::abs (delta) / 3);
+ bool passed = rk != ResultKind::catastrophic_failure && delta >= 0;
+ int grade = (std::abs (delta) / 3);
+ if (delta < 0) grade *= -1;
+ if (rk == ResultKind::excelent_pass) grade += 3;
+ else if (rk == ResultKind::catastrophic_failure) grade = std::min (grade - 3, -1);
- return {passed, grade, s, a1, a2, d1, d2};
+ return {passed, rk, grade, s, a1, a2, d1, d2};
+}
+::std::ostream& operator<< (std::ostream& os, const sm::data::Character::SkillTest& st)
+{
+ os << "SkillTest{ Passed: " << st.passed
+ << " ResultKind: " << static_cast<unsigned int> (st.kind)
+ << " (" << st.d1 << ',' << st.d2 << ") "
+ << " Grades: " << st.grades
+ << '\n';
+ return os;
}
}
namespace sm::data
{
-enum Skill : unsigned int {
+enum class Skill : unsigned int {
acrobatics,
alchemy,
leadership,
windmagic
};
-enum Attribute : unsigned int {
+enum class Attribute : unsigned int {
charisma,
agility,
intuition,
willpower
};
-enum Damage : unsigned int {
+enum class Damage : unsigned int {
canalised,
exhausted,
used
};
-enum TestKind : unsigned int {
+enum class TestKind : unsigned int {
safe,
normal,
risk
};
+enum class ResultKind : unsigned int {
+ catastrophic_failure,
+ normal,
+ excelent_pass
+};
+
static const std::unordered_map<Skill, std::pair<Attribute, Attribute>> skillAttributes{
- {acrobatics, {agility, strength}},
- {alchemy, {mystic, mind}},
- {leadership, {charisma, willpower}},
- {arcanelore, {mystic, mind}},
- {athletics, {agility, strength}},
- {performance, {charisma, willpower}},
- {diplomacy, {charisma, mind}},
- {clscraft, {intuition, mind}},
- {empathy, {intuition, mind}},
- {determination, {charisma, willpower}},
- {dexterity, {charisma, agility}},
- {history, {mystic, mind}},
- {craftmanship, {constitution, mind}},
- {heal, {intuition, mind}},
- {stealth, {agility, intuition}},
- {hunting, {constitution, mind}},
- {countrylore, {intuition, mind}},
- {nature, {intuition, mind}},
- {eloquence, {charisma, willpower}},
- {locksntraps, {intuition, agility}},
- {swim, {strength, constitution}},
- {seafaring, {agility, constitution}},
- {streetlore, {charisma, intuition}},
- {animals, {charisma, agility}},
- {survival, {intuition, constitution}},
- {perception, {intuition, willpower}},
- {endurance, {constitution, willpower}},
- {antimagic, {mystic, willpower}},
- {controlmagic, {mystic, willpower}},
- {motionmagic, {mystic, agility}},
- {insightmagic, {mystic, mind}},
- {stonemagic, {mystic, constitution}},
- {firemagic, {mystic, charisma}},
- {healmagic, {mystic, charisma}},
- {illusionmagic, {mystic, charisma}},
- {combatmagic, {mystic, strength}},
- {lightmagic, {mystic, charisma}},
- {naturemagic, {mystic, charisma}},
- {shadowmagic, {mystic, intuition}},
- {fatemagic, {mystic, charisma}},
- {protectionmagic, {mystic, charisma}},
- {enhancemagic, {mystic, strength}},
- {deathmagic, {mystic, mind}},
- {transformationmagic, {mystic, constitution}},
- {watermagic, {mystic, intuition}},
- {windmagic, {mystic, mind}}
+ {Skill::acrobatics, {Attribute::agility, Attribute::strength}},
+ {Skill::alchemy, {Attribute::mystic, Attribute::mind}},
+ {Skill::leadership, {Attribute::charisma, Attribute::willpower}},
+ {Skill::arcanelore, {Attribute::mystic, Attribute::mind}},
+ {Skill::athletics, {Attribute::agility, Attribute::strength}},
+ {Skill::performance, {Attribute::charisma, Attribute::willpower}},
+ {Skill::diplomacy, {Attribute::charisma, Attribute::mind}},
+ {Skill::clscraft, {Attribute::intuition, Attribute::mind}},
+ {Skill::empathy, {Attribute::intuition, Attribute::mind}},
+ {Skill::determination, {Attribute::charisma, Attribute::willpower}},
+ {Skill::dexterity, {Attribute::charisma, Attribute::agility}},
+ {Skill::history, {Attribute::mystic, Attribute::mind}},
+ {Skill::craftmanship, {Attribute::constitution, Attribute::mind}},
+ {Skill::heal, {Attribute::intuition, Attribute::mind}},
+ {Skill::stealth, {Attribute::agility, Attribute::intuition}},
+ {Skill::hunting, {Attribute::constitution, Attribute::mind}},
+ {Skill::countrylore, {Attribute::intuition, Attribute::mind}},
+ {Skill::nature, {Attribute::intuition, Attribute::mind}},
+ {Skill::eloquence, {Attribute::charisma, Attribute::willpower}},
+ {Skill::locksntraps, {Attribute::intuition, Attribute::agility}},
+ {Skill::swim, {Attribute::strength, Attribute::constitution}},
+ {Skill::seafaring, {Attribute::agility, Attribute::constitution}},
+ {Skill::streetlore, {Attribute::charisma, Attribute::intuition}},
+ {Skill::animals, {Attribute::charisma, Attribute::agility}},
+ {Skill::survival, {Attribute::intuition, Attribute::constitution}},
+ {Skill::perception, {Attribute::intuition, Attribute::willpower}},
+ {Skill::endurance, {Attribute::constitution, Attribute::willpower}},
+ {Skill::antimagic, {Attribute::mystic, Attribute::willpower}},
+ {Skill::controlmagic, {Attribute::mystic, Attribute::willpower}},
+ {Skill::motionmagic, {Attribute::mystic, Attribute::agility}},
+ {Skill::insightmagic, {Attribute::mystic, Attribute::mind}},
+ {Skill::stonemagic, {Attribute::mystic, Attribute::constitution}},
+ {Skill::firemagic, {Attribute::mystic, Attribute::charisma}},
+ {Skill::healmagic, {Attribute::mystic, Attribute::charisma}},
+ {Skill::illusionmagic, {Attribute::mystic, Attribute::charisma}},
+ {Skill::combatmagic, {Attribute::mystic, Attribute::strength}},
+ {Skill::lightmagic, {Attribute::mystic, Attribute::charisma}},
+ {Skill::naturemagic, {Attribute::mystic, Attribute::charisma}},
+ {Skill::shadowmagic, {Attribute::mystic, Attribute::intuition}},
+ {Skill::fatemagic, {Attribute::mystic, Attribute::charisma}},
+ {Skill::protectionmagic, {Attribute::mystic, Attribute::charisma}},
+ {Skill::enhancemagic, {Attribute::mystic, Attribute::strength}},
+ {Skill::deathmagic, {Attribute::mystic, Attribute::mind}},
+ {Skill::transformationmagic, {Attribute::mystic, Attribute::constitution}},
+ {Skill::watermagic, {Attribute::mystic, Attribute::intuition}},
+ {Skill::windmagic, {Attribute::mystic, Attribute::mind}}
};
class Character
unsigned int skill (Skill skill) const;
unsigned int attribute (Attribute attribute) const;
unsigned int life () const;
- struct SkillTest {
- SkillTest (bool _passed, unsigned int _grades, unsigned int _sv, unsigned int _a1v, unsigned int _a2v, unsigned int _d1,
+ class SkillTest
+ {
+ public:
+ SkillTest (bool _passed, ResultKind _kind, int _grades, unsigned int _sv, unsigned int _a1v, unsigned int _a2v,
+ unsigned int _d1,
unsigned int _d2)
: passed (_passed)
+ , kind (_kind)
, grades (_grades)
, skillValue (_sv)
, attribute1Value (_a1v)
, d1 (_d1)
, d2 (_d2)
{}
-
+ friend ::std::ostream& operator<< (::std::ostream& os, const SkillTest& st);
const bool passed;
- const unsigned int grades;
+ const ResultKind kind;
+ const int grades;
const unsigned int skillValue;
const unsigned int attribute1Value;
const unsigned int attribute2Value;
const unsigned int d1;
const unsigned int d2;
};
- SkillTest testSkill (Skill skill, unsigned int against) const;
+
+ SkillTest testSkill (Skill skill, unsigned int against, TestKind kind) const;
private:
QSharedDataPointer<CharacterData> d;
};
+
}
#endif // CHARACTER_H