From 228b9329259e136bfab281127963e99ec6ff43a0 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 12 Jul 2015 00:41:56 +0200 Subject: [PATCH] Core/Players: Fixed power slot ordering --- sql/base/characters_database.sql | 2 ++ sql/updates/characters/2015_07_12_00_characters.sql | 2 ++ src/server/game/DataStores/DB2Stores.cpp | 12 ++++++++++-- src/server/game/DataStores/DB2Stores.h | 4 +++- src/server/game/DataStores/DB2fmt.h | 2 +- src/server/game/Entities/Player/Player.cpp | 2 +- src/server/game/Entities/Unit/Unit.cpp | 8 ++++---- src/server/game/Miscellaneous/SharedDefines.h | 2 +- src/server/shared/DataStores/DB2Store.h | 8 ++++++++ src/server/shared/DataStores/DBStorageIterator.h | 3 +-- .../Database/Implementation/CharacterDatabase.cpp | 12 ++++++------ 11 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 sql/updates/characters/2015_07_12_00_characters.sql diff --git a/sql/base/characters_database.sql b/sql/base/characters_database.sql index e011983e2c..4332ea6051 100644 --- a/sql/base/characters_database.sql +++ b/sql/base/characters_database.sql @@ -1425,6 +1425,7 @@ CREATE TABLE `character_stats` ( `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', `strength` int(10) unsigned NOT NULL DEFAULT '0', `agility` int(10) unsigned NOT NULL DEFAULT '0', `stamina` int(10) unsigned NOT NULL DEFAULT '0', @@ -1627,6 +1628,7 @@ CREATE TABLE `characters` ( `power3` int(10) unsigned NOT NULL DEFAULT '0', `power4` int(10) unsigned NOT NULL DEFAULT '0', `power5` int(10) unsigned NOT NULL DEFAULT '0', + `power6` int(10) unsigned NOT NULL DEFAULT '0', `latency` mediumint(8) unsigned NOT NULL DEFAULT '0', `talentGroupsCount` tinyint(3) unsigned NOT NULL DEFAULT '1', `activeTalentGroup` tinyint(3) unsigned NOT NULL DEFAULT '0', diff --git a/sql/updates/characters/2015_07_12_00_characters.sql b/sql/updates/characters/2015_07_12_00_characters.sql new file mode 100644 index 0000000000..575097f7ff --- /dev/null +++ b/sql/updates/characters/2015_07_12_00_characters.sql @@ -0,0 +1,2 @@ +ALTER TABLE `characters` ADD `power6` int(10) unsigned NOT NULL DEFAULT '0' AFTER `power5`; +ALTER TABLE `character_stats` ADD `maxpower6` int(10) unsigned NOT NULL DEFAULT '0' AFTER `maxpower5`; diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp index a3eb7fed48..5e9344f10b 100644 --- a/src/server/game/DataStores/DB2Stores.cpp +++ b/src/server/game/DataStores/DB2Stores.cpp @@ -287,6 +287,7 @@ void DB2Manager::LoadStores(std::string const& dataPath) for (CharStartOutfitEntry const* outfit : sCharStartOutfitStore) _charStartOutfits[outfit->RaceID | (outfit->ClassID << 8) | (outfit->GenderID << 16)] = outfit; + sChrClassesXPowerTypesStore.Sort(&ChrClassesXPowerTypesEntryComparator::Compare); for (uint32 i = 0; i < MAX_CLASSES; ++i) for (uint32 j = 0; j < MAX_POWERS; ++j) _powersByClass[i][j] = MAX_POWERS; @@ -784,14 +785,21 @@ std::vector DB2Manager::GetSpellPowers(uint32 spellId, D return powers; } -bool DB2Manager::GlyphSlotEntryComparator::operator()(GlyphSlotEntry const* left, GlyphSlotEntry const* right) const +bool DB2Manager::ChrClassesXPowerTypesEntryComparator::Compare(ChrClassesXPowerTypesEntry const* left, ChrClassesXPowerTypesEntry const* right) +{ + if (left->ClassID != right->ClassID) + return left->ClassID < right->ClassID; + return left->PowerType < right->PowerType; +} + +bool DB2Manager::GlyphSlotEntryComparator::Compare(GlyphSlotEntry const* left, GlyphSlotEntry const* right) { if (left->Tooltip != right->Tooltip) return left->Tooltip < right->Tooltip; return left->Type > right->Type; } -bool DB2Manager::MountTypeXCapabilityEntryComparator::operator()(MountTypeXCapabilityEntry const* left, MountTypeXCapabilityEntry const* right) const +bool DB2Manager::MountTypeXCapabilityEntryComparator::Compare(MountTypeXCapabilityEntry const* left, MountTypeXCapabilityEntry const* right) { if (left->MountTypeID == right->MountTypeID) return left->OrderIndex > right->OrderIndex; diff --git a/src/server/game/DataStores/DB2Stores.h b/src/server/game/DataStores/DB2Stores.h index 32b6dc4e98..b99a5f7530 100644 --- a/src/server/game/DataStores/DB2Stores.h +++ b/src/server/game/DataStores/DB2Stores.h @@ -115,12 +115,14 @@ typedef std::vector HotfixData; #define DEFINE_DB2_SET_COMPARATOR(structure) \ struct structure ## Comparator : public std::binary_function \ { \ - bool operator()(structure const* left, structure const* right) const; \ + bool operator()(structure const* left, structure const* right) const { return Compare(left, right); } \ + static bool Compare(structure const* left, structure const* right); \ }; class DB2Manager { public: + DEFINE_DB2_SET_COMPARATOR(ChrClassesXPowerTypesEntry); DEFINE_DB2_SET_COMPARATOR(GlyphSlotEntry); DEFINE_DB2_SET_COMPARATOR(MountTypeXCapabilityEntry); diff --git a/src/server/game/DataStores/DB2fmt.h b/src/server/game/DataStores/DB2fmt.h index a7b1e3e795..b7f3356176 100644 --- a/src/server/game/DataStores/DB2fmt.h +++ b/src/server/game/DataStores/DB2fmt.h @@ -24,7 +24,7 @@ char const AuctionHouseFormat[] = "niiis"; char const BarberShopStyleFormat[] = "nissfiii"; char const BroadcastTextFormat[] = "nissiiiiiiiii"; char const CharStartOutfitFormat[] = "nbbbbiiiiiiiiiiiiiiiiiiiiiiiiii"; -char const ChrClassesXPowerTypesFormat[] = "nii"; +char const ChrClassesXPowerTypesFormat[] = "iii"; char const CinematicSequencesFormat[] = "niiiiiiiii"; char const CreatureDisplayInfoFormat[] = "niiiffissssiiiiiiiiiii"; char const CreatureTypeFormat[] = "nsi"; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 35f0b92f3f..82a06801b8 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -2414,7 +2414,7 @@ void Player::Regenerate(Powers power) // Skip regeneration for power type we cannot have uint32 powerIndex = GetPowerIndex(power); - if (powerIndex == MAX_POWERS) + if (powerIndex == MAX_POWERS || powerIndex >= MAX_POWERS_PER_CLASS) return; float addvalue = 0.0f; diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 3942853192..d247e46e59 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -11505,7 +11505,7 @@ void Unit::SetMaxHealth(uint32 val) int32 Unit::GetPower(Powers power) const { uint32 powerIndex = GetPowerIndex(power); - if (powerIndex == MAX_POWERS) + if (powerIndex == MAX_POWERS || powerIndex >= MAX_POWERS_PER_CLASS) return 0; return GetUInt32Value(UNIT_FIELD_POWER + powerIndex); @@ -11514,7 +11514,7 @@ int32 Unit::GetPower(Powers power) const int32 Unit::GetMaxPower(Powers power) const { uint32 powerIndex = GetPowerIndex(power); - if (powerIndex == MAX_POWERS) + if (powerIndex == MAX_POWERS || powerIndex >= MAX_POWERS_PER_CLASS) return 0; return GetInt32Value(UNIT_FIELD_MAXPOWER + powerIndex); @@ -11523,7 +11523,7 @@ int32 Unit::GetMaxPower(Powers power) const void Unit::SetPower(Powers power, int32 val) { uint32 powerIndex = GetPowerIndex(power); - if (powerIndex == MAX_POWERS) + if (powerIndex == MAX_POWERS || powerIndex >= MAX_POWERS_PER_CLASS) return; int32 maxPower = int32(GetMaxPower(power)); @@ -11557,7 +11557,7 @@ void Unit::SetPower(Powers power, int32 val) void Unit::SetMaxPower(Powers power, int32 val) { uint32 powerIndex = GetPowerIndex(power); - if (powerIndex == MAX_POWERS) + if (powerIndex == MAX_POWERS || powerIndex >= MAX_POWERS_PER_CLASS) return; int32 cur_power = GetPower(power); diff --git a/src/server/game/Miscellaneous/SharedDefines.h b/src/server/game/Miscellaneous/SharedDefines.h index f04f7b537d..d767f88e10 100644 --- a/src/server/game/Miscellaneous/SharedDefines.h +++ b/src/server/game/Miscellaneous/SharedDefines.h @@ -267,7 +267,7 @@ enum Powers // (6.0) POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) }; -#define MAX_POWERS_PER_CLASS 5 +#define MAX_POWERS_PER_CLASS 6 enum SpellSchools : uint16 { diff --git a/src/server/shared/DataStores/DB2Store.h b/src/server/shared/DataStores/DB2Store.h index c541a6651a..b4ae20ce1d 100644 --- a/src/server/shared/DataStores/DB2Store.h +++ b/src/server/shared/DataStores/DB2Store.h @@ -181,6 +181,14 @@ public: DB2DatabaseLoader(_fileName).LoadStrings(_format, _hotfixStatement + 1, locale, _indexTable.AsChar, _stringPoolList); } + typedef bool(*SortFunc)(T const* left, T const* right); + + void Sort(SortFunc pred) + { + ASSERT(strpbrk(_format, "nd") == nullptr, "Only non-indexed storages can be sorted"); + std::sort(_indexTable.AsT, _indexTable.AsT + _indexTableSize, pred); + } + iterator begin() { return iterator(_indexTable.AsT, _indexTableSize); } iterator end() { return iterator(_indexTable.AsT, _indexTableSize, _indexTableSize); } diff --git a/src/server/shared/DataStores/DBStorageIterator.h b/src/server/shared/DataStores/DBStorageIterator.h index a34cd6677c..767900a123 100644 --- a/src/server/shared/DataStores/DBStorageIterator.h +++ b/src/server/shared/DataStores/DBStorageIterator.h @@ -30,9 +30,8 @@ public: { if (_pos < _end) { - do + while (_pos < _end && !_index[_pos]) ++_pos; - while (_pos < _end && !_index[_pos]); } } diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp index a9d0ca6640..233ec96bab 100644 --- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp +++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp @@ -79,7 +79,7 @@ void CharacterDatabaseConnection::DoPrepareStatements() "position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, " "resettalents_time, talentTree, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeonDifficulty, " "totalKills, todayKills, yesterdayKills, chosenTitle, watchedFaction, drunk, " - "health, power1, power2, power3, power4, power5, instance_id, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, knownTitles, actionBars, grantableLevels, raidDifficulty, legacyRaidDifficulty " + "health, power1, power2, power3, power4, power5, power6, instance_id, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, knownTitles, actionBars, grantableLevels, raidDifficulty, legacyRaidDifficulty " "FROM characters WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_SEL_GROUP_MEMBER, "SELECT guid FROM group_member WHERE memberGuid = ?", CONNECTION_BOTH); @@ -393,13 +393,13 @@ void CharacterDatabaseConnection::DoPrepareStatements() "extra_flags, stable_slots, at_login, zone, " "death_expire_time, taxi_path, totalKills, " "todayKills, yesterdayKills, chosenTitle, watchedFaction, drunk, health, power1, power2, power3, " - "power4, power5, latency, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, knownTitles, actionBars, grantableLevels) VALUES " - "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", CONNECTION_ASYNC); + "power4, power5, power6, latency, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, knownTitles, actionBars, grantableLevels) VALUES " + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", CONNECTION_ASYNC); PrepareStatement(CHAR_UPD_CHARACTER, "UPDATE characters SET name=?,race=?,class=?,gender=?,level=?,xp=?,money=?,playerBytes=?,playerBytes2=?,playerFlags=?," "map=?,instance_id=?,dungeonDifficulty=?,raidDifficulty=?,legacyRaidDifficulty=?,position_x=?,position_y=?,position_z=?,orientation=?,trans_x=?,trans_y=?,trans_z=?,trans_o=?,transguid=?,taximask=?,cinematic=?,totaltime=?,leveltime=?,rest_bonus=?," "logout_time=?,is_logout_resting=?,resettalents_cost=?,resettalents_time=?,talentTree=?,extra_flags=?,stable_slots=?,at_login=?,zone=?,death_expire_time=?,taxi_path=?," "totalKills=?,todayKills=?,yesterdayKills=?,chosenTitle=?," - "watchedFaction=?,drunk=?,health=?,power1=?,power2=?,power3=?,power4=?,power5=?,latency=?,talentGroupsCount=?,activeTalentGroup=?,exploredZones=?," + "watchedFaction=?,drunk=?,health=?,power1=?,power2=?,power3=?,power4=?,power5=?,power6=?,latency=?,talentGroupsCount=?,activeTalentGroup=?,exploredZones=?," "equipmentCache=?,knownTitles=?,actionBars=?,grantableLevels=?,online=? WHERE guid=?", CONNECTION_ASYNC); PrepareStatement(CHAR_UPD_ADD_AT_LOGIN_FLAG, "UPDATE characters SET at_login = at_login | ? WHERE guid = ?", CONNECTION_ASYNC); @@ -573,9 +573,9 @@ void CharacterDatabaseConnection::DoPrepareStatements() PrepareStatement(CHAR_UPD_CHAR_SKILLS, "UPDATE character_skills SET value = ?, max = ? WHERE guid = ? AND skill = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_CHAR_SPELL, "INSERT INTO character_spell (guid, spell, active, disabled) VALUES (?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_CHAR_STATS, "DELETE FROM character_stats WHERE guid = ?", CONNECTION_ASYNC); - PrepareStatement(CHAR_INS_CHAR_STATS, "INSERT INTO character_stats (guid, maxhealth, maxpower1, maxpower2, maxpower3, maxpower4, maxpower5, strength, agility, stamina, intellect, spirit, " + PrepareStatement(CHAR_INS_CHAR_STATS, "INSERT INTO character_stats (guid, maxhealth, maxpower1, maxpower2, maxpower3, maxpower4, maxpower5, maxpower6, strength, agility, stamina, intellect, spirit, " "armor, resHoly, resFire, resNature, resFrost, resShadow, resArcane, blockPct, dodgePct, parryPct, critPct, rangedCritPct, spellCritPct, attackPower, rangedAttackPower, " - "spellPower, resilience) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); + "spellPower, resilience) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_PETITION_BY_OWNER, "DELETE FROM petition WHERE ownerguid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_PETITION_SIGNATURE_BY_OWNER, "DELETE FROM petition_sign WHERE ownerguid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_CHAR_GLYPHS, "INSERT INTO character_glyphs (guid, talentGroup, glyph1, glyph2, glyph3, glyph4, glyph5, glyph6) VALUES(?, ?, ?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC);