diff options
author | Philipp Sehmisch <crush@themanaworld.org> | 2009-10-26 21:27:26 +0100 |
---|---|---|
committer | Philipp Sehmisch <crush@themanaworld.org> | 2009-10-26 21:28:18 +0100 |
commit | b7481331c65a08d54d5e2ae286923627195076ce (patch) | |
tree | 62e9a7391f074913652d8d2dedc1cdc28cb53124 | |
parent | ecefeb60244e6ad9c5d043f8bdf086ac89889b9e (diff) | |
download | manaserv-b7481331c65a08d54d5e2ae286923627195076ce.tar.gz manaserv-b7481331c65a08d54d5e2ae286923627195076ce.tar.bz2 manaserv-b7481331c65a08d54d5e2ae286923627195076ce.tar.xz manaserv-b7481331c65a08d54d5e2ae286923627195076ce.zip |
Added optional optimal level mechanic which reduces exp gain of certain sources after a certain skill level.
-rw-r--r-- | src/game-server/character.cpp | 10 | ||||
-rw-r--r-- | src/game-server/character.hpp | 5 | ||||
-rw-r--r-- | src/game-server/monster.cpp | 2 | ||||
-rw-r--r-- | src/game-server/monster.hpp | 16 | ||||
-rw-r--r-- | src/game-server/monstermanager.cpp | 1 | ||||
-rw-r--r-- | src/scripting/lua.cpp | 7 |
6 files changed, 32 insertions, 9 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 94bd7465..f351edb3 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -48,6 +48,7 @@ const float Character::EXPCURVE_EXPONENT = 3.0f; const float Character::EXPCURVE_FACTOR = 10.0f; const float Character::LEVEL_SKILL_PRECEDENCE_FACTOR = 0.75f; +const float Character::EXP_LEVEL_FLEXIBILITY = 1.0f; Character::Character(MessageIn &msg): Being(OBJECT_CHARACTER), @@ -460,10 +461,17 @@ int Character::levelForExp(int exp) return int(pow(float(exp) / EXPCURVE_FACTOR, 1.0f / EXPCURVE_EXPONENT)); } -void Character::receiveExperience(int skill, int experience) +void Character::receiveExperience(int skill, int experience, int optimalLevel) { if (skill >= CHAR_ATTR_END) { + // reduce experience when skill is over optimal level + int levelOverOptimum = getAttribute(skill) - optimalLevel; + if (optimalLevel && levelOverOptimum > 0) + { + experience *= EXP_LEVEL_FLEXIBILITY / (levelOverOptimum + EXP_LEVEL_FLEXIBILITY); + } + // add exp int oldExp = mExperience[skill]; long int newExp = mExperience[skill] + experience; diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp index 15d81323..78e96616 100644 --- a/src/game-server/character.hpp +++ b/src/game-server/character.hpp @@ -267,7 +267,7 @@ class Character : public Being * Gives a skill a specific amount of exp and checks if a levelup * occured. */ - void receiveExperience(int skill, int experience); + void receiveExperience(int skill, int experience, int optimalLevel); int getSkillSize() const { return mExperience.size(); } @@ -300,7 +300,7 @@ class Character : public Being * Sets total accumulated exp for skill */ void setExperience(int skill, int value) - { mExperience[skill] = 0; receiveExperience(skill, value); } + { mExperience[skill] = 0; receiveExperience(skill, value, 0); } /** * Shortcut to get being's health @@ -355,6 +355,7 @@ class Character : public Being static const float EXPCURVE_EXPONENT; static const float EXPCURVE_FACTOR; static const float LEVEL_SKILL_PRECEDENCE_FACTOR; // I am taking suggestions for a better name + static const float EXP_LEVEL_FLEXIBILITY; static const int CHARPOINTS_PER_LEVELUP = 5; static const int CORRECTIONPOINTS_PER_LEVELUP = 2; static const int CORRECTIONPOINTS_MAX = 10; diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 08ddb2aa..c6b6079e 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -463,7 +463,7 @@ void Monster::died() int expPerSkill = int(expPerChar / skillSet->size()); for (iSkill = skillSet->begin(); iSkill != skillSet->end(); iSkill++) { - character->receiveExperience(*iSkill, expPerSkill); + character->receiveExperience(*iSkill, expPerSkill, mSpecy->getOptimalLevel()); } } } diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp index dd064073..1d7e958b 100644 --- a/src/game-server/monster.hpp +++ b/src/game-server/monster.hpp @@ -79,6 +79,7 @@ class MonsterClass mStrollRange(0), mMutation(0), mAttackDistance(0), + mOptimalLevel(0), mScript("") {} @@ -125,6 +126,12 @@ class MonsterClass /** Returns experience reward for killing the monster. */ int getExp() const { return mExp; } + /** Gets maximum skill level after which exp reward is reduced */ + void setOptimalLevel(int level) { mOptimalLevel = level; } + + /** Sets maximum skill level after which exp reward is reduced. */ + int getOptimalLevel() const { return mOptimalLevel; } + /** Sets if the monster attacks without being attacked first. */ void setAggressive(bool aggressive) { mAggressive = aggressive; } @@ -186,10 +193,11 @@ class MonsterClass int mExp; bool mAggressive; - unsigned mTrackRange; - unsigned mStrollRange; - unsigned mMutation; - unsigned mAttackDistance; + int mTrackRange; + int mStrollRange; + int mMutation; + int mAttackDistance; + int mOptimalLevel; MonsterAttacks mAttacks; std::string mScript; }; diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index 144de6fd..cf5afb30 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -203,6 +203,7 @@ void MonsterManager::reload() { xmlChar *exp = subnode->xmlChildrenNode->content; monster->setExp(atoi((const char*)exp)); + monster->setOptimalLevel(XML::getProperty(subnode, "level", 0)); } else if (xmlStrEqual(subnode->name, BAD_CAST "behavior")) { diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index fc505eb4..fe777a0c 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1192,7 +1192,12 @@ static int chr_give_exp(lua_State *s) int exp = lua_tointeger(s, 3); - c->receiveExperience(skill, exp); + int optimalLevel = 0; + if (lua_isnumber(s, 4)) + { + optimalLevel = lua_tointeger(s, 4); + } + c->receiveExperience(skill, exp, optimalLevel); return 0; } |