summaryrefslogtreecommitdiff
path: root/src/game-server/monster.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-30 22:29:56 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-01-30 22:29:56 +0100
commita7c5cbc6f9e66275b697875e8a440910b0f5e982 (patch)
tree23ca4d3f8441730b6e377c84e2c85ac344d3a1fb /src/game-server/monster.cpp
parent074351e17125998d9de19d9528b08ab0b2029870 (diff)
downloadmanaserv-a7c5cbc6f9e66275b697875e8a440910b0f5e982.tar.gz
manaserv-a7c5cbc6f9e66275b697875e8a440910b0f5e982.tar.bz2
manaserv-a7c5cbc6f9e66275b697875e8a440910b0f5e982.tar.xz
manaserv-a7c5cbc6f9e66275b697875e8a440910b0f5e982.zip
Made the monsters' attributes compute fine again.
As a consequence, the monsters can spawn again. Reviewed-by: Freeyorp.
Diffstat (limited to 'src/game-server/monster.cpp')
-rw-r--r--src/game-server/monster.cpp47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 78268db1..07916d0e 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -97,17 +97,17 @@ Monster::Monster(MonsterClass *specy):
double attr = 0.0f;
if (specy->hasAttribute(it2->first))
+ {
attr = specy->getAttribute(it2->first);
- setAttribute(it2->first,
+ setAttribute(it2->first,
mutation ?
attr * (100 + (rand()%(mutation << 1)) - mutation) / 100.0 :
attr);
+ recalculateBaseAttribute(it2->first);
+ }
}
- // Set the speed in tiles per second.
- setAttribute(ATTR_MOVE_SPEED_RAW,
- utils::tpsToRawSpeed(getAttribute(ATTR_MOVE_SPEED_TPS)));
setSize(specy->getSize());
// Set positions relative to target from which the monster can attack
@@ -513,3 +513,42 @@ void Monster::died()
}
}
+bool Monster::recalculateBaseAttribute(unsigned int attr)
+{
+ LOG_DEBUG("Received update attribute recalculation request at Monster for "
+ << attr << ".");
+ if (!mAttributes.count(attr)) return false;
+ double newBase = getAttribute(attr);
+
+ switch (attr)
+ {
+ // Those a set only at load time.
+ case ATTR_MAX_HP:
+ case MOB_ATTR_PHY_ATK_MIN:
+ case MOB_ATTR_PHY_ATK_DELTA:
+ case MOB_ATTR_MAG_ATK:
+ case ATTR_DODGE:
+ case ATTR_MAGIC_DODGE:
+ case ATTR_ACCURACY:
+ case ATTR_DEFENSE:
+ case ATTR_MAGIC_DEFENSE:
+ case ATTR_HP_REGEN:
+ case ATTR_MOVE_SPEED_TPS:
+ case ATTR_INV_CAPACITY:
+ // nothing to do.
+ break;
+
+ // Only HP and Speed Raw updated for monsters
+ default:
+ Being::recalculateBaseAttribute(attr);
+ break;
+ }
+ if (newBase != getAttribute(attr))
+ {
+ setAttribute(attr, newBase);
+ updateDerivedAttributes(attr);
+ return true;
+ }
+ LOG_DEBUG("No changes to sync for attribute '" << attr << "'.");
+ return false;
+}