A huge thank you to Evil Hero for pointing out a serious oversight in my coding. Here are the corrections that need to be made to the code so that the skill increase is only affecting each specific, individual monster, and not affecting the skill of the entire MonsterType class.
First, in monster.h, right above
int32_t getDefense() final;
, we need to create a new function to get the local skill (we'll use this later):
C++:
int32_t getSkill() const {
return skill;
}
We also need to declare
skill
and
tries
as new variables for the
Monster
class specifically. Underneath
uint64_t skillTries = 0;
add:
C++:
int32_t skill = 0;
int64_t tries = 0;
Now, in monster.cpp, in
Monster::Monster
, underneath
skillTries = 0;
, we need to initialize these variables. But, we aren't going to initialize them as 0, we're going to initialize them as whatever that particular monster's skill is:
C++:
skill = mType->info.skill;
tries = mType->info.tries;
Now, we're going to modify
skill
and
tries
that are tied to the specific monster, not the entire mType. So, we need to change anywhere in the function
void Monster::addSkillAdvance
that was incorrectly referencing
info.skills
or
info.tries
. Also, I added an important additional check to prevent an infinite 'while' loop:
C++:
void Monster::addSkillAdvance(int count) {
const float TRIES_INCREASE_FACTOR = (float)mType->info.multiplier / 1000;
const uint64_t MAX_TRIES_VALUE = std::numeric_limits<uint64_t>::max();
skillTries += count;
uint64_t levelUpThreshold = tries;
if (levelUpThreshold == 0) {
return;
}
while (skillTries >= levelUpThreshold) {
skillTries -= levelUpThreshold;
skill++;
levelUpThreshold *= TRIES_INCREASE_FACTOR;
if (levelUpThreshold > MAX_TRIES_VALUE) {
std::cout << "Overflow detected. Exiting function." << std::endl;
return;
}
tries = static_cast<uint64_t>(levelUpThreshold);
}
}
This is not all, however. There are other functions that use a monster's skill value, and those functions are referencing
mType->info.skill
either directly or indirectly. This means that while a specific monster's skills might be leveling up, all of the important formulas (damage, defense) aren't even using the new level!
So, a little further down in monster.cpp, in
int32_t Monster::getDefense()
, we need to change this line
int32_t defenseSkill = mType->info.skill;
to this:
C++:
int32_t defenseSkill = skill;
Finally, we need to do something similar in combat.cpp. Find the function
void Combat::getAttackValue
and at the very bottom, the last
else if
statement, change
skillValue = monster->mType->info.skill;
to:
C++:
skillValue = monster->getSkill();
Here is a snapshot of it working live (I boosted the skill gain rate by 10x to make it quicker to see the difference):

Then, after they had all trained up a bit, I hit each one of the spiders individually with a melee attack, and they each have their own defense value based on how long they had been training:

Thanks again to Evil Hero for pointing out my mistake. Now, it should now be working as intended!