[Server] Fix skill-related script functions

Add getSkillIncrease() and setSkillIncrease() script functions to get and set the attribute bonuses received at the next level up as a result of skill increases.

Previously, getSkill() and setSkill() attempted to return and set the attribute bonuses, respectively. However, they mistakenly used a skill ID as a parameter for the attribute bonuses, when in fact npcStats.mSkillIncrease is an integer array of size 8 where the key stands for an attribute's ID. As a result, setSkill() had the unexpected side effect of messing up a player's major and minor skills because of the invalid values it was setting for npcStats.mSkillIncreases.
new-script-api
David Cernat 7 years ago
parent 57a0415ba3
commit 80be664139

@ -67,6 +67,9 @@ void Player::Init(LuaState &lua)
"getSkill", &Player::getSkill,
"setSkill", &Player::setSkill,
"getSkillIncrease", &Player::getSkillIncrease,
"setSkillIncrease", &Player::setSkillIncrease,
"getClass", &Player::getCharClass,
"getSettings", &Player::getSettings,
"getBooks", &Player::getBooks,
@ -483,16 +486,16 @@ void Player::setAttribute(unsigned short id, int base, int current)
attributesChanged = true;
}
std::tuple<int, int, float, int> Player::getSkill(unsigned short id) const
std::tuple<int, int, float> Player::getSkill(unsigned short id) const
{
if (id >= ESM::Skill::Length)
return make_tuple(0, 0, 0.0f, 0);
return make_tuple(0, 0, 0.0f);
const auto &skill = npcStats.mSkills[id];
return make_tuple(skill.mBase, skill.mCurrent, skill.mProgress, npcStats.mSkillIncrease[id]);
return make_tuple(skill.mBase, skill.mCurrent, skill.mProgress);
}
void Player::setSkill(unsigned short id, int base, int current, float progress, int increase)
void Player::setSkill(unsigned short id, int base, int current, float progress)
{
if (id >= ESM::Skill::Length)
return;
@ -501,7 +504,21 @@ void Player::setSkill(unsigned short id, int base, int current, float progress,
skill.mBase = base;
skill.mCurrent = current;
skill.mProgress = progress;
npcStats.mSkillIncrease[id] = increase;
skillsChanged = true;
}
int Player::getSkillIncrease(unsigned short attributeId) const
{
return npcStats.mSkillIncrease[attributeId];
}
void Player::setSkillIncrease(unsigned short attributeId, int increase)
{
if (attributeId >= ESM::Attribute::Length)
return;
npcStats.mSkillIncrease[attributeId] = increase;
skillsChanged = true;
}

@ -158,8 +158,11 @@ public:
*
* @return base, current, progress, increase
*/
std::tuple<int, int, float, int> getSkill(unsigned short id) const;
void setSkill(unsigned short id, int base, int current, float progress, int increase);
std::tuple<int, int, float> getSkill(unsigned short id) const;
void setSkill(unsigned short id, int base, int current, float progress);
int getSkillIncrease(unsigned short attributeId) const;
void setSkillIncrease(unsigned short attributeId, int increase);
CellState getCellState(int i);
size_t cellStateSize() const;

Loading…
Cancel
Save