From b88bfbdcefbe457b28af34d5f750a148d7155807 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Fri, 16 Jan 2009 00:59:12 +0300 Subject: [PATCH] [7092] Work vs XP per level data Add new table "player_xp_for_level" for this Fill table data 1-79 level Remove old code Signed-off-by: DiSlord --- sql/mangos.sql | 101 ++++++++++++++++++++- sql/updates/7092_01_mangos_player_xp_for_level.sql | 93 +++++++++++++++++++ sql/updates/Makefile.am | 2 + src/game/Formulas.h | 60 ------------ src/game/ObjectMgr.cpp | 68 ++++++++++++++ src/game/ObjectMgr.h | 4 + src/game/Pet.cpp | 6 +- src/game/Player.cpp | 4 +- src/game/World.cpp | 1 - src/game/World.h | 1 - src/mangosd/mangosd.conf.dist.in | 5 - src/shared/revision_nr.h | 2 +- 12 files changed, 273 insertions(+), 74 deletions(-) create mode 100644 sql/updates/7092_01_mangos_player_xp_for_level.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index 4d75aad4d..d6f890806 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -22,7 +22,7 @@ DROP TABLE IF EXISTS `db_version`; CREATE TABLE `db_version` ( `version` varchar(120) default NULL, - `required_7078_01_mangos_spell_proc_event` bit(1) default NULL + `required_7092_01_mangos_player_xp_for_level` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- @@ -9291,6 +9291,105 @@ INSERT INTO `player_levelstats` VALUES /*!40000 ALTER TABLE `player_levelstats` ENABLE KEYS */; UNLOCK TABLES; +-- ---------------------------- +-- Table structure for player_xp_for_level +-- ---------------------------- +DROP TABLE IF EXISTS `player_xp_for_level`; +CREATE TABLE `player_xp_for_level` ( + `lvl` int(3) unsigned NOT NULL, + `xp_for_next_level` int(10) unsigned NOT NULL, + PRIMARY KEY (`lvl`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `player_xp_for_level` +-- + +LOCK TABLES `player_xp_for_level` WRITE; +/*!40000 ALTER TABLE `player_xp_for_level` DISABLE KEYS */; +INSERT INTO `player_xp_for_level` VALUES +('1', '400'), +('2', '900'), +('3', '1400'), +('4', '2100'), +('5', '2800'), +('6', '3600'), +('7', '4500'), +('8', '5400'), +('9', '6500'), +('10', '7600'), +('11', '8700'), +('12', '9800'), +('13', '11000'), +('14', '12300'), +('15', '13600'), +('16', '15000'), +('17', '16400'), +('18', '17800'), +('19', '19300'), +('20', '20800'), +('21', '22400'), +('22', '24000'), +('23', '25500'), +('24', '27200'), +('25', '28900'), +('26', '30500'), +('27', '32200'), +('28', '33900'), +('29', '36300'), +('30', '38800'), +('31', '41600'), +('32', '44600'), +('33', '48000'), +('34', '51400'), +('35', '55000'), +('36', '58700'), +('37', '62400'), +('38', '66200'), +('39', '70200'), +('40', '74300'), +('41', '78500'), +('42', '82800'), +('43', '87100'), +('44', '91600'), +('45', '96300'), +('46', '101000'), +('47', '105800'), +('48', '110700'), +('49', '115700'), +('50', '120900'), +('51', '126100'), +('52', '131500'), +('53', '137000'), +('54', '142500'), +('55', '148200'), +('56', '154000'), +('57', '159900'), +('58', '165800'), +('59', '172000'), +('60', '290000'), +('61', '317000'), +('62', '349000'), +('63', '386000'), +('64', '428000'), +('65', '475000'), +('66', '527000'), +('67', '585000'), +('68', '648000'), +('69', '717000'), +('70', '1523800'), +('71', '1539600'), +('72', '1555700'), +('73', '1571800'), +('74', '1587900'), +('75', '1604200'), +('76', '1620700'), +('77', '1637400'), +('78', '1653900'), +('79', '1670800'); +/*!40000 ALTER TABLE `player_xp_for_level` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `playercreateinfo` -- diff --git a/sql/updates/7092_01_mangos_player_xp_for_level.sql b/sql/updates/7092_01_mangos_player_xp_for_level.sql new file mode 100644 index 000000000..aa4fabd28 --- /dev/null +++ b/sql/updates/7092_01_mangos_player_xp_for_level.sql @@ -0,0 +1,93 @@ +ALTER TABLE db_version CHANGE COLUMN required_7078_01_mangos_spell_proc_event required_7092_01_mangos_player_xp_for_level bit; + +DROP TABLE IF EXISTS `player_xp_for_level`; +CREATE TABLE `player_xp_for_level` ( + `lvl` int(3) unsigned NOT NULL, + `xp_for_next_level` int(10) unsigned NOT NULL, + PRIMARY KEY (`lvl`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `player_xp_for_level` +-- + +INSERT INTO `player_xp_for_level` VALUES +('1', '400'), +('2', '900'), +('3', '1400'), +('4', '2100'), +('5', '2800'), +('6', '3600'), +('7', '4500'), +('8', '5400'), +('9', '6500'), +('10', '7600'), +('11', '8700'), +('12', '9800'), +('13', '11000'), +('14', '12300'), +('15', '13600'), +('16', '15000'), +('17', '16400'), +('18', '17800'), +('19', '19300'), +('20', '20800'), +('21', '22400'), +('22', '24000'), +('23', '25500'), +('24', '27200'), +('25', '28900'), +('26', '30500'), +('27', '32200'), +('28', '33900'), +('29', '36300'), +('30', '38800'), +('31', '41600'), +('32', '44600'), +('33', '48000'), +('34', '51400'), +('35', '55000'), +('36', '58700'), +('37', '62400'), +('38', '66200'), +('39', '70200'), +('40', '74300'), +('41', '78500'), +('42', '82800'), +('43', '87100'), +('44', '91600'), +('45', '96300'), +('46', '101000'), +('47', '105800'), +('48', '110700'), +('49', '115700'), +('50', '120900'), +('51', '126100'), +('52', '131500'), +('53', '137000'), +('54', '142500'), +('55', '148200'), +('56', '154000'), +('57', '159900'), +('58', '165800'), +('59', '172000'), +('60', '290000'), +('61', '317000'), +('62', '349000'), +('63', '386000'), +('64', '428000'), +('65', '475000'), +('66', '527000'), +('67', '585000'), +('68', '648000'), +('69', '717000'), +('70', '1523800'), +('71', '1539600'), +('72', '1555700'), +('73', '1571800'), +('74', '1587900'), +('75', '1604200'), +('76', '1620700'), +('77', '1637400'), +('78', '1653900'), +('79', '1670800'); \ No newline at end of file diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index 84f20c9a6..25c460c9a 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -137,6 +137,7 @@ pkgdata_DATA = \ 7075_02_mangos_spell_learn_spell.sql \ 7077_01_characters_character_spell.sql \ 7078_01_mangos_spell_proc_event.sql \ + 7092_01_mangos_player_xp_for_level.sql \ README ## Additional files to include when running 'make dist' @@ -254,4 +255,5 @@ EXTRA_DIST = \ 7075_02_mangos_spell_learn_spell.sql \ 7077_01_characters_character_spell.sql \ 7078_01_mangos_spell_proc_event.sql \ + 7092_01_mangos_player_xp_for_level.sql \ README diff --git a/src/game/Formulas.h b/src/game/Formulas.h index a00e523d1..cea5346fe 100644 --- a/src/game/Formulas.h +++ b/src/game/Formulas.h @@ -116,66 +116,6 @@ namespace MaNGOS return (uint32)(xp_gain*sWorld.getRate(RATE_XP_KILL)); } - inline uint32 xp_Diff(uint32 lvl) - { - if( lvl < 29 ) - return 0; - if( lvl == 29 ) - return 1; - if( lvl == 30 ) - return 3; - if( lvl == 31 ) - return 6; - else - return (5*(lvl-30)); - } - - inline uint32 mxp(uint32 lvl) - { - if (lvl < 60) - { - return (45 + (5*lvl)); - } - else - { - return (235 + (5*lvl)); - } - } - - inline uint32 xp_to_level(uint32 lvl) - { - uint32 xp = 0; - if (lvl < 60) - { - xp = (8*lvl + xp_Diff(lvl)) * mxp(lvl); - } - else if (lvl == 60) - { - xp = (155 + mxp(lvl) * (1344 - 70 - ((69 - lvl) * (7 + (69 - lvl) * 8 - 1)/2))); - } - else if (lvl < 70) - { - xp = (155 + mxp(lvl) * (1344 - ((69-lvl) * (7 + (69 - lvl) * 8 - 1)/2))); - }else - { - // level higher than 70 is not supported - xp = (uint32)(779700 * (pow(sWorld.getRate(RATE_XP_PAST_70), (int32)lvl - 69))); - return ((xp < 0x7fffffff) ? xp : 0x7fffffff); - } - - // The XP to Level is always rounded to the nearest 100 points (50 rounded to high). - xp = ((xp + 50) / 100) * 100; // use additional () for prevent free association operations in C++ - - if ((lvl > 10) && (lvl < 60)) // compute discount added in 2.3.x - { - uint32 discount = (lvl < 28) ? (lvl - 10) : 18; - xp = (xp * (100 - discount)) / 100; // apply discount - xp = (xp / 100) * 100; // floor to hundreds - } - - return xp; - } - inline float xp_in_group_rate(uint32 count, bool isRaid) { if(isRaid) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 2bc096ccf..c7d25cb1e 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -2559,6 +2559,67 @@ void ObjectMgr::LoadPlayerInfo() } } } + + // Loading xp per level data + { + mPlayerXPperLevel.resize(sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)); + for (uint32 level = 0; level < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL); ++level) + mPlayerXPperLevel[level] = 0; + + // 0 1 + QueryResult *result = WorldDatabase.Query("SELECT lvl, xp_for_next_level FROM player_xp_for_level"); + + uint32 count = 0; + + if (!result) + { + barGoLink bar( 1 ); + + sLog.outString(); + sLog.outString( ">> Loaded %u xp for level definitions", count ); + sLog.outErrorDb( "Error loading `player_xp_for_level` table or empty table."); + exit(1); + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field* fields = result->Fetch(); + + uint32 current_level = fields[0].GetUInt32(); + uint32 current_xp = fields[1].GetUInt32(); + + if(current_level >= sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) + { + if(current_level > STRONG_MAX_LEVEL) // hardcoded level maximum + sLog.outErrorDb("Wrong (> %u) level %u in `player_xp_for_level` table, ignoring.", STRONG_MAX_LEVEL,current_level); + else + sLog.outDetail("Unused (> MaxPlayerLevel in mangosd.conf) level %u in `player_xp_for_levels` table, ignoring.",current_level); + continue; + } + //PlayerXPperLevel + mPlayerXPperLevel[current_level] = current_xp; + bar.step(); + ++count; + } + while (result->NextRow()); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u xp for level definitions", count ); + } + + // fill level gaps + for (uint32 level = 1; level < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL); ++level) + { + if( mPlayerXPperLevel[level] == 0) + { + sLog.outErrorDb("Level %i does not have XP for level data. Using data of level [%i] + 100.",level+1, level); + mPlayerXPperLevel[level] = mPlayerXPperLevel[level-1]+100; + } + } } void ObjectMgr::GetPlayerClassLevelInfo(uint32 class_, uint32 level, PlayerClassLevelInfo* info) const @@ -5714,6 +5775,13 @@ uint32 ObjectMgr::GetBaseXP(uint32 level) return mBaseXPTable[level] ? mBaseXPTable[level] : 0; } +uint32 ObjectMgr::GetXPForLevel(uint32 level) +{ + if (level < mPlayerXPperLevel.size()) + return mPlayerXPperLevel[level]; + return 0; +} + void ObjectMgr::LoadPetNames() { uint32 count = 0; diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index eac5a6bf2..b8b75f0ba 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -568,6 +568,7 @@ class ObjectMgr std::string GeneratePetName(uint32 entry); uint32 GetBaseXP(uint32 level); + uint32 GetXPForLevel(uint32 level); int32 GetFishingBaseSkillLevel(uint32 entry) const { @@ -862,6 +863,9 @@ class ObjectMgr void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const; PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES]; + typedef std::vector PlayerXPperLevel; // [level] + PlayerXPperLevel mPlayerXPperLevel; + typedef std::map BaseXPMap; // [area level][base xp] BaseXPMap mBaseXPTable; diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 93894e4d3..df8042603 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -700,7 +700,7 @@ void Pet::GivePetXP(uint32 xp) newXP -= nextLvlXP; SetLevel( level + 1 ); - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((MaNGOS::XP::xp_to_level(level+1))/4)); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, objmgr.GetXPForLevel(level+1)/4); level = getLevel(); nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); @@ -763,7 +763,7 @@ bool Pet::CreateBaseAtCreature(Creature* creature) setPowerType(POWER_FOCUS); SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0); SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0); - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((MaNGOS::XP::xp_to_level(creature->getLevel()))/4)); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, objmgr.GetXPForLevel(creature->getLevel())/4); SetUInt32Value(UNIT_NPC_FLAGS, 0); CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(creature->GetCreatureInfo()->family); @@ -906,7 +906,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel) } case HUNTER_PET: { - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((MaNGOS::XP::xp_to_level(petlevel))/4)); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, objmgr.GetXPForLevel(petlevel)/4); learnLevelupSpells(); //these formula may not be correct; however, it is designed to be close to what it should be //this makes dps 0.5 of pets level diff --git a/src/game/Player.cpp b/src/game/Player.cpp index e5bc23984..f71bc979c 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -2182,7 +2182,7 @@ void Player::GiveLevel(uint32 level) GetSession()->SendPacket(&data); - SetUInt32Value(PLAYER_NEXT_LEVEL_XP, MaNGOS::XP::xp_to_level(level)); + SetUInt32Value(PLAYER_NEXT_LEVEL_XP, objmgr.GetXPForLevel(level)); //update level, max level of skills if(getLevel()!= level) @@ -2261,7 +2261,7 @@ void Player::InitStatsForLevel(bool reapplyMods) objmgr.GetPlayerLevelInfo(getRace(),getClass(),getLevel(),&info); SetUInt32Value(PLAYER_FIELD_MAX_LEVEL, sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL) ); - SetUInt32Value(PLAYER_NEXT_LEVEL_XP, MaNGOS::XP::xp_to_level(getLevel())); + SetUInt32Value(PLAYER_NEXT_LEVEL_XP, objmgr.GetXPForLevel(getLevel())); UpdateSkillsForLevel (); diff --git a/src/game/World.cpp b/src/game/World.cpp index 74be1cbe8..6453715c6 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -464,7 +464,6 @@ void World::LoadConfigSettings(bool reload) rate_values[RATE_XP_KILL] = sConfig.GetFloatDefault("Rate.XP.Kill", 1.0f); rate_values[RATE_XP_QUEST] = sConfig.GetFloatDefault("Rate.XP.Quest", 1.0f); rate_values[RATE_XP_EXPLORE] = sConfig.GetFloatDefault("Rate.XP.Explore", 1.0f); - rate_values[RATE_XP_PAST_70] = sConfig.GetFloatDefault("Rate.XP.PastLevel70", 1.0f); rate_values[RATE_REPUTATION_GAIN] = sConfig.GetFloatDefault("Rate.Reputation.Gain", 1.0f); rate_values[RATE_CREATURE_NORMAL_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Normal.Damage", 1.0f); rate_values[RATE_CREATURE_ELITE_ELITE_DAMAGE] = sConfig.GetFloatDefault("Rate.Creature.Elite.Elite.Damage", 1.0f); diff --git a/src/game/World.h b/src/game/World.h index 98622effe..f75118e8c 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -217,7 +217,6 @@ enum Rates RATE_XP_KILL, RATE_XP_QUEST, RATE_XP_EXPLORE, - RATE_XP_PAST_70, RATE_REPUTATION_GAIN, RATE_CREATURE_NORMAL_HP, RATE_CREATURE_ELITE_ELITE_HP, diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in index c0f099640..241258ced 100644 --- a/src/mangosd/mangosd.conf.dist.in +++ b/src/mangosd/mangosd.conf.dist.in @@ -973,10 +973,6 @@ Visibility.Distance.Grey.Object = 10 # XP rates # Default: 1 # -# Rate.XP.PastLevel70 -# XP needed per level past 70 (Rates below 1 not recommended) -# Default: 1 -# # Rate.Rest.InGame # Rate.Rest.Offline.InTavernOrCity # Rate.Rest.Offline.InWilderness @@ -1086,7 +1082,6 @@ Rate.Drop.Money = 1 Rate.XP.Kill = 1 Rate.XP.Quest = 1 Rate.XP.Explore = 1 -Rate.XP.PastLevel70 = 1 Rate.Rest.InGame = 1 Rate.Rest.Offline.InTavernOrCity = 1 Rate.Rest.Offline.InWilderness = 1 diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 49be127c6..d159296e9 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "7091" + #define REVISION_NR "7092" #endif // __REVISION_NR_H__ -- 2.11.4.GIT