fix(Core/Achivement): Implement ACHIEVEMENT_FLAG_AVERAGE (#17263)
This commit is contained in:
@@ -71,7 +71,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
|
|||||||
"resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, instance_mode_mask, "
|
"resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, instance_mode_mask, "
|
||||||
"arenaPoints, totalHonorPoints, todayHonorPoints, yesterdayHonorPoints, totalKills, todayKills, yesterdayKills, chosenTitle, knownCurrencies, watchedFaction, drunk, "
|
"arenaPoints, totalHonorPoints, todayHonorPoints, yesterdayHonorPoints, totalKills, todayKills, yesterdayKills, chosenTitle, knownCurrencies, watchedFaction, drunk, "
|
||||||
"health, power1, power2, power3, power4, power5, power6, power7, instance_id, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, ammoId, "
|
"health, power1, power2, power3, power4, power5, power6, power7, instance_id, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, ammoId, "
|
||||||
"knownTitles, actionBars, grantableLevels, innTriggerId, extraBonusTalentCount FROM characters WHERE guid = ?", CONNECTION_ASYNC);
|
"knownTitles, actionBars, grantableLevels, innTriggerId, extraBonusTalentCount, UNIX_TIMESTAMP(creation_date) FROM characters WHERE guid = ?", CONNECTION_ASYNC);
|
||||||
|
|
||||||
PrepareStatement(CHAR_SEL_CHARACTER_AURAS, "SELECT casterGuid, itemGuid, spell, effectMask, recalculateMask, stackCount, amount0, amount1, amount2, "
|
PrepareStatement(CHAR_SEL_CHARACTER_AURAS, "SELECT casterGuid, itemGuid, spell, effectMask, recalculateMask, stackCount, amount0, amount1, amount2, "
|
||||||
"base_amount0, base_amount1, base_amount2, maxDuration, remainTime, remainCharges FROM character_aura WHERE guid = ?", CONNECTION_ASYNC);
|
"base_amount0, base_amount1, base_amount2, maxDuration, remainTime, remainCharges FROM character_aura WHERE guid = ?", CONNECTION_ASYNC);
|
||||||
|
|||||||
@@ -758,7 +758,12 @@ void AchievementMgr::SendCriteriaUpdate(AchievementCriteriaEntry const* entry, C
|
|||||||
data << uint32(timedCompleted ? 0 : 1); // 1 is for keeping the counter at 0 in client
|
data << uint32(timedCompleted ? 0 : 1); // 1 is for keeping the counter at 0 in client
|
||||||
data.AppendPackedTime(progress->date);
|
data.AppendPackedTime(progress->date);
|
||||||
data << uint32(timeElapsed); // time elapsed in seconds
|
data << uint32(timeElapsed); // time elapsed in seconds
|
||||||
data << uint32(0); // unk
|
|
||||||
|
if (sAchievementMgr->IsAverageCriteria(entry))
|
||||||
|
data << uint32(GameTime::GetGameTime().count() - GetPlayer()->GetCreationTime().count()); // for average achievements
|
||||||
|
else
|
||||||
|
data << uint32(timeElapsed); // time elapsed in seconds
|
||||||
|
|
||||||
GetPlayer()->SendDirectMessage(&data);
|
GetPlayer()->SendDirectMessage(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2356,7 +2361,11 @@ void AchievementMgr::BuildAllDataPacket(WorldPacket* data) const
|
|||||||
*data << uint32(0); /// @todo: This should be 1 if it is a failed timed criteria
|
*data << uint32(0); /// @todo: This should be 1 if it is a failed timed criteria
|
||||||
data->AppendPackedTime(iter->second.date);
|
data->AppendPackedTime(iter->second.date);
|
||||||
*data << uint32(now - iter->second.date);
|
*data << uint32(now - iter->second.date);
|
||||||
*data << uint32(now - iter->second.date);
|
|
||||||
|
if (sAchievementMgr->IsAverageCriteria(sAchievementCriteriaStore.LookupEntry(iter->first)))
|
||||||
|
*data << uint32(now - GetPlayer()->GetCreationTime().count()); // for average achievements
|
||||||
|
else
|
||||||
|
*data << uint32(now - iter->second.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
*data << int32(-1);
|
*data << int32(-1);
|
||||||
@@ -2445,6 +2454,19 @@ bool AchievementGlobalMgr::IsStatisticAchievement(AchievementEntry const* achiev
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AchievementGlobalMgr::IsAverageCriteria(AchievementCriteriaEntry const* criteria) const
|
||||||
|
{
|
||||||
|
if ((sAchievementStore.LookupEntry(criteria->referredAchievement))->flags & ACHIEVEMENT_FLAG_AVERAGE)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (AchievementEntryList const* achRefList = GetAchievementByReferencedId(criteria->referredAchievement))
|
||||||
|
for (AchievementEntryList::const_iterator itr = achRefList->begin(); itr != achRefList->end(); ++itr)
|
||||||
|
if ((*itr)->flags & ACHIEVEMENT_FLAG_AVERAGE)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool AchievementGlobalMgr::IsRealmCompleted(AchievementEntry const* achievement) const
|
bool AchievementGlobalMgr::IsRealmCompleted(AchievementEntry const* achievement) const
|
||||||
{
|
{
|
||||||
auto itr = _allCompletedAchievements.find(achievement->ID);
|
auto itr = _allCompletedAchievements.find(achievement->ID);
|
||||||
|
|||||||
@@ -330,6 +330,7 @@ public:
|
|||||||
|
|
||||||
bool IsStatisticCriteria(AchievementCriteriaEntry const* achievementCriteria) const;
|
bool IsStatisticCriteria(AchievementCriteriaEntry const* achievementCriteria) const;
|
||||||
bool IsStatisticAchievement(AchievementEntry const* achievement) const;
|
bool IsStatisticAchievement(AchievementEntry const* achievement) const;
|
||||||
|
bool IsAverageCriteria(AchievementCriteriaEntry const* criteria) const;
|
||||||
|
|
||||||
[[nodiscard]] AchievementCriteriaEntryList const* GetAchievementCriteriaByType(AchievementCriteriaTypes type) const
|
[[nodiscard]] AchievementCriteriaEntryList const* GetAchievementCriteriaByType(AchievementCriteriaTypes type) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -384,6 +384,8 @@ Player::Player(WorldSession* session): Unit(true), m_mover(this)
|
|||||||
|
|
||||||
_activeCheats = CHEAT_NONE;
|
_activeCheats = CHEAT_NONE;
|
||||||
|
|
||||||
|
m_creationTime = 0s;
|
||||||
|
|
||||||
_cinematicMgr = new CinematicMgr(this);
|
_cinematicMgr = new CinematicMgr(this);
|
||||||
|
|
||||||
m_achievementMgr = new AchievementMgr(this);
|
m_achievementMgr = new AchievementMgr(this);
|
||||||
|
|||||||
@@ -2495,6 +2495,9 @@ public:
|
|||||||
void CompletedAchievement(AchievementEntry const* entry);
|
void CompletedAchievement(AchievementEntry const* entry);
|
||||||
[[nodiscard]] AchievementMgr* GetAchievementMgr() const { return m_achievementMgr; }
|
[[nodiscard]] AchievementMgr* GetAchievementMgr() const { return m_achievementMgr; }
|
||||||
|
|
||||||
|
void SetCreationTime(Seconds creationTime) { m_creationTime = creationTime; }
|
||||||
|
[[nodiscard]] Seconds GetCreationTime() const { return m_creationTime; }
|
||||||
|
|
||||||
[[nodiscard]] bool HasTitle(uint32 bitIndex) const;
|
[[nodiscard]] bool HasTitle(uint32 bitIndex) const;
|
||||||
bool HasTitle(CharTitlesEntry const* title) const { return HasTitle(title->bit_index); }
|
bool HasTitle(CharTitlesEntry const* title) const { return HasTitle(title->bit_index); }
|
||||||
void SetTitle(CharTitlesEntry const* title, bool lost = false);
|
void SetTitle(CharTitlesEntry const* title, bool lost = false);
|
||||||
@@ -2949,6 +2952,8 @@ private:
|
|||||||
bool _wasOutdoor;
|
bool _wasOutdoor;
|
||||||
|
|
||||||
PlayerSettingMap m_charSettingsMap;
|
PlayerSettingMap m_charSettingsMap;
|
||||||
|
|
||||||
|
Seconds m_creationTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddItemsSetItem(Player* player, Item* item);
|
void AddItemsSetItem(Player* player, Item* item);
|
||||||
|
|||||||
@@ -4948,8 +4948,8 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
|||||||
//"arenaPoints, totalHonorPoints, todayHonorPoints, yesterdayHonorPoints, totalKills, todayKills, yesterdayKills, chosenTitle, knownCurrencies, watchedFaction, drunk, "
|
//"arenaPoints, totalHonorPoints, todayHonorPoints, yesterdayHonorPoints, totalKills, todayKills, yesterdayKills, chosenTitle, knownCurrencies, watchedFaction, drunk, "
|
||||||
// 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
||||||
//"health, power1, power2, power3, power4, power5, power6, power7, instance_id, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, ammoId, knownTitles,
|
//"health, power1, power2, power3, power4, power5, power6, power7, instance_id, talentGroupsCount, activeTalentGroup, exploredZones, equipmentCache, ammoId, knownTitles,
|
||||||
// 70 71 72 73
|
// 70 71 72 73 74
|
||||||
//"actionBars, grantableLevels, innTriggerId, extraBonusTalentCount FROM characters WHERE guid = '{}'", guid);
|
//"actionBars, grantableLevels, innTriggerId, extraBonusTalentCount, UNIX_TIMESTAMP(creation_date) FROM characters WHERE guid = '{}'", guid);
|
||||||
PreparedQueryResult result = holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_FROM);
|
PreparedQueryResult result = holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_FROM);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
@@ -5026,6 +5026,9 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
|
|||||||
SetObjectScale(1.0f);
|
SetObjectScale(1.0f);
|
||||||
SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f);
|
SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f);
|
||||||
|
|
||||||
|
// load character creation date, relevant for achievements of type average
|
||||||
|
SetCreationTime(fields[74].Get<Seconds>());
|
||||||
|
|
||||||
// load achievements before anything else to prevent multiple gains for the same achievement/criteria on every loading (as loading does call UpdateAchievementCriteria)
|
// load achievements before anything else to prevent multiple gains for the same achievement/criteria on every loading (as loading does call UpdateAchievementCriteria)
|
||||||
m_achievementMgr->LoadFromDB(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_ACHIEVEMENTS), holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_CRITERIA_PROGRESS));
|
m_achievementMgr->LoadFromDB(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_ACHIEVEMENTS), holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_CRITERIA_PROGRESS));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user