mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-17 16:10:49 +01:00
Merge pull request #7891 from tibbi/title_converter
adding Title converter to faction converter, original author Silinoron
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
-- Title converter
|
||||
DROP TABLE IF EXISTS `player_factionchange_titles`;
|
||||
CREATE TABLE `player_factionchange_titles` (
|
||||
`alliance_id` int(8) NOT NULL,
|
||||
`horde_id` int(8) NOT NULL,
|
||||
PRIMARY KEY (`alliance_id`,`horde_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
DELETE FROM `player_factionchange_titles` WHERE `alliance_id` IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,48,75,113,126,146,147,148,149);
|
||||
INSERT INTO `player_factionchange_titles` (`alliance_id`,`horde_id`) VALUES
|
||||
(1, 15),
|
||||
(2, 16),
|
||||
(3, 17),
|
||||
(4, 18),
|
||||
(5, 19),
|
||||
(6, 20),
|
||||
(7, 21),
|
||||
(8, 22),
|
||||
(9, 23),
|
||||
(10, 24),
|
||||
(11, 25),
|
||||
(12, 26),
|
||||
(13, 27),
|
||||
(14, 28),
|
||||
(48, 47),
|
||||
(75, 76),
|
||||
(113, 153),
|
||||
(126, 127),
|
||||
(146, 152),
|
||||
(147, 154),
|
||||
(148, 151),
|
||||
(149, 150);
|
||||
@@ -8605,6 +8605,41 @@ void ObjectMgr::LoadFactionChangeReputations()
|
||||
sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u faction change reputation pairs in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadFactionChangeTitles()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
QueryResult result = WorldDatabase.Query("SELECT alliance_id, horde_id FROM player_factionchange_titles");
|
||||
|
||||
if (!result)
|
||||
{
|
||||
sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 faction change title pairs. DB table `player_factionchange_title` is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 alliance = fields[0].GetUInt32();
|
||||
uint32 horde = fields[1].GetUInt32();
|
||||
|
||||
if (!sCharTitlesStore.LookupEntry(alliance))
|
||||
sLog->outError(LOG_FILTER_SQL, "Title %u referenced in `player_factionchange_title` does not exist, pair skipped!", alliance);
|
||||
else if (!sCharTitlesStore.LookupEntry(horde))
|
||||
sLog->outError(LOG_FILTER_SQL, "Title %u referenced in `player_factionchange_title` does not exist, pair skipped!", horde);
|
||||
else
|
||||
FactionChange_Titles[alliance] = horde;
|
||||
|
||||
++count;
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u faction change title pairs in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
GameObjectTemplate const* ObjectMgr::GetGameObjectTemplate(uint32 entry)
|
||||
{
|
||||
GameObjectTemplateContainer::const_iterator itr = _gameObjectTemplateStore.find(entry);
|
||||
|
||||
@@ -1139,11 +1139,13 @@ class ObjectMgr
|
||||
CharacterConversionMap FactionChange_Items;
|
||||
CharacterConversionMap FactionChange_Spells;
|
||||
CharacterConversionMap FactionChange_Reputation;
|
||||
CharacterConversionMap FactionChange_Titles;
|
||||
|
||||
void LoadFactionChangeAchievements();
|
||||
void LoadFactionChangeItems();
|
||||
void LoadFactionChangeSpells();
|
||||
void LoadFactionChangeReputations();
|
||||
void LoadFactionChangeTitles();
|
||||
|
||||
private:
|
||||
// first free id for selected id type
|
||||
|
||||
@@ -1644,6 +1644,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
|
||||
uint32 level = uint32(fields[1].GetUInt8());
|
||||
uint32 at_loginFlags = fields[2].GetUInt16();
|
||||
uint32 used_loginFlag = ((recv_data.GetOpcode() == CMSG_CHAR_RACE_CHANGE) ? AT_LOGIN_CHANGE_RACE : AT_LOGIN_CHANGE_FACTION);
|
||||
char const* knownTitlesStr = fields[3].GetCString();
|
||||
|
||||
if (!sObjectMgr->GetPlayerInfo(race, playerClass))
|
||||
{
|
||||
@@ -2014,6 +2015,70 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
|
||||
stmt->setUInt32(2, lowGuid);
|
||||
trans->Append(stmt);
|
||||
}
|
||||
|
||||
// Title conversion
|
||||
if (knownTitlesStr)
|
||||
{
|
||||
const uint32 ktcount = KNOWN_TITLES_SIZE * 2;
|
||||
uint32 knownTitles[ktcount];
|
||||
Tokens tokens(knownTitlesStr, ' ', ktcount);
|
||||
|
||||
if (tokens.size() != ktcount)
|
||||
return;
|
||||
|
||||
for (uint32 index = 0; index < ktcount; ++index)
|
||||
knownTitles[index] = atol(tokens[index]);
|
||||
|
||||
for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Titles.begin(); it != sObjectMgr->FactionChange_Titles.end(); ++it)
|
||||
{
|
||||
uint32 title_alliance = it->first;
|
||||
uint32 title_horde = it->second;
|
||||
|
||||
CharTitlesEntry const* atitleInfo = sCharTitlesStore.LookupEntry(title_alliance);
|
||||
CharTitlesEntry const* htitleInfo = sCharTitlesStore.LookupEntry(title_horde);
|
||||
// new team
|
||||
if (team == BG_TEAM_ALLIANCE)
|
||||
{
|
||||
uint32 bitIndex = htitleInfo->bit_index;
|
||||
uint32 index = bitIndex / 32;
|
||||
uint32 old_flag = 1 << (bitIndex % 32);
|
||||
uint32 new_flag = 1 << (atitleInfo->bit_index % 32);
|
||||
if (knownTitles[index] & old_flag)
|
||||
{
|
||||
knownTitles[index] &= ~old_flag;
|
||||
// use index of the new title
|
||||
knownTitles[atitleInfo->bit_index / 32] |= new_flag;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 bitIndex = atitleInfo->bit_index;
|
||||
uint32 index = bitIndex / 32;
|
||||
uint32 old_flag = 1 << (bitIndex % 32);
|
||||
uint32 new_flag = 1 << (htitleInfo->bit_index % 32);
|
||||
if (knownTitles[index] & old_flag)
|
||||
{
|
||||
knownTitles[index] &= ~old_flag;
|
||||
// use index of the new title
|
||||
knownTitles[htitleInfo->bit_index / 32] |= new_flag;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream ss;
|
||||
for (uint32 index = 0; index < ktcount; ++index)
|
||||
ss << knownTitles[index] << ' ';
|
||||
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_TITLES_FACTION_CHANGE);
|
||||
stmt->setString(0, ss.str().c_str());
|
||||
stmt->setUInt32(1, lowGuid);
|
||||
trans->Append(stmt);
|
||||
|
||||
// unset any currently chosen title
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_RES_CHAR_TITLES_FACTION_CHANGE);
|
||||
stmt->setUInt32(0, lowGuid);
|
||||
trans->Append(stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
|
||||
@@ -1617,6 +1617,9 @@ void World::SetInitialWorldSettings()
|
||||
sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading faction change reputation pairs...");
|
||||
sObjectMgr->LoadFactionChangeReputations();
|
||||
|
||||
sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading faction change title pairs...");
|
||||
sObjectMgr->LoadFactionChangeTitles();
|
||||
|
||||
sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading GM tickets...");
|
||||
sTicketMgr->LoadTickets();
|
||||
|
||||
|
||||
@@ -420,7 +420,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
PREPARE_STATEMENT(CHAR_SEL_CHAR_GUID_NAME_BY_ACC, "SELECT guid, name FROM characters WHERE account = ?", CONNECTION_SYNCH);
|
||||
PREPARE_STATEMENT(CHAR_SEL_POOL_QUEST_SAVE, "SELECT quest_id FROM pool_quest_save WHERE pool_id = ?", CONNECTION_SYNCH);
|
||||
PREPARE_STATEMENT(CHAR_SEL_CHARACTER_AT_LOGIN, "SELECT at_login FROM characters WHERE guid = ?", CONNECTION_SYNCH);
|
||||
PREPARE_STATEMENT(CHAR_SEL_CHAR_CLASS_LVL_AT_LOGIN, "SELECT class, level, at_login FROM characters WHERE guid = ?", CONNECTION_SYNCH);
|
||||
PREPARE_STATEMENT(CHAR_SEL_CHAR_CLASS_LVL_AT_LOGIN, "SELECT class, level, at_login, knownTitles FROM characters WHERE guid = ?", CONNECTION_SYNCH);
|
||||
PREPARE_STATEMENT(CHAR_SEL_INSTANCE, "SELECT data, completedEncounters FROM instance WHERE map = ? AND id = ?", CONNECTION_SYNCH);
|
||||
PREPARE_STATEMENT(CHAR_SEL_PET_SPELL_LIST, "SELECT DISTINCT pet_spell.spell FROM pet_spell, character_pet WHERE character_pet.owner = ? AND character_pet.id = pet_spell.guid AND character_pet.id <> ?", CONNECTION_SYNCH);
|
||||
PREPARE_STATEMENT(CHAR_SEL_CHAR_PET, "SELECT id FROM character_pet WHERE owner = ? AND id <> ?", CONNECTION_SYNCH);
|
||||
@@ -499,6 +499,8 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
||||
PREPARE_STATEMENT(CHAR_UPD_CHAR_SPELL_FACTION_CHANGE, "UPDATE character_spell SET spell = ? where spell = ? AND guid = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_DEL_CHAR_REP_BY_FACTION, "DELETE FROM character_reputation WHERE faction = ? AND guid = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_UPD_CHAR_REP_FACTION_CHANGE, "UPDATE character_reputation SET faction = ? where faction = ? AND guid = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_UPD_CHAR_TITLES_FACTION_CHANGE, "UPDATE characters SET knownTitles = ? WHERE guid = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_RES_CHAR_TITLES_FACTION_CHANGE, "UPDATE characters SET chosenTitle = 0 WHERE guid = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_DEL_CHAR_SPELL_COOLDOWN, "DELETE FROM character_spell_cooldown WHERE guid = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_DEL_CHARACTER, "DELETE FROM characters WHERE guid = ?", CONNECTION_ASYNC);
|
||||
PREPARE_STATEMENT(CHAR_DEL_CHAR_ACTION, "DELETE FROM character_action WHERE guid = ?", CONNECTION_ASYNC);
|
||||
|
||||
@@ -462,6 +462,8 @@ enum CharacterDatabaseStatements
|
||||
CHAR_UPD_CHAR_SPELL_FACTION_CHANGE,
|
||||
CHAR_DEL_CHAR_REP_BY_FACTION,
|
||||
CHAR_UPD_CHAR_REP_FACTION_CHANGE,
|
||||
CHAR_UPD_CHAR_TITLES_FACTION_CHANGE,
|
||||
CHAR_RES_CHAR_TITLES_FACTION_CHANGE,
|
||||
CHAR_DEL_CHAR_SPELL_COOLDOWN,
|
||||
CHAR_DEL_CHARACTER,
|
||||
CHAR_DEL_CHAR_ACTION,
|
||||
|
||||
Reference in New Issue
Block a user