From 1e562bdd132c4166ca4de2bdb3f241adaa9a7149 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Wed, 9 Nov 2011 03:45:42 +0100 Subject: Added a way to specify the min and max attributes values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This can now be done in attributes.xml through the minimum and maximum attribute parameters. I also changed the AttributeInfo struct as requested by bjorn. Reviewed-by: Erik Schilling, Thorbjørn Lindeijer --- src/game-server/attribute.cpp | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'src/game-server/attribute.cpp') diff --git a/src/game-server/attribute.cpp b/src/game-server/attribute.cpp index 91113f49..82419e43 100644 --- a/src/game-server/attribute.cpp +++ b/src/game-server/attribute.cpp @@ -312,28 +312,34 @@ bool AttributeModifiersEffect::tick() return ret; } -Attribute::Attribute(const std::vector &type) - : mBase(0) +Attribute::Attribute(const AttributeManager::AttributeInfo &info): + mBase(0), + mMinValue(info.minimum), + mMaxValue(info.maximum) { - LOG_DEBUG("Construction of new attribute with '" << type.size() << "' layers."); - for (unsigned int i = 0; i < type.size(); ++i) + const std::vector &modifiers = info.modifiers; + LOG_DEBUG("Construction of new attribute with '" << modifiers.size() + << "' layers."); + for (unsigned int i = 0; i < modifiers.size(); ++i) { - LOG_DEBUG("Adding layer with stackable type " << type[i].stackableType - << " and effect type " << type[i].effectType << "."); - mMods.push_back(new AttributeModifiersEffect(type[i].stackableType, - type[i].effectType)); + LOG_DEBUG("Adding layer with stackable type " + << modifiers[i].stackableType + << " and effect type " << modifiers[i].effectType << "."); + mMods.push_back(new AttributeModifiersEffect(modifiers[i].stackableType, + modifiers[i].effectType)); LOG_DEBUG("Layer added."); } + mBase = checkBounds(mBase); } Attribute::~Attribute() { - for (std::vector::iterator it = mMods.begin(), - it_end = mMods.end(); it != it_end; ++it) - { +// for (std::vector::iterator it = mMods.begin(), +// it_end = mMods.end(); it != it_end; ++it) +// { // ? //delete *it; - } +// } } bool Attribute::tick() @@ -365,8 +371,10 @@ void Attribute::clearMods() void Attribute::setBase(double base) { + base = checkBounds(base); LOG_DEBUG("Setting base attribute from " << mBase << " to " << base << "."); double prev = mBase = base; + std::vector::iterator it = mMods.begin(); while (it != mMods.end()) { @@ -383,3 +391,13 @@ void AttributeModifiersEffect::clearMods(double baseValue) mCacheVal = baseValue; mMod = mEffectType == Additive ? 0 : 1; } + +double Attribute::checkBounds(double baseValue) +{ + LOG_DEBUG("Checking bounds for value: " << baseValue); + if (baseValue > mMaxValue) + baseValue = mMaxValue; + else if (baseValue < mMinValue) + baseValue = mMinValue; + return baseValue; +} -- cgit v1.2.3-70-g09d2