summaryrefslogtreecommitdiff
path: root/src/game-server/attribute.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-11-09 03:45:42 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2012-02-02 15:35:17 +0100
commit1e562bdd132c4166ca4de2bdb3f241adaa9a7149 (patch)
tree84bca9f39cfd3c05d3a315c8e9cd854b18cb4682 /src/game-server/attribute.cpp
parent4cd1957231605e976c5cf001eddea80d5e49272f (diff)
downloadmanaserv-1e562bdd132c4166ca4de2bdb3f241adaa9a7149.tar.gz
manaserv-1e562bdd132c4166ca4de2bdb3f241adaa9a7149.tar.bz2
manaserv-1e562bdd132c4166ca4de2bdb3f241adaa9a7149.tar.xz
manaserv-1e562bdd132c4166ca4de2bdb3f241adaa9a7149.zip
Added a way to specify the min and max attributes values.
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
Diffstat (limited to 'src/game-server/attribute.cpp')
-rw-r--r--src/game-server/attribute.cpp42
1 files changed, 30 insertions, 12 deletions
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<struct AttributeInfoType> &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<AttributeModifier> &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<AttributeModifiersEffect *>::iterator it = mMods.begin(),
- it_end = mMods.end(); it != it_end; ++it)
- {
+// for (std::vector<AttributeModifiersEffect *>::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<AttributeModifiersEffect *>::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;
+}