diff options
author | n0n4m3 <none@none> | 2010-04-14 13:29:56 +0400 |
---|---|---|
committer | n0n4m3 <none@none> | 2010-04-14 13:29:56 +0400 |
commit | a6af93c3d6df91e6f9f5d374a55ef1d7b8d7a5f4 (patch) | |
tree | ca5179cadd1785e92cf79dd48f2392e46fdcda7e | |
parent | 8b6005666dc10ba6acb423c7ad936b8b290fd6ee (diff) |
Create new table character_stats for external tools(website,etc). This table use only when player logout. Original code by hunuza.
--HG--
branch : trunk
-rw-r--r-- | sql/characters.sql | 49 | ||||
-rw-r--r-- | sql/updates/7906_characters_character_stats.sql | 34 | ||||
-rw-r--r-- | src/game/Player.cpp | 39 | ||||
-rw-r--r-- | src/game/Player.h | 1 | ||||
-rw-r--r-- | src/game/World.cpp | 8 | ||||
-rw-r--r-- | src/game/World.h | 2 | ||||
-rw-r--r-- | src/trinitycore/trinitycore.conf.dist | 12 |
7 files changed, 145 insertions, 0 deletions
diff --git a/sql/characters.sql b/sql/characters.sql index 0d5158a1f09..d5200917a56 100644 --- a/sql/characters.sql +++ b/sql/characters.sql @@ -1043,6 +1043,55 @@ LOCK TABLES `character_spell_cooldown` WRITE; UNLOCK TABLES; -- +-- Table structure for table `character_stats` +-- + +DROP TABLE IF EXISTS `character_stats`; +CREATE TABLE `character_stats` ( + `guid` int(11) unsigned NOT NULL default '0' COMMENT 'Global Unique Identifier, Low part', + `maxhealth` int(10) UNSIGNED NOT NULL default '0', + `maxpower1` int(10) UNSIGNED NOT NULL default '0', + `maxpower2` int(10) UNSIGNED NOT NULL default '0', + `maxpower3` int(10) UNSIGNED NOT NULL default '0', + `maxpower4` int(10) UNSIGNED NOT NULL default '0', + `maxpower5` int(10) UNSIGNED NOT NULL default '0', + `maxpower6` int(10) UNSIGNED NOT NULL default '0', + `maxpower7` int(10) UNSIGNED NOT NULL default '0', + `strength` int(10) UNSIGNED NOT NULL default '0', + `agility` int(10) UNSIGNED NOT NULL default '0', + `stamina` int(10) UNSIGNED NOT NULL default '0', + `intellect` int(10) UNSIGNED NOT NULL default '0', + `spirit` int(10) UNSIGNED NOT NULL default '0', + `armor` int(10) UNSIGNED NOT NULL default '0', + `resHoly` int(10) UNSIGNED NOT NULL default '0', + `resFire` int(10) UNSIGNED NOT NULL default '0', + `resNature` int(10) UNSIGNED NOT NULL default '0', + `resFrost` int(10) UNSIGNED NOT NULL default '0', + `resShadow` int(10) UNSIGNED NOT NULL default '0', + `resArcane` int(10) UNSIGNED NOT NULL default '0', + `blockPct` float UNSIGNED NOT NULL default '0', + `dodgePct` float UNSIGNED NOT NULL default '0', + `parryPct` float UNSIGNED NOT NULL default '0', + `critPct` float UNSIGNED NOT NULL default '0', + `rangedCritPct` float UNSIGNED NOT NULL default '0', + `spellCritPct` float UNSIGNED NOT NULL default '0', + `attackPower` int(10) UNSIGNED NOT NULL default '0', + `rangedAttackPower` int(10) UNSIGNED NOT NULL default '0', + `spellPower` int(10) UNSIGNED NOT NULL default '0', + + PRIMARY KEY (`guid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `character_stats` +-- + +LOCK TABLES `character_stats` WRITE; +/*!40000 ALTER TABLE `character_stats` DISABLE KEYS */; +/*!40000 ALTER TABLE `character_stats` ENABLE KEYS */; +UNLOCK TABLES; + +-- -- Table structure for table `character_talent` -- diff --git a/sql/updates/7906_characters_character_stats.sql b/sql/updates/7906_characters_character_stats.sql new file mode 100644 index 00000000000..82aebbbaf51 --- /dev/null +++ b/sql/updates/7906_characters_character_stats.sql @@ -0,0 +1,34 @@ +DROP TABLE IF EXISTS `character_stats`; +CREATE TABLE `character_stats` ( + `guid` int(11) unsigned NOT NULL default '0' COMMENT 'Global Unique Identifier, Low part', + `maxhealth` int(10) UNSIGNED NOT NULL default '0', + `maxpower1` int(10) UNSIGNED NOT NULL default '0', + `maxpower2` int(10) UNSIGNED NOT NULL default '0', + `maxpower3` int(10) UNSIGNED NOT NULL default '0', + `maxpower4` int(10) UNSIGNED NOT NULL default '0', + `maxpower5` int(10) UNSIGNED NOT NULL default '0', + `maxpower6` int(10) UNSIGNED NOT NULL default '0', + `maxpower7` int(10) UNSIGNED NOT NULL default '0', + `strength` int(10) UNSIGNED NOT NULL default '0', + `agility` int(10) UNSIGNED NOT NULL default '0', + `stamina` int(10) UNSIGNED NOT NULL default '0', + `intellect` int(10) UNSIGNED NOT NULL default '0', + `spirit` int(10) UNSIGNED NOT NULL default '0', + `armor` int(10) UNSIGNED NOT NULL default '0', + `resHoly` int(10) UNSIGNED NOT NULL default '0', + `resFire` int(10) UNSIGNED NOT NULL default '0', + `resNature` int(10) UNSIGNED NOT NULL default '0', + `resFrost` int(10) UNSIGNED NOT NULL default '0', + `resShadow` int(10) UNSIGNED NOT NULL default '0', + `resArcane` int(10) UNSIGNED NOT NULL default '0', + `blockPct` float UNSIGNED NOT NULL default '0', + `dodgePct` float UNSIGNED NOT NULL default '0', + `parryPct` float UNSIGNED NOT NULL default '0', + `critPct` float UNSIGNED NOT NULL default '0', + `rangedCritPct` float UNSIGNED NOT NULL default '0', + `spellCritPct` float UNSIGNED NOT NULL default '0', + `attackPower` int(10) UNSIGNED NOT NULL default '0', + `rangedAttackPower` int(10) UNSIGNED NOT NULL default '0', + `spellPower` int(10) UNSIGNED NOT NULL default '0', + PRIMARY KEY (`guid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 0d70553c2c0..8441dd31fa5 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -17448,6 +17448,11 @@ void Player::SaveToDB() CharacterDatabase.CommitTransaction(); + // check if stats should only be saved on logout + // save stats can be out of transaction + if (m_session->isLogingOut() || !sWorld.getConfig(CONFIG_STATS_SAVE_ONLY_ON_LOGOUT)) + _SaveStats(); + // save pet (hunter pet level and experience and all type pets health/mana). if (Pet* pet = GetPet()) pet->SavePetToDB(PET_SAVE_AS_CURRENT); @@ -17789,6 +17794,40 @@ void Player::_SaveSpells() } } +// save player stats -- only for external usage +// real stats will be recalculated on player login +void Player::_SaveStats() +{ + // check if stat saving is enabled and if char level is high enough + if (!sWorld.getConfig(CONFIG_MIN_LEVEL_STAT_SAVE) || getLevel() < sWorld.getConfig(CONFIG_MIN_LEVEL_STAT_SAVE)) + return; + + CharacterDatabase.PExecute("DELETE FROM character_stats WHERE guid = '%u'", GetGUIDLow()); + std::ostringstream ss; + ss << "INSERT INTO character_stats (guid, maxhealth, maxpower1, maxpower2, maxpower3, maxpower4, maxpower5, maxpower6, maxpower7, " + "strength, agility, stamina, intellect, spirit, armor, resHoly, resFire, resNature, resFrost, resShadow, resArcane, " + "blockPct, dodgePct, parryPct, critPct, rangedCritPct, spellCritPct, attackPower, rangedAttackPower, spellPower) VALUES (" + << GetGUIDLow() << ", " + << GetMaxHealth() << ", "; + for (int i = 0; i < MAX_POWERS; ++i) + ss << GetMaxPower(Powers(i)) << ", "; + for (int i = 0; i < MAX_STATS; ++i) + ss << GetStat(Stats(i)) << ", "; + // armor + school resistances + for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) + ss << GetResistance(SpellSchools(i)) << ","; + ss << GetFloatValue(PLAYER_BLOCK_PERCENTAGE) << ", " + << GetFloatValue(PLAYER_DODGE_PERCENTAGE) << ", " + << GetFloatValue(PLAYER_PARRY_PERCENTAGE) << ", " + << GetFloatValue(PLAYER_CRIT_PERCENTAGE) << ", " + << GetFloatValue(PLAYER_RANGED_CRIT_PERCENTAGE) << ", " + << GetFloatValue(PLAYER_SPELL_CRIT_PERCENTAGE1) << ", " + << GetUInt32Value(UNIT_FIELD_ATTACK_POWER) << ", " + << GetUInt32Value(UNIT_FIELD_RANGED_ATTACK_POWER) << ", " + << GetBaseSpellPowerBonus() << ")"; + CharacterDatabase.Execute(ss.str().c_str()); +} + void Player::outDebugValues() const { if (!sLog.IsOutDebug()) // optimize disabled debug output diff --git a/src/game/Player.h b/src/game/Player.h index 244a50c58ca..bccf9030fe1 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -2411,6 +2411,7 @@ class Player : public Unit, public GridObject<Player> void _SaveBGData(); void _SaveGlyphs(); void _SaveTalents(); + void _SaveStats(); void _SetCreateBits(UpdateMask *updateMask, Player *target) const; void _SetUpdateBits(UpdateMask *updateMask, Player *target) const; diff --git a/src/game/World.cpp b/src/game/World.cpp index 630f339b7e4..057e3489216 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -613,6 +613,14 @@ void World::LoadConfigSettings(bool reload) m_configs[CONFIG_GRID_UNLOAD] = sConfig.GetBoolDefault("GridUnload", true); m_configs[CONFIG_INTERVAL_SAVE] = sConfig.GetIntDefault("PlayerSaveInterval", 15 * MINUTE * IN_MILISECONDS); m_configs[CONFIG_INTERVAL_DISCONNECT_TOLERANCE] = sConfig.GetIntDefault("DisconnectToleranceInterval", 0); + m_configs[CONFIG_STATS_SAVE_ONLY_ON_LOGOUT] = sConfig.GetBoolDefault("PlayerSave.Stats.SaveOnlyOnLogout", true); + + m_configs[CONFIG_MIN_LEVEL_STAT_SAVE] = sConfig.GetIntDefault("PlayerSave.Stats.MinLevel", 0); + if (m_configs[CONFIG_MIN_LEVEL_STAT_SAVE] > MAX_LEVEL) + { + sLog.outError("PlayerSave.Stats.MinLevel (%i) must be in range 0..80. Using default, do not save character stats (0).",m_configs[CONFIG_MIN_LEVEL_STAT_SAVE]); + m_configs[CONFIG_MIN_LEVEL_STAT_SAVE] = 0; + } m_configs[CONFIG_INTERVAL_GRIDCLEAN] = sConfig.GetIntDefault("GridCleanUpDelay", 5 * MINUTE * IN_MILISECONDS); if (m_configs[CONFIG_INTERVAL_GRIDCLEAN] < MIN_GRID_DELAY) diff --git a/src/game/World.h b/src/game/World.h index 958ab584488..0a336395921 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -274,6 +274,8 @@ enum WorldConfigs CONFIG_CLIENTCACHE_VERSION, CONFIG_GUILD_EVENT_LOG_COUNT, CONFIG_GUILD_BANK_EVENT_LOG_COUNT, + CONFIG_MIN_LEVEL_STAT_SAVE, + CONFIG_STATS_SAVE_ONLY_ON_LOGOUT, CONFIG_VALUE_COUNT }; diff --git a/src/trinitycore/trinitycore.conf.dist b/src/trinitycore/trinitycore.conf.dist index 4e94e3dee75..c6582bb1837 100644 --- a/src/trinitycore/trinitycore.conf.dist +++ b/src/trinitycore/trinitycore.conf.dist @@ -145,6 +145,16 @@ EAIErrorLevel = 2 # Player save interval (in milliseconds) # Default: 900000 (15 min) # +# PlayerSave.Stats.MinLevel +# Minimum level for saving character stats for external usage in database +# Default: 0 (do not save character stats) +# 1+ (save stats for characters with level 1+) +# +# PlayerSave.Stats.SaveOnlyOnLogout +# Enable/Disable saving of character stats only on logout +# Default: 1 (only save on logout) +# 0 (save on every player save) +# # vmap.enableLOS # vmap.enableHeight # Enable/Disable VMmap support for line of sight and height calculation @@ -227,6 +237,8 @@ GridCleanUpDelay = 300000 MapUpdateInterval = 100 ChangeWeatherInterval = 600000 PlayerSaveInterval = 900000 +PlayerSave.Stats.MinLevel = 0 +PlayerSave.Stats.SaveOnlyOnLogout = 1 vmap.enableLOS = 0 vmap.enableHeight = 0 vmap.ignoreMapIds = "369" |