From 80be664139d023ac1af59264538ace0372e6eeaa Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 18 Nov 2017 10:02:52 +0200 Subject: [PATCH] [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. --- apps/openmw-mp/Player.cpp | 27 ++++++++++++++++++++++----- apps/openmw-mp/Player.hpp | 7 +++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/apps/openmw-mp/Player.cpp b/apps/openmw-mp/Player.cpp index 319cc7214..111747618 100644 --- a/apps/openmw-mp/Player.cpp +++ b/apps/openmw-mp/Player.cpp @@ -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 Player::getSkill(unsigned short id) const +std::tuple 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; } diff --git a/apps/openmw-mp/Player.hpp b/apps/openmw-mp/Player.hpp index 91c33f098..37bf427df 100644 --- a/apps/openmw-mp/Player.hpp +++ b/apps/openmw-mp/Player.hpp @@ -158,8 +158,11 @@ public: * * @return base, current, progress, increase */ - std::tuple getSkill(unsigned short id) const; - void setSkill(unsigned short id, int base, int current, float progress, int increase); + std::tuple 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;