From e97c9f72a27e4dfcaa541e75395170fed8d6a181 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 4 Dec 2017 15:06:27 +0200 Subject: [PATCH] [General] Rework getting/clearing of skill modifiers as with attributes --- apps/openmw-mp/Script/Functions/Stats.cpp | 10 +++++----- apps/openmw-mp/Script/Functions/Stats.hpp | 8 ++++---- apps/openmw/mwmp/LocalPlayer.cpp | 9 ++++++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 4a18208e0..141425246 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -239,7 +239,7 @@ int StatsFunctions::GetSkillBase(unsigned short pid, unsigned short skill) noexc return player->npcStats.mSkills[skill].mBase; } -int StatsFunctions::GetSkillCurrent(unsigned short pid, unsigned short skill) noexcept +int StatsFunctions::GetSkillModifier(unsigned short pid, unsigned short skill) noexcept { Player *player; GET_PLAYER(pid, player, 0); @@ -247,7 +247,7 @@ int StatsFunctions::GetSkillCurrent(unsigned short pid, unsigned short skill) no if (skill >= Skill::Length) return 0; - return player->npcStats.mSkills[skill].mCurrent; + return player->npcStats.mSkills[skill].mMod; } double StatsFunctions::GetSkillProgress(unsigned short pid, unsigned short skill) noexcept @@ -442,7 +442,7 @@ void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short a player->creatureStats.mAttributes[attribute].mMod = 0; } -void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skill, int value) noexcept //TODO: need packet for one value +void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skill, int value) noexcept { Player *player; GET_PLAYER(pid, player,); @@ -453,7 +453,7 @@ void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skill, int player->npcStats.mSkills[skill].mBase = value; } -void StatsFunctions::SetSkillCurrent(unsigned short pid, unsigned short skill, int value) noexcept //TODO: need packet for one value +void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skill) noexcept { Player *player; GET_PLAYER(pid, player,); @@ -461,7 +461,7 @@ void StatsFunctions::SetSkillCurrent(unsigned short pid, unsigned short skill, i if (skill >= Skill::Length) return; - player->npcStats.mSkills[skill].mCurrent = value; + player->npcStats.mSkills[skill].mMod = 0; } void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skill, double value) noexcept diff --git a/apps/openmw-mp/Script/Functions/Stats.hpp b/apps/openmw-mp/Script/Functions/Stats.hpp index 9259b4df4..ff2421ef7 100644 --- a/apps/openmw-mp/Script/Functions/Stats.hpp +++ b/apps/openmw-mp/Script/Functions/Stats.hpp @@ -39,7 +39,7 @@ {"GetAttributeModifier", StatsFunctions::GetAttributeModifier},\ \ {"GetSkillBase", StatsFunctions::GetSkillBase},\ - {"GetSkillCurrent", StatsFunctions::GetSkillCurrent},\ + {"GetSkillModifier", StatsFunctions::GetSkillModifier},\ {"GetSkillProgress", StatsFunctions::GetSkillProgress},\ {"GetSkillIncrease", StatsFunctions::GetSkillIncrease},\ \ @@ -67,7 +67,7 @@ {"ClearAttributeModifier", StatsFunctions::ClearAttributeModifier},\ \ {"SetSkillBase", StatsFunctions::SetSkillBase},\ - {"SetSkillCurrent", StatsFunctions::SetSkillCurrent},\ + {"ClearSkillModifier", StatsFunctions::ClearSkillModifier},\ {"SetSkillProgress", StatsFunctions::SetSkillProgress},\ {"SetSkillIncrease", StatsFunctions::SetSkillIncrease},\ \ @@ -116,7 +116,7 @@ public: static int GetAttributeModifier(unsigned short pid, unsigned short attribute) noexcept; static int GetSkillBase(unsigned short pid, unsigned short skill) noexcept; - static int GetSkillCurrent(unsigned short pid, unsigned short skill) noexcept; + static int GetSkillModifier(unsigned short pid, unsigned short skill) noexcept; static double GetSkillProgress(unsigned short pid, unsigned short skill) noexcept; static int GetSkillIncrease(unsigned short pid, unsigned int pos) noexcept; @@ -144,7 +144,7 @@ public: static void ClearAttributeModifier(unsigned short pid, unsigned short attribute) noexcept; static void SetSkillBase(unsigned short pid, unsigned short skill, int value) noexcept; - static void SetSkillCurrent(unsigned short pid, unsigned short skill, int value) noexcept; + static void ClearSkillModifier(unsigned short pid, unsigned short skill) noexcept; static void SetSkillProgress(unsigned short pid, unsigned short skill, double value) noexcept; static void SetSkillIncrease(unsigned short pid, unsigned int pos, int value) noexcept; diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index b6eb85711..696bb9155 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -275,7 +275,8 @@ void LocalPlayer::updateSkills(bool forceUpdate) for (int i = 0; i < 27; ++i) { - if (ptrNpcStats.getSkill(i).getBase() != npcStats.mSkills[i].mBase) + if (ptrNpcStats.getSkill(i).getBase() != npcStats.mSkills[i].mBase || + ptrNpcStats.getSkill(i).getModifier() != npcStats.mSkills[i].mMod) { ptrNpcStats.getSkill(i).writeState(npcStats.mSkills[i]); skillsChanged = true; @@ -812,6 +813,12 @@ void LocalPlayer::setSkills() for (int i = 0; i < 27; ++i) { + // If the server wants to clear our skill's non-zero modifier, we need to remove + // the spell effect causing it, to avoid an infinite loop where the effect keeps resetting + // the modifier + if (npcStats.mSkills[i].mMod == 0 && ptrNpcStats->getSkill(i).getModifier() > 0) + ptrNpcStats->getActiveSpells().purgeEffectByArg(ESM::MagicEffect::FortifySkill, i); + skillValue.readState(npcStats.mSkills[i]); ptrNpcStats->setSkill(i, skillValue); }