2 //! @author Patrick Nicoll 27218729
3 //! @brief Implementation of the class representing an instance of a character
10 //! Default no param constructor
11 Character::Character() {
16 //! Constructor that takes a level to initialize the stats accordingly
17 //! @param levelVal Level of character
18 Character::Character(int levelVal
) {
22 //Print statements used for testing
23 std::cout
<< "str: " << str
<< std::endl
;
24 std::cout
<< "dex: " << dex
<< std::endl
;
25 std::cout
<< "con: " << con
<< std::endl
;
27 for (int i
= 1; i
< levelVal
; i
++) {
34 Character::~Character()
38 //! Validates wheter the character has valid starting stats
39 //! @return Whether valid or not, true it is valid, false it is not
40 bool Character::validateNewCharacter()
44 if (str
< 3 || str
> 18)
46 if (dex
< 3 || dex
> 18)
48 if (con
< 3 || con
> 18)
50 if (intel
< 3 || intel
> 18)
52 if (wis
< 3 || wis
> 18)
54 if (cha
< 3 || cha
> 18)
60 //! Method to call all the appropriate methods used during character creation.
61 void Character::create() {
62 generateRandomStats();
65 calculateBaseAttackBonus();
66 calculateDamageBonus();
69 //! Generate the attribute values for the six major stats.
70 //! Values are between 3-18
71 void Character::generateRandomStats()
73 // Will be used, but for testing purposes will hardcoded numbers will be set
76 // create source of randomness, and initialize it with non-deterministic seed
78 std::seed_seq seed
{ r(),r(),r(),r(),r(),r() };
79 std::mt19937 eng
{ seed
};
81 // a distribution that takes randomness and produces values in the range of 3 to 18
82 std::uniform_int_distribution
<> dist(3, 18);
84 for (int i
= 0; i
< 6; i
++) {
97 str_mod
= getModifier(stats
[0]);
98 dex_mod
= getModifier(stats
[1]);
99 con_mod
= getModifier(stats
[2]);
100 intel_mod
= getModifier(stats
[3]);
101 wis_mod
= getModifier(stats
[4]);
102 cha_mod
= getModifier(stats
[5]);
105 //! Calculates the hitpoints of the character.
106 //! Hitpoints are calculated by adding the constitution modifier to the character level
107 void Character::calculateHp()
109 hp
= abs(con_mod
) + level
;
110 maxHp
= abs(con_mod
) + level
;
113 //! Calculates the armor class of the character.
114 //! Armor class is calculated by adding the dexterity modifier, armor bonus and shield bonus togther and then adding 10
115 void Character::calculateAc()
120 //! Calculates the base attack bonus of the character.
121 //! Base attack bonus is calculated by adding the strength modifier to the character level
122 void Character::calculateBaseAttackBonus()
124 attackBonus
= str_mod
+ level
;
127 //! Calculates the damage bonus of the character.
128 //! Damage bonus is calculated based on the strength modifier of the character
129 void Character::calculateDamageBonus()
131 damageBonus
= str_mod
;
134 //! Will increase attributes upon levelling up
135 void Character::levelUp() {
141 //Call relevant methods to update based on new stat increase
142 str_mod
= (getModifier(str
));
143 dex_mod
= (getModifier(dex
));
144 con_mod
= (getModifier(con
));
147 calculateBaseAttackBonus();
148 calculateDamageBonus();
151 //! Determines modifier based on stat entered by evaluating which range it falls in
152 //! @param stat Stat to determine range of
153 //! @return Value of the range the stat fell under
154 int Character::getModifier(int stat
)
184 //! Reduces character's hitpoints based on damage inputed
185 //! @param damage Damage to be taken away from hitpoints
186 void Character::hit(int damage
) {