TrinityCore
InspectHandler.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WorldSession.h"
19#include "AchievementMgr.h"
20#include "AzeriteItem.h"
21#include "Guild.h"
22#include "GuildMgr.h"
23#include "InspectPackets.h"
24#include "Log.h"
25#include "ObjectAccessor.h"
26#include "Player.h"
27#include "World.h"
28
30{
32 if (!player)
33 {
34 TC_LOG_DEBUG("network", "WorldSession::HandleInspectOpcode: Target {} not found.", inspect.Target.ToString());
35 return;
36 }
37
38 TC_LOG_DEBUG("network", "WorldSession::HandleInspectOpcode: Target {}.", inspect.Target.ToString());
39
40 if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false))
41 return;
42
43 if (GetPlayer()->IsValidAttackTarget(player))
44 return;
45
47 inspectResult.DisplayInfo.Initialize(player);
48
49 if (GetPlayer()->CanBeGameMaster() || sWorld->getIntConfig(CONFIG_TALENTS_INSPECTING) + (GetPlayer()->GetEffectiveTeam() == player->GetEffectiveTeam()) > 1)
50 {
51 PlayerTalentMap const* talents = player->GetTalentMap(player->GetActiveTalentGroup());
52 for (PlayerTalentMap::value_type const& v : *talents)
53 if (v.second != PLAYERSPELL_REMOVED)
54 inspectResult.Talents.push_back(v.first);
55
56 PlayerPvpTalentMap const& pvpTalents = player->GetPvpTalentMap(player->GetActiveTalentGroup());
57 for (std::size_t i = 0; i < pvpTalents.size(); ++i)
58 inspectResult.PvpTalents[i] = pvpTalents[i];
59
60 inspectResult.TalentTraits.Level = player->GetLevel();
62 if (UF::TraitConfig const* traitConfig = player->GetTraitConfig(player->m_activePlayerData->ActiveCombatTraitConfigID))
63 inspectResult.TalentTraits.Config = WorldPackets::Traits::TraitConfig(*traitConfig);
64 }
65
66 if (Guild* guild = sGuildMgr->GetGuildById(player->GetGuildId()))
67 {
68 inspectResult.GuildData.emplace();
69 inspectResult.GuildData->GuildGUID = guild->GetGUID();
70 inspectResult.GuildData->NumGuildMembers = guild->GetMembersCount();
71 inspectResult.GuildData->AchievementPoints = guild->GetAchievementMgr().GetAchievementPoints();
72 }
73
75 if (AzeriteItem const* azeriteItem = heartOfAzeroth->ToAzeriteItem())
76 inspectResult.AzeriteLevel = azeriteItem->GetEffectiveLevel();
77
78 inspectResult.ItemLevel = int32(player->GetAverageItemLevel());
79 inspectResult.LifetimeMaxRank = player->m_activePlayerData->LifetimeMaxRank;
80 inspectResult.TodayHK = player->m_activePlayerData->TodayHonorableKills;
81 inspectResult.YesterdayHK = player->m_activePlayerData->YesterdayHonorableKills;
82 inspectResult.LifetimeHK = player->m_activePlayerData->LifetimeHonorableKills;
83 inspectResult.HonorLevel = player->m_playerData->HonorLevel;
84
85 SendPacket(inspectResult.Write());
86}
87
89{
90 Player* player = ObjectAccessor::GetPlayer(*_player, inspect.Guid);
91 if (!player)
92 {
93 TC_LOG_DEBUG("network", "WorldSession::HandleQueryInspectAchievements: [{}] inspected unknown Player [{}]", GetPlayer()->GetGUID().ToString(), inspect.Guid.ToString());
94 return;
95 }
96
97 TC_LOG_DEBUG("network", "WorldSession::HandleQueryInspectAchievements: [{}] inspected Player [{}]", GetPlayer()->GetGUID().ToString(), inspect.Guid.ToString());
98
99 if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false))
100 return;
101
102 if (GetPlayer()->IsValidAttackTarget(player))
103 return;
104
106}
constexpr uint32 ITEM_ID_HEART_OF_AZEROTH
Definition: AzeriteItem.h:23
int32_t int32
Definition: Define.h:138
#define sGuildMgr
Definition: GuildMgr.h:70
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
#define INSPECT_DISTANCE
Definition: ObjectDefines.h:26
std::array< uint32, MAX_PVP_TALENT_SLOTS > PlayerPvpTalentMap
Definition: Player.h:275
std::unordered_map< uint32, PlayerSpellState > PlayerTalentMap
Definition: Player.h:274
@ PLAYERSPELL_REMOVED
Definition: Player.h:189
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:491
Definition: Guild.h:329
Definition: Item.h:170
AzeriteItem * ToAzeriteItem()
Definition: Item.h:243
std::string ToString() const
Definition: ObjectGuid.cpp:554
ChrSpecialization GetPrimarySpecialization() const
Definition: Player.h:1841
UF::UpdateField< UF::PlayerData, 0, TYPEID_PLAYER > m_playerData
Definition: Player.h:2863
UF::TraitConfig const * GetTraitConfig(int32 configId) const
Definition: Player.cpp:28247
Item * GetItemByEntry(uint32 entry, ItemSearchLocation where=ItemSearchLocation::Default) const
Definition: Player.cpp:12589
void SendRespondInspectAchievements(Player *player) const
Definition: Player.cpp:26736
ObjectGuid::LowType GetGuildId() const
Definition: Player.h:1993
uint8 GetActiveTalentGroup() const
Definition: Player.h:1843
PlayerPvpTalentMap const & GetPvpTalentMap(uint8 spec) const
Definition: Player.h:1875
float GetAverageItemLevel() const
Definition: Player.cpp:29020
UF::UpdateField< UF::ActivePlayerData, 0, TYPEID_ACTIVE_PLAYER > m_activePlayerData
Definition: Player.h:2864
PlayerTalentMap const * GetTalentMap(uint8 spec) const
Definition: Player.h:1873
Team GetEffectiveTeam() const
Definition: Player.h:2239
uint8 GetLevel() const
Definition: Unit.h:746
PlayerModelDisplayInfo DisplayInfo
WorldPacket const * Write() override
std::array< uint16, MAX_PVP_TALENT_SLOTS > PvpTalents
Optional< InspectGuildData > GuildData
Player * GetPlayer() const
void HandleQueryInspectAchievements(WorldPackets::Inspect::QueryInspectAchievements &inspect)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
void HandleInspectOpcode(WorldPackets::Inspect::Inspect &inspect)
Player * _player
#define sWorld
Definition: World.h:931
@ CONFIG_TALENTS_INSPECTING
Definition: World.h:428
TC_GAME_API Player * GetPlayer(Map const *, ObjectGuid const &guid)
std::string ToString(Type &&val, Params &&... params)