Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
- index 96192b2..6125236 100644
- --- a/src/server/game/Achievements/AchievementMgr.cpp
- +++ b/src/server/game/Achievements/AchievementMgr.cpp
- @@ -526,7 +526,8 @@ void AchievementMgr<Player>::SaveToDB(SQLTransaction& charTrans, SQLTransaction&
- if (!m_completedAchievements.empty())
- {
- - bool needExecute = false;
- + bool needCharacterExecute = false;
- + bool needAccountExecute = false;
- std::ostringstream ssAccDel;
- std::ostringstream ssAccIns;
- @@ -543,38 +544,58 @@ void AchievementMgr<Player>::SaveToDB(SQLTransaction& charTrans, SQLTransaction&
- if (!completionData.changed)
- continue;
- + AchievementEntry const* ach = sAchievementMgr->GetAchievement(achievementId);
- + if (!ach)
- + continue;
- +
- + bool isAccountAchievement = ach->flags & ACHIEVEMENT_FLAG_ACCOUNT;
- bool const mustSaveForCharacter = completionData.completedByThisCharacter;
- - if (!needExecute)
- + if (!needAccountExecute)
- {
- - // First new/changed record prefix
- - ssAccDel << "DELETE FROM account_achievement WHERE account = " << accountId << " AND achievement IN (";
- - ssAccIns << "INSERT INTO account_achievement (account, first_guid, achievement, date) VALUES ";
- + if (isAccountAchievement)
- + {
- + // First new/changed record prefix
- + ssAccDel << "DELETE FROM account_achievement WHERE account = " << accountId << " AND achievement IN (";
- + ssAccIns << "INSERT INTO account_achievement (account, first_guid, achievement, date) VALUES ";
- + needAccountExecute = true;
- + }
- + }
- + else
- + {
- + if (isAccountAchievement)
- + {
- + // Next new/changed record prefix
- + ssAccDel << ',';
- + ssAccIns << ',';
- + }
- + }
- - if (mustSaveForCharacter)
- + if (!needCharacterExecute)
- + {
- + if (mustSaveForCharacter || !isAccountAchievement)
- {
- ssCharDel << "DELETE FROM character_achievement WHERE guid = " << guidLow << " AND achievement IN (";
- ssCharIns << "INSERT INTO character_achievement (guid, achievement) VALUES ";
- + needCharacterExecute = true;
- }
- - needExecute = true;
- }
- else
- {
- - // Next new/changed record prefix
- - ssAccDel << ',';
- - ssAccIns << ',';
- -
- - if (mustSaveForCharacter)
- + if (mustSaveForCharacter || !isAccountAchievement)
- {
- ssCharDel << ',';
- ssCharIns << ',';
- }
- }
- - // New/changed record data
- - ssAccDel << achievementId;
- - ssAccIns << '(' << accountId << ',' << completionData.first_guid << ',' << achievementId << ',' << completionData.date << ')';
- + if (isAccountAchievement)
- + {
- + // New/changed record data
- + ssAccDel << achievementId;
- + ssAccIns << '(' << accountId << ',' << completionData.first_guid << ',' << achievementId << ',' << completionData.date << ')';
- + }
- - if (mustSaveForCharacter)
- + if (mustSaveForCharacter || !isAccountAchievement)
- {
- ssCharDel << achievementId;
- ssCharIns << '(' << guidLow << ',' << achievementId << ')';
- @@ -584,13 +605,18 @@ void AchievementMgr<Player>::SaveToDB(SQLTransaction& charTrans, SQLTransaction&
- completionData.changed = false;
- }
- - if (needExecute)
- + if (needAccountExecute)
- {
- ssAccDel << ')';
- - ssCharDel << ')';
- authTrans->Append(ssAccDel.str().c_str());
- authTrans->Append(ssAccIns.str().c_str());
- + }
- +
- + if (needCharacterExecute)
- + {
- + ssCharDel << ')';
- +
- charTrans->Append(ssCharDel.str().c_str());
- charTrans->Append(ssCharIns.str().c_str());
- }
- @@ -901,9 +927,9 @@ void AchievementMgr<Player>::LoadFromDB(PreparedQueryResult achievementResult, P
- continue;
- // Achievement in character_achievement but not in account_achievement, there is a problem.
- - if (m_completedAchievements.find(achievementid) == m_completedAchievements.end())
- + if (m_completedAchievements.find(achievementid) == m_completedAchievements.end() && achievement->flags & ACHIEVEMENT_FLAG_ACCOUNT)
- {
- - TC_LOG_ERROR("achievement", "Achievement '%u' in character_achievement but not in account_achievement, there is a problem.", achievementid);
- + TC_LOG_ERROR("achievement", "Account-wide achievement '%u' in character_achievement but not in account_achievement, there is a problem.", achievementid);
- continue;
- }
Add Comment
Please, Sign In to add comment