forked from cmangos/mangos-tbc
/
Custom.cpp
262 lines (212 loc) · 7.05 KB
/
Custom.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "Custom.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Database/DatabaseEnv.h"
#include "World.h"
#include "Log.h"
#include "SocialMgr.h"
#include "GossipDef.h"
Custom::~Custom()
{
for (CachedSpellContainer::const_iterator itr = m_CachedSpellContainer.begin(); itr != m_CachedSpellContainer.end(); ++itr)
delete itr->second;
for (TalentContainer::const_iterator itr = m_TalentContainer.begin(); itr != m_TalentContainer.end(); ++itr)
delete *itr;
}
void World::SendWorldChat(ObjectGuid guid, std::string msg)
{
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
if (itr->second)
if (Player* pPlayer = itr->second->GetPlayer())
if (pPlayer->IsInWorld() && !pPlayer->GetSocial()->HasIgnore(guid) && pPlayer->WCHatOn())
pPlayer->BoxChat << msg << "\n";
}
void World::SendGMMessage(std::string msg)
{
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
if (itr->second)
if (Player* pPlayer = itr->second->GetPlayer())
if (pPlayer->IsInWorld() && pPlayer->GetSession()->GetSecurity() > SEC_PLAYER)
pPlayer->BothChat << msg << "\n";
}
SpellContainer Custom::GetSpellContainerByCreatureEntry(uint32 entry)
{
SpellContainer spellContainer;
if (TrainerSpellData const* spelldata = sObjectMgr.GetNpcTrainerSpells(entry))
for (TrainerSpellMap::const_iterator itr = spelldata->spellList.begin(); itr != spelldata->spellList.end(); ++itr)
spellContainer.push_back(itr->second);
const CreatureInfo* creature = sObjectMgr.GetCreatureTemplate(entry);
if (!creature)
return spellContainer;
uint32 trainertemplate = creature->trainerId;
if (trainertemplate)
if (TrainerSpellData const* spelldata2 = sObjectMgr.GetNpcTrainerTemplateSpells(trainertemplate))
for (TrainerSpellMap::const_iterator itr = spelldata2->spellList.begin(); itr != spelldata2->spellList.end(); ++itr)
spellContainer.push_back(itr->second);
return spellContainer;
}
SpellContainer* Custom::GetCachedSpellContainer(uint32 crval)
{
if (m_CachedSpellContainer.find(crval) != m_CachedSpellContainer.end())
return m_CachedSpellContainer[crval];
return NULL;
}
const std::string Custom::m_ClassColor[] =
{
"",
MSG_COLOR_WARRIOR,
MSG_COLOR_PALADIN,
MSG_COLOR_HUNTER,
MSG_COLOR_ROGUE,
MSG_COLOR_PRIEST,
"",
MSG_COLOR_SHAMAN,
MSG_COLOR_MAGE,
MSG_COLOR_WARLOCK,
"",
MSG_COLOR_DRUID
};
const std::string Custom::m_ItemColor[] =
{
MSG_COLOR_GREY,
MSG_COLOR_WHITE,
MSG_COLOR_GREEN,
MSG_COLOR_BLUE,
MSG_COLOR_PURPLE,
MSG_COLOR_ORANGE
};
const std::string Custom::m_SlotNames[] =
{
"Head",
"Neck",
"Shoulders",
"Shirt",
"Chest",
"Waist",
"Legs",
"Feet",
"Wrists",
"Hands",
"Ring 1",
"Ring 2",
"Trinket 1",
"Trinket 2",
"Back",
"Mainhand",
"Offhand",
"Ranged",
"Tabard"
};
std::string Custom::ChatNameWrapper(std::string cName)
{
std::ostringstream ss;
ss << MSG_COLOR_WHITE << "[" << MSG_COLOR_MAGENTA << cName << MSG_COLOR_WHITE << "]:";
return ss.str().c_str();
}
void Custom::LoadFakePlayerBytes()
{
uint32 count = 0;
QueryResult* result = WorldDatabase.PQuery("SELECT race, maleBytes, maleBytes2, femaleBytes, femaleBytes2 FROM fakeplayerbytes");
if (result)
{
do
{
Field* fields = result->Fetch();
FakePlayerBytes bytes;
uint8 race = fields[0].GetUInt8();
bytes.PlayerBytes[GENDER_MALE] = fields[1].GetUInt32();
bytes.PlayerBytes2[GENDER_MALE] = fields[2].GetUInt32();
bytes.PlayerBytes[GENDER_FEMALE] = fields[3].GetUInt32();
bytes.PlayerBytes[GENDER_FEMALE] = fields[4].GetUInt32();
m_FakePlayerBytesContainer.insert(std::make_pair(race, bytes));
if (race && bytes.PlayerBytes[GENDER_MALE] && bytes.PlayerBytes2[GENDER_MALE] &&
bytes.PlayerBytes[GENDER_FEMALE] && bytes.PlayerBytes[GENDER_FEMALE])
++count;
}
while (result->NextRow());
}
if (sWorld.getConfig(CONFIG_BOOL_CFBG_ENABLED) && (count < 10 || !result))
{
const char* message = "There was something wrong with loading fakeplayerbytes for crossfaction battlegrounds!";
sLog.outError(message);
sLog.outErrorDb(message);
std::exit(EXIT_FAILURE);
}
}
uint8 Custom::PickFakeRace(uint8 pclass, Team team)
{
std::vector<uint8> playableRaces;
for (uint8 i = RACE_HUMAN; i <= RACE_DRAENEI; i++)
{
if (i == RACE_GOBLIN)
continue;
PlayerInfo const* info = sObjectMgr.GetPlayerInfo(i, pclass);
if (!info)
continue;
if (Player::TeamForRace(i) == team)
continue;
playableRaces.push_back(i);
}
return playableRaces[urand(0, playableRaces.size() - 1)];
}
bool ChatHandler::HandleWToggleCommand(char* /*args*/)
{
m_session->GetPlayer()->ToggleWChat();
PSendSysMessage("%s World chat is now %sabled", sCustom.ChatNameWrapper("World Chat").c_str(), m_session->GetPlayer()->WCHatOn() ? "en" : "dis");
return true;
}
bool ChatHandler::HandleWChatCommand(char* args)
{
if (!*args)
return false;
if (m_session->GetPlayer()->WCHatOn())
m_session->GetPlayer()->SendWorldChatMsg(args);
else
PSendSysMessage("%s You have disabled the worldchat, please enable it to speak in it.", sCustom.ChatNameWrapper("World Chat").c_str());
return true;
}
void PlayerMenu::SendGossipMenu(std::string text, ObjectGuid objectGuid, uint32 textid)
{
WorldPacket data(SMSG_NPC_TEXT_UPDATE, 100); // guess size
data << textid; // can be < 0
for (uint32 i = 0; i < 8; ++i)
{
data << float(0);
data << text;
data << text;
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
}
GetMenuSession()->SendPacket(&data);
SendGossipMenu(textid, objectGuid);
}
void Custom::LoadTalentContainer()
{
for (TalentContainer::const_iterator itr = m_TalentContainer.begin(); itr != m_TalentContainer.end(); ++itr)
delete *itr;
m_TalentContainer.clear();
uint32 count = 0;
QueryResult* result = WorldDatabase.PQuery("SELECT class, spec, id, rank FROM talenttemplates");
if (result)
{
do
{
Field* fields = result->Fetch();
TalentLearning* pTalent = new TalentLearning;
pTalent->ClassId = fields[0].GetUInt8();
pTalent->SpecId = fields[1].GetUInt8();
pTalent->TalentId = fields[2].GetUInt32();
pTalent->TalentRank = fields[3].GetUInt8();
m_TalentContainer.push_back(pTalent);
++count;
}
while (result->NextRow());
delete result;
}
sLog.outString("Loaded %u talents", count);
}