From 57aeec59d5a2c51302404624f4f490896ca0f0d4 Mon Sep 17 00:00:00 2001 From: Allofich Date: Wed, 22 Mar 2017 14:27:30 +0900 Subject: [PATCH] Change bounds behavior of stat script commands Fixes (#3776) --- apps/openmw/mwmechanics/stat.cpp | 2 +- apps/openmw/mwscript/statsextensions.cpp | 39 +++++++++++++++++------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwmechanics/stat.cpp b/apps/openmw/mwmechanics/stat.cpp index cf1f228c0..41c5bac5a 100644 --- a/apps/openmw/mwmechanics/stat.cpp +++ b/apps/openmw/mwmechanics/stat.cpp @@ -189,7 +189,7 @@ namespace MWMechanics void AttributeValue::setBase(int base) { - mBase = std::max(0, base); + mBase = base; } void AttributeValue::setModifier(int mod) diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 19f2a035e..6b1953917 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -123,7 +123,7 @@ namespace MWScript runtime.pop(); MWMechanics::AttributeValue attribute = ptr.getClass().getCreatureStats(ptr).getAttribute(mIndex); - attribute.setBase (value - (attribute.getModified() - attribute.getBase())); + attribute.setBase (value); ptr.getClass().getCreatureStats(ptr).setAttribute(mIndex, attribute); } }; @@ -148,7 +148,18 @@ namespace MWScript .getCreatureStats(ptr) .getAttribute(mIndex); - attribute.setBase (std::min(100, attribute.getBase() + value)); + if (value == 0) + return; + + if (((attribute.getBase() <= 0) && (value < 0)) + || ((attribute.getBase() >= 100) && (value > 0))) + return; + + if (value < 0) + attribute.setBase(std::max(0, attribute.getBase() + value)); + else + attribute.setBase(std::min(100, attribute.getBase() + value)); + ptr.getClass().getCreatureStats(ptr).setAttribute(mIndex, attribute); } }; @@ -350,12 +361,7 @@ namespace MWScript MWMechanics::NpcStats& stats = ptr.getClass().getNpcStats (ptr); - int newLevel = value - (stats.getSkill(mIndex).getModified() - stats.getSkill(mIndex).getBase()); - - if (newLevel<0) - newLevel = 0; - - stats.getSkill (mIndex).setBase (newLevel); + stats.getSkill (mIndex).setBase (value); } }; @@ -375,10 +381,21 @@ namespace MWScript Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - MWMechanics::NpcStats& stats = ptr.getClass().getNpcStats(ptr); + MWMechanics::SkillValue &skill = ptr.getClass() + .getNpcStats(ptr) + .getSkill(mIndex); + + if (value == 0) + return; + + if (((skill.getBase() <= 0) && (value < 0)) + || ((skill.getBase() >= 100) && (value > 0))) + return; - stats.getSkill(mIndex). - setBase (std::min(100, stats.getSkill(mIndex).getBase() + value)); + if (value < 0) + skill.setBase(std::max(0, skill.getBase() + value)); + else + skill.setBase(std::min(100, skill.getBase() + value)); } };