From a6fe295025af210f5dbdcf5b69cc7d615185e030 Mon Sep 17 00:00:00 2001 From: John Janus Date: Wed, 21 Aug 2019 16:29:15 +0200 Subject: [PATCH] fix skill test to include testkind and resultkind and fix calculations --- splittermond-assistant-tests/tst_test.cpp | 5 + splittermond-assistant/src/character.cpp | 53 ++++++++-- splittermond-assistant/src/character.h | 123 ++++++++++++---------- 3 files changed, 120 insertions(+), 61 deletions(-) diff --git a/splittermond-assistant-tests/tst_test.cpp b/splittermond-assistant-tests/tst_test.cpp index 2ea0de2..d13763f 100644 --- a/splittermond-assistant-tests/tst_test.cpp +++ b/splittermond-assistant-tests/tst_test.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "character.h" // add necessary includes here @@ -57,6 +58,10 @@ void Test::init_Character() 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 11}), std::invalid_argument); + for (int i = 0; i < 100; i++) { + auto res = c.testSkill (sm::data::Skill::alchemy, 40, sm::data::TestKind::normal); + std::cout << res; + } } QTEST_APPLESS_MAIN (Test) diff --git a/splittermond-assistant/src/character.cpp b/splittermond-assistant/src/character.cpp index a3488d1..81cb1e2 100644 --- a/splittermond-assistant/src/character.cpp +++ b/splittermond-assistant/src/character.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace sm::data { @@ -75,7 +76,7 @@ unsigned int Character::life() const 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 d10 (1, 10); std::random_device gen; @@ -84,15 +85,55 @@ Character::SkillTest Character::testSkill (Skill _skill, unsigned int against) c 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 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 (st.kind) + << " (" << st.d1 << ',' << st.d2 << ") " + << " Grades: " << st.grades + << '\n'; + return os; } } diff --git a/splittermond-assistant/src/character.h b/splittermond-assistant/src/character.h index f00dae1..0387c0b 100644 --- a/splittermond-assistant/src/character.h +++ b/splittermond-assistant/src/character.h @@ -8,7 +8,7 @@ namespace sm::data { -enum Skill : unsigned int { +enum class Skill : unsigned int { acrobatics, alchemy, leadership, @@ -57,7 +57,7 @@ enum Skill : unsigned int { windmagic }; -enum Attribute : unsigned int { +enum class Attribute : unsigned int { charisma, agility, intuition, @@ -68,65 +68,71 @@ enum Attribute : unsigned int { 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> 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 @@ -144,10 +150,14 @@ public: 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) @@ -155,16 +165,18 @@ public: , 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: @@ -172,5 +184,6 @@ private: QSharedDataPointer d; }; + } #endif // CHARACTER_H -- 2.47.0