Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions src/server/game/Achievements/AchievementMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,17 +504,13 @@ void AchievementMgr::Reset()
{
for (std::pair<uint32 const, CompletedAchievementData> const& completedAchievement : m_completedAchievements)
{
WorldPacket data(SMSG_ACHIEVEMENT_DELETED, 4);
data << uint32(completedAchievement.first);
m_player->SendDirectMessage(&data);
WorldPackets::Achievement::AchievementDeleted achievementDeleted;
achievementDeleted.AchievementID = completedAchievement.first;
m_player->SendDirectMessage(achievementDeleted.Write());
}

for (std::pair<uint32 const, CriteriaProgress> const& criteriaprogress : m_criteriaProgress)
{
WorldPacket data(SMSG_CRITERIA_DELETED, 4);
data << uint32(criteriaprogress.first);
m_player->SendDirectMessage(&data);
}
SendCriteriaProgressRemoved(criteriaprogress.first);

m_completedAchievements.clear();
m_achievementPoints = 0;
Expand Down Expand Up @@ -704,17 +700,16 @@ void AchievementMgr::SendAchievementEarned(AchievementEntry const* achievement)
uint32 team = GetPlayer()->GetTeam();

// broadcast realm first reached
WorldPacket data(SMSG_SERVER_FIRST_ACHIEVEMENT, GetPlayer()->GetName().size() + 1 + 8 + 4 + 4);
data << GetPlayer()->GetName();
data << GetPlayer()->GetGUID();
data << uint32(achievement->ID);

std::size_t linkTypePos = data.wpos();
data << uint32(1); // display name as clickable link in chat
sWorld->SendGlobalMessage(&data, nullptr, team);

data.put<uint32>(linkTypePos, 0); // display name as plain string in chat
sWorld->SendGlobalMessage(&data, nullptr, team == ALLIANCE ? HORDE : ALLIANCE);
WorldPackets::Achievement::BroadcastAchievement serverFirstAchievement;
serverFirstAchievement.Name = m_player->GetName();
serverFirstAchievement.PlayerGUID = m_player->GetGUID();
serverFirstAchievement.AchievementID = achievement->ID;
serverFirstAchievement.DisplayLink = true; // display name as clickable link in chat
sWorld->SendGlobalMessage(serverFirstAchievement.Write(), nullptr, team);

serverFirstAchievement.Clear();
serverFirstAchievement.DisplayLink = false; // display name as plain string in chat
sWorld->SendGlobalMessage(serverFirstAchievement.Write(), nullptr, team == ALLIANCE ? HORDE : ALLIANCE);
}
// if player is in world he can tell his friends about new achievement
else if (GetPlayer()->IsInWorld())
Expand Down Expand Up @@ -759,6 +754,13 @@ void AchievementMgr::SendCriteriaUpdate(AchievementCriteriaEntry const* entry, C
GetPlayer()->SendDirectMessage(criteriaUpdate.Write());
}

void AchievementMgr::SendCriteriaProgressRemoved(uint32 criteriaId) const
{
WorldPackets::Achievement::CriteriaDeleted criteriaDeleted;
criteriaDeleted.CriteriaID = criteriaId;
GetPlayer()->SendDirectMessage(criteriaDeleted.Write());
}

/**
* called at player login. The player might have fulfilled some achievements when the achievement system wasn't working yet
*/
Expand Down Expand Up @@ -1434,18 +1436,16 @@ void AchievementMgr::SetCriteriaProgress(AchievementCriteriaEntry const* entry,
SendCriteriaUpdate(entry, progress, timeElapsed, timedCompleted);
}

void AchievementMgr::RemoveCriteriaProgress(AchievementCriteriaEntry const* entry)
void AchievementMgr::RemoveCriteriaProgress(AchievementCriteriaEntry const* criteria)
{
if (!entry)
if (!criteria)
return;

CriteriaProgressMap::iterator criteriaProgress = m_criteriaProgress.find(entry->ID);
auto criteriaProgress = m_criteriaProgress.find(criteria->ID);
if (criteriaProgress == m_criteriaProgress.end())
return;

WorldPacket data(SMSG_CRITERIA_DELETED, 4);
data << uint32(entry->ID);
m_player->SendDirectMessage(&data);
SendCriteriaProgressRemoved(criteria->ID);

m_criteriaProgress.erase(criteriaProgress);
}
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Achievements/AchievementMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ class TC_GAME_API AchievementMgr
private:
void SendAchievementEarned(AchievementEntry const* achievement) const;
void SendCriteriaUpdate(AchievementCriteriaEntry const* entry, CriteriaProgress const* progress, uint32 timeElapsed, bool timedCompleted) const;
void SendCriteriaProgressRemoved(uint32 criteriaId) const;
CriteriaProgress* GetCriteriaProgress(AchievementCriteriaEntry const* entry);
void SetCriteriaProgress(AchievementCriteriaEntry const* entry, uint32 changeValue, ProgressType ptype = PROGRESS_SET);
void RemoveCriteriaProgress(AchievementCriteriaEntry const* entry);
void RemoveCriteriaProgress(AchievementCriteriaEntry const* criteria);
void CompletedCriteriaFor(AchievementEntry const* achievement);
bool IsCompletedCriteria(AchievementCriteriaEntry const* achievementCriteria, AchievementEntry const* achievement);
bool IsCompletedAchievement(AchievementEntry const* entry);
Expand Down
15 changes: 7 additions & 8 deletions src/server/game/DataStores/DBCStores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

typedef std::map<uint16, uint32> AreaFlagByAreaID;
typedef std::map<uint32, uint32> AreaFlagByMapID;

typedef std::map<std::pair<uint32, Difficulty>, MapDifficultyEntry const*> MapDifficultyMap;
typedef std::tuple<int16, int8, int32> WMOAreaTableKey;
typedef std::map<WMOAreaTableKey, WMOAreaTableEntry const*> WMOAreaInfoByTripple;

Expand Down Expand Up @@ -132,7 +132,7 @@ DBCStorage <MapEntry> sMapStore(MapEntryfmt);

// DBC used only for initialization sMapDifficultyMap at startup.
DBCStorage <MapDifficultyEntry> sMapDifficultyStore(MapDifficultyEntryfmt); // only for loading
MapDifficultyMap sMapDifficultyMap;
static MapDifficultyMap sMapDifficultyMap;

DBCStorage <MovieEntry> sMovieStore(MovieEntryfmt);

Expand Down Expand Up @@ -437,7 +437,7 @@ void LoadDBCStores(const std::string& dataPath)

// fill data
for (MapDifficultyEntry const* entry : sMapDifficultyStore)
sMapDifficultyMap[MAKE_PAIR32(entry->MapID, entry->Difficulty)] = MapDifficulty(entry->RaidDuration, entry->MaxPlayers, entry->Message[0] != '\0');
sMapDifficultyMap[{ entry->MapID, Difficulty(entry->Difficulty) }] = entry;

for (NamesProfanityEntry const* namesProfanity : sNamesProfanityStore)
{
Expand Down Expand Up @@ -799,16 +799,15 @@ void Map2ZoneCoordinates(float& x, float& y, uint32 zone)
std::swap(x, y); // client have map coords swapped
}

MapDifficulty const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
MapDifficultyEntry const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
{
MapDifficultyMap::const_iterator itr = sMapDifficultyMap.find(MAKE_PAIR32(mapId, difficulty));
return itr != sMapDifficultyMap.end() ? &itr->second : nullptr;
return Trinity::Containers::MapGetValuePtr(sMapDifficultyMap, { mapId, difficulty });
}

MapDifficulty const* GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
MapDifficultyEntry const* GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
{
uint32 tmpDiff = difficulty;
MapDifficulty const* mapDiff = GetMapDifficultyData(mapId, Difficulty(tmpDiff));
MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapId, Difficulty(tmpDiff));
if (!mapDiff)
{
if (tmpDiff > RAID_DIFFICULTY_25MAN_NORMAL) // heroic, downscale to normal
Expand Down
8 changes: 3 additions & 5 deletions src/server/game/DataStores/DBCStores.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ TC_GAME_API bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint
TC_GAME_API void Zone2MapCoordinates(float &x, float &y, uint32 zone);
TC_GAME_API void Map2ZoneCoordinates(float &x, float &y, uint32 zone);

typedef std::map<uint32/*pair32(map, diff)*/, MapDifficulty> MapDifficultyMap;
TC_GAME_API MapDifficulty const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty);
TC_GAME_API MapDifficulty const* GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty);
TC_GAME_API MapDifficultyEntry const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty);
TC_GAME_API MapDifficultyEntry const* GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty);

TC_GAME_API uint32 const* /*[MAX_TALENT_TABS]*/ GetTalentTabPages(uint8 cls);

Expand Down Expand Up @@ -157,8 +156,7 @@ TC_GAME_API extern DBCStorage <LiquidTypeEntry> sLiquidTypeStore;
TC_GAME_API extern DBCStorage <LockEntry> sLockStore;
TC_GAME_API extern DBCStorage <MailTemplateEntry> sMailTemplateStore;
TC_GAME_API extern DBCStorage <MapEntry> sMapStore;
//TC_GAME_API extern DBCStorage <MapDifficultyEntry> sMapDifficultyStore; -- use GetMapDifficultyData insteed
TC_GAME_API extern MapDifficultyMap sMapDifficultyMap;
TC_GAME_API extern DBCStorage <MapDifficultyEntry> sMapDifficultyStore;
TC_GAME_API extern DBCStorage <MovieEntry> sMovieStore;
TC_GAME_API extern DBCStorage <OverrideSpellDataEntry> sOverrideSpellDataStore;
TC_GAME_API extern DBCStorage <PowerDisplayEntry> sPowerDisplayStore;
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ void Creature::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
stmt->setUInt8(index++, spawnMask);
stmt->setUInt32(index++, GetPhaseMask());
stmt->setUInt32(index++, displayId);
stmt->setInt32(index++, int32(GetCurrentEquipmentId()));
stmt->setUInt8(index++, GetCurrentEquipmentId());
stmt->setFloat(index++, GetPositionX());
stmt->setFloat(index++, GetPositionY());
stmt->setFloat(index++, GetPositionZ());
Expand Down
40 changes: 20 additions & 20 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11626,29 +11626,29 @@ void Player::RemoveAmmo()
}

// Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case.
Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId, GuidSet const& allowedLooters)
Item* Player::StoreNewItem(ItemPosCountVec const& pos, uint32 itemId, bool update, int32 randomPropertyId /*= 0*/, GuidSet const& allowedLooters /*= GuidSet()*/)
{
uint32 count = 0;
for (ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
for (ItemPosCountVec::const_iterator itr = pos.begin(); itr != pos.end(); ++itr)
count += itr->count;

Item* pItem = Item::CreateItem(item, count, this);
if (pItem)
Item* item = Item::CreateItem(itemId, count, this);
if (item)
{
if (randomPropertyId)
pItem->SetItemRandomProperties(randomPropertyId);
item->SetItemRandomProperties(randomPropertyId);

pItem = StoreItem(dest, pItem, update);
item = StoreItem(pos, item, update);

ItemAddedQuestCheck(item, count);
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, item, count);
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM, item, count);
ItemAddedQuestCheck(itemId, count);
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, itemId, count);
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM, itemId, count);

if (allowedLooters.size() > 1 && pItem->GetTemplate()->GetMaxStackSize() == 1 && pItem->IsSoulBound())
if (allowedLooters.size() > 1 && item->GetTemplate()->GetMaxStackSize() == 1 && item->IsSoulBound())
{
pItem->SetSoulboundTradeable(allowedLooters);
pItem->SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, GetTotalPlayedTime());
AddTradeableItem(pItem);
item->SetSoulboundTradeable(allowedLooters);
item->SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, GetTotalPlayedTime());
AddTradeableItem(item);

// save data
std::ostringstream ss;
Expand All @@ -11658,13 +11658,13 @@ Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update
ss << ' ' << itr->GetCounter();

CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEM_BOP_TRADE);
stmt->setUInt32(0, pItem->GetGUID().GetCounter());
stmt->setUInt32(0, item->GetGUID().GetCounter());
stmt->setString(1, ss.str());
CharacterDatabase.Execute(stmt);
}
Transmogrification::instance().AddToCollection(this, pItem);
Transmogrification::instance().AddToCollection(this, item);
}
return pItem;
return item;
}

Item* Player::StoreItem(ItemPosCountVec const& dest, Item* pItem, bool update)
Expand Down Expand Up @@ -18657,7 +18657,7 @@ void Player::_LoadBoundInstances(PreparedQueryResult result)
}
else
{
MapDifficulty const* mapDiff = GetMapDifficultyData(mapId, Difficulty(difficulty));
MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapId, Difficulty(difficulty));
if (!mapDiff)
{
TC_LOG_ERROR("entities.player", "Player::_LoadBoundInstances: player '{}' ({}) has bind to not existed difficulty {} instance for map {} ({})",
Expand Down Expand Up @@ -18695,7 +18695,7 @@ void Player::_LoadBoundInstances(PreparedQueryResult result)
InstancePlayerBind* Player::GetBoundInstance(uint32 mapid, Difficulty difficulty, bool withExpired)
{
// some instances only have one difficulty
MapDifficulty const* mapDiff = GetDownscaledMapDifficultyData(mapid, difficulty);
MapDifficultyEntry const* mapDiff = GetDownscaledMapDifficultyData(mapid, difficulty);
if (!mapDiff)
return nullptr;

Expand Down Expand Up @@ -18966,14 +18966,14 @@ bool Player::Satisfy(AccessRequirement const* ar, uint32 target_map, bool report
missingAchievement = ar->achievement;

Difficulty target_difficulty = group ? group->GetDifficultyID(mapEntry) : GetDifficultyID(mapEntry);
MapDifficulty const* mapDiff = GetDownscaledMapDifficultyData(target_map, target_difficulty);
MapDifficultyEntry const* mapDiff = GetDownscaledMapDifficultyData(target_map, target_difficulty);
if (LevelMin || LevelMax || missingItem || missingQuest || missingAchievement)
{
if (report)
{
if (missingQuest && !ar->questFailedText.empty())
ChatHandler(GetSession()).PSendSysMessage("%s", ar->questFailedText.c_str());
else if (mapDiff->hasErrorMessage) // if (missingAchievement) covered by this case
else if (mapDiff->Message[sWorld->GetDefaultDbcLocale()][0] != '\0') // if (missingAchievement) covered by this case
SendTransferAborted(target_map, TRANSFER_ABORT_DIFFICULTY, target_difficulty);
else if (missingItem)
GetSession()->SendAreaTriggerMessage(GetSession()->GetTrinityString(LANG_LEVEL_MINREQUIRED_AND_ITEM), LevelMin, ASSERT_NOTNULL(sObjectMgr->GetItemTemplate(missingItem))->GetName(GetSession()->GetSessionDbLocaleIndex()).c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
InventoryResult CanUseItem(ItemTemplate const* pItem) const;
InventoryResult CanUseAmmo(uint32 item) const;
InventoryResult CanRollForItemInLFG(ItemTemplate const* item, WorldObject const* lootedObject) const;
Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId = 0, GuidSet const& allowedLooters = GuidSet());
Item* StoreNewItem(ItemPosCountVec const& pos, uint32 itemId, bool update, int32 randomPropertyId = 0, GuidSet const& allowedLooters = GuidSet());
Item* StoreItem(ItemPosCountVec const& pos, Item* pItem, bool update);
Item* EquipNewItem(uint16 pos, uint32 item, bool update);
Item* EquipItem(uint16 pos, Item* pItem, bool update);
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Handlers/MovementHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ void WorldSession::HandleMoveWorldportAck()
{
// check if this instance has a reset time and send it to player if so
Difficulty diff = newMap->GetDifficultyID();
if (MapDifficulty const* mapDiff = GetMapDifficultyData(mEntry->ID, diff))
if (MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mEntry->ID, diff))
{
if (mapDiff->resetTime)
if (mapDiff->RaidDuration)
{
if (time_t timeReset = sInstanceSaveMgr->GetResetTimeFor(mEntry->ID, diff))
{
Expand Down
22 changes: 10 additions & 12 deletions src/server/game/Instances/InstanceSaveMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ void InstanceSaveManager::LoadResetTimes()
Difficulty difficulty = Difficulty(fields[1].GetUInt8());
uint64 oldresettime = fields[2].GetUInt64();

MapDifficulty const* mapDiff = GetMapDifficultyData(mapid, difficulty);
MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapid, difficulty);
if (!mapDiff)
{
TC_LOG_ERROR("misc", "InstanceSaveManager::LoadResetTimes: invalid mapid({})/difficulty({}) pair in instance_reset!", mapid, static_cast<uint32>(difficulty));
Expand Down Expand Up @@ -384,17 +384,15 @@ void InstanceSaveManager::LoadResetTimes()

// calculate new global reset times for expired instances and those that have never been reset yet
// add the global reset times to the priority queue
for (MapDifficultyMap::const_iterator itr = sMapDifficultyMap.begin(); itr != sMapDifficultyMap.end(); ++itr)
for (MapDifficultyEntry const* mapDiff : sMapDifficultyStore)
{
uint32 map_diff_pair = itr->first;
uint32 mapid = PAIR32_LOPART(map_diff_pair);
Difficulty difficulty = Difficulty(PAIR32_HIPART(map_diff_pair));
MapDifficulty const* mapDiff = &itr->second;
if (!mapDiff->resetTime)
uint32 mapid = mapDiff->MapID;
Difficulty difficulty = Difficulty(mapDiff->Difficulty);
if (!mapDiff->RaidDuration)
continue;

// the reset_delay must be at least one day
uint32 period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY));
uint32 period = uint32(((mapDiff->RaidDuration * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY));
if (period < DAY)
period = DAY;

Expand Down Expand Up @@ -435,23 +433,23 @@ void InstanceSaveManager::LoadResetTimes()

ScheduleReset(true, t - ResetTimeDelay[type-1], InstResetEvent(type, mapid, difficulty, 0));

ResetTimeMapDiffInstancesBounds range = mapDiffResetInstances.equal_range(map_diff_pair);
ResetTimeMapDiffInstancesBounds range = mapDiffResetInstances.equal_range(MAKE_PAIR32(mapid, difficulty));
for (; range.first != range.second; ++range.first)
ScheduleReset(true, t - ResetTimeDelay[type-1], InstResetEvent(type, mapid, difficulty, range.first->second));
}
}

time_t InstanceSaveManager::GetSubsequentResetTime(uint32 mapid, Difficulty difficulty, time_t resetTime) const
{
MapDifficulty const* mapDiff = GetMapDifficultyData(mapid, difficulty);
if (!mapDiff || !mapDiff->resetTime)
MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapid, difficulty);
if (!mapDiff || !mapDiff->RaidDuration)
{
TC_LOG_ERROR("misc", "InstanceSaveManager::GetSubsequentResetTime: not valid difficulty or no reset delay for map {}", mapid);
return 0;
}

time_t resetHour = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR);
time_t period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY));
time_t period = uint32(((mapDiff->RaidDuration * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY));
if (period < DAY)
period = DAY;

Expand Down
Loading
Loading