From: John Janus Date: Tue, 13 Aug 2019 13:40:35 +0000 (+0200) Subject: use private implementation for character and add some more stuff X-Git-Url: https://git.johnzone.org/?a=commitdiff_plain;h=0b7c231cdbb35105fdb7f1a25b1022c16bc61765;p=splittermond-assistant.git use private implementation for character and add some more stuff --- diff --git a/src/character.cpp b/src/character.cpp index 04907ee..3e63414 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -1,7 +1,67 @@ #include "character.h" -namespace sm::data { - Character::Character(const QFile& file) - { +#include +#include +#include + +namespace sm::data +{ + +class Character::CharacterData : public QSharedData +{ +public: + CharacterData() {} + CharacterData (const CharacterData& other) : QSharedData (other) {} + + ~CharacterData() {} + unsigned int life = 0; + const std::vector damage; + const std::unordered_map skills; + const std::unordered_map attributes; +}; + +Character::Character () : d{new Character::CharacterData} +{ + +} + +Character::~Character() +{ + +} + +unsigned int Character::skill (Skill _skill) const +{ + return d->skills.at (_skill); +} + +unsigned int Character::attribute (Attribute _attribute) const +{ + return d->attributes.at (_attribute); +} + +unsigned int Character::life() const +{ + return d->life; +} + +Character::SkillTest Character::testSkill (Skill _skill, unsigned int against) const +{ + std::uniform_int_distribution d10 (1, 10); + std::random_device gen; + unsigned int s = d->skills.at (_skill); + Attribute attr1 = skillAttributes.at (_skill).first; + Attribute attr2 = skillAttributes.at (_skill).second; + unsigned int a1 = d->attributes.at (attr1); + unsigned int a2 = d->attributes.at (attr2); + + 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); + + return {passed, grade, s, a1, a2, d1, d2}; +} - } } diff --git a/src/character.h b/src/character.h index 18df734..2b013a6 100644 --- a/src/character.h +++ b/src/character.h @@ -2,162 +2,160 @@ #define CHARACTER_H #include -#include -#include -#include -#include "definitions.h" +#include namespace sm::data { - enum Skill { - acrobatics, - alchemy, - leadership, - arcanelore, - athletics, - performance, - diplomacy, - clscraft, - empathy, - determination, - dexterity, - history, - craftmanship, - heal, - stealth, - hunting, - countrylore, - nature, - eloquence, - locksntraps, - swim, - seafaring, - streetlore, - animals, - survival, - perception, - endurance, - antimagic, - controlmagic, - motionmagic, - insightmagic, - stonemagic, - firemagic, - healmagic, - illusionmagic, - combatmagic, - lightmagic, - naturemagic, - shadowmagic, - fatemagic, - protectionmagic, - enhancemagic, - deathmagic, - transformationmagic, - watermagic, - windmagic - }; +enum Skill { + acrobatics, + alchemy, + leadership, + arcanelore, + athletics, + performance, + diplomacy, + clscraft, + empathy, + determination, + dexterity, + history, + craftmanship, + heal, + stealth, + hunting, + countrylore, + nature, + eloquence, + locksntraps, + swim, + seafaring, + streetlore, + animals, + survival, + perception, + endurance, + antimagic, + controlmagic, + motionmagic, + insightmagic, + stonemagic, + firemagic, + healmagic, + illusionmagic, + combatmagic, + lightmagic, + naturemagic, + shadowmagic, + fatemagic, + protectionmagic, + enhancemagic, + deathmagic, + transformationmagic, + watermagic, + windmagic +}; - enum Attribute { - charisma, - agility, - intuition, - constitution, - mystic, - strength, - mind, - willpower - }; +enum Attribute { + charisma, + agility, + intuition, + constitution, + mystic, + strength, + mind, + willpower +}; - 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}} - }; +enum Damage { + canalised, + exhausted, + used +}; - class Character - { - public: - explicit Character(const QFile& file); - virtual ~Character() {} - unsigned int skill(Skill _skill) const {return skills.at(_skill);} - unsigned int attribute(Attribute _attribute) const {return attributes.at(_attribute);} +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}} +}; - private: - const std::unordered_map skills; - const std::unordered_map attributes; +class Character +{ +public: + explicit Character (); + virtual ~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, + unsigned int _d2) + : passed (_passed) + , grades (_grades) + , skillValue (_sv) + , attribute1Value (_a1v) + , attribute2Value (_a2v) + , d1 (_d1) + , d2 (_d2) + {} + const bool passed; + const unsigned 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; - class SkillTest - { - public: - SkillTest(const Character& hero, const Skill skill, const unsigned int against) - { - std::uniform_int_distribution d10(1,10); - std::random_device generator; - this->d1 = d10(generator); - this->d2 = d10(generator); - this->accumulated = d1 + d2 - + hero.skill(skill) - + hero.attribute(skillAttributes.at(skill).first) - + hero.attribute(skillAttributes.at(skill).second); - this->delta = accumulated - against; - passed = delta >= 0; - grade = std::abs(delta) / 3; - } +private: + class CharacterData; + QSharedDataPointer d; - private: - unsigned int d1; - unsigned int d2; - unsigned int accumulated; - int delta; - bool passed; - unsigned int grade; - }; - }; +}; } #endif // CHARACTER_H