forked from Nefertumm/mod-instance-reset
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathinstance_reset.cpp
More file actions
244 lines (218 loc) · 8 KB
/
instance_reset.cpp
File metadata and controls
244 lines (218 loc) · 8 KB
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
#include "instance_reset.h"
/*
* This method is used to override the npc_text
* Without resorting to the database, since it is a module.
* And we want to avoid adding information that is not blizzlike.
*/
void GossipSetText(Player* player, std::string message, uint32 textID)
{
WorldPacket data(SMSG_NPC_TEXT_UPDATE, 100);
data << textID;
for (uint8 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i)
{
data << float(0);
data << message;
data << message;
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
}
player->GetSession()->SendPacket(&data);
}
void InstanceResetAnnouncer::OnPlayerLogin(Player* player)
{
if (sConfigMgr->GetOption<bool>("instanceReset.Announcer", true))
{
std::string message = "";
switch (player->GetSession()->GetSessionDbLocaleIndex())
{
case LOCALE_enUS:
case LOCALE_koKR:
case LOCALE_frFR:
case LOCALE_deDE:
case LOCALE_zhCN:
case LOCALE_zhTW:
{
message = "This server is running the |cff4CFF00Instance Reset |rmodule.";
break;
}
case LOCALE_esES:
case LOCALE_esMX:
{
message = "Este servidor está ejecutando el módulo |cff4CFF00Instance reset|r";
break;
}
case LOCALE_ruRU:
{
message = "Этот сервер использует модуль |cff4CFF00Перезапуск подземелий|r.";
break;
}
default:
break;
}
ChatHandler(player->GetSession()).SendSysMessage(message);
}
}
bool InstanceReset::OnGossipHello(Player* player, Creature* creature)
{
ClearGossipMenuFor(player);
std::string gossipText = "";
std::string message = "";
switch (player->GetSession()->GetSessionDbLocaleIndex())
{
case LOCALE_enUS:
case LOCALE_koKR:
case LOCALE_frFR:
case LOCALE_deDE:
case LOCALE_zhCN:
case LOCALE_zhTW:
{
gossipText = "I would like to remove my instance saves.";
message = "Greetings $n. This is an npc that allows you to reset instance ids, allowing you to re-enter, without the need to wait for the reset time to expire. It was developed by the AzerothCore community.";
break;
}
case LOCALE_esES:
case LOCALE_esMX:
{
gossipText = "Me gustaría reiniciar mis ids de instancias.";
message = "Saludos $n. Este es un npc que te permite reiniciar los ids de las instancias, permitiéndote volver a entrar, sin la necesidad de esperar a que se cumpla el tiempo para el reinicio. Fue desarrollado por la comunidad de AzerothCore.";
break;
}
case LOCALE_ruRU:
{
gossipText = "Я бы хотел удалить мои сохраненные подземелья.";
message = "Приветствую, $n. Этот персонаж может удалить список посещенных подземелий, позволив Вам повторно их посетить не дожидаясь времени планового перезапуска. Разработан в AzerothCore community.";
break;
}
default:
break;
}
if (enable)
{
switch (transactionType)
{
case 0:
{
AddGossipItemFor(player, GOSSIP_ICON_CHAT, gossipText, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
break;
}
case 1:
{
if (player->HasItemCount(token, count, true))
AddGossipItemFor(player, GOSSIP_ICON_CHAT, gossipText, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
else
creature->Whisper("You do not have the required items or token.", LANG_UNIVERSAL, player);
break;
}
case 2:
{
if (player->GetMoney() >= money)
AddGossipItemFor(player, GOSSIP_ICON_CHAT, gossipText, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
else
creature->Whisper("You don't have enough money.", LANG_UNIVERSAL, player);
break;
}
case 3:
{
if ((player->HasItemCount(token, count, true)) && ((player->GetMoney() >= money)))
AddGossipItemFor(player, GOSSIP_ICON_CHAT, gossipText, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
else
creature->Whisper("The reset requires a token and money.", LANG_UNIVERSAL, player);
break;
}
default:
break;
}
}
GossipSetText(player, message, DEFAULT_GOSSIP_MESSAGE);
SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
return true;
}
bool InstanceReset::OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)
{
ClearGossipMenuFor(player);
uint32 diff = 2;
if (action == GOSSIP_ACTION_INFO_DEF + 1)
{
if (!(sConfigMgr->GetOption<bool>("instanceReset.NormalModeOnly", true)))
diff = MAX_DIFFICULTY;
for (uint8 i = 0; i < diff; ++i)
{
BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(player->GetGUID(), Difficulty(i));
for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end();)
{
if (itr->first != player->GetMapId())
{
sInstanceSaveMgr->PlayerUnbindInstance(player->GetGUID(), itr->first, Difficulty(i), true, player);
itr = m_boundInstances.begin();
}
else
++itr;
}
}
std::string creatureWhisper = "";
switch (player->GetSession()->GetSessionDbLocaleIndex())
{
case LOCALE_enUS:
case LOCALE_koKR:
case LOCALE_frFR:
case LOCALE_deDE:
case LOCALE_zhCN:
case LOCALE_zhTW:
{
creatureWhisper = "Your instances have been reset.";
break;
}
case LOCALE_esES:
case LOCALE_esMX:
{
creatureWhisper = "Sus instancias han sido restablecidas.";
break;
}
case LOCALE_ruRU:
{
creatureWhisper = "Ваши подземелья перезагружены.";
break;
}
default:
break;
}
creature->Whisper(creatureWhisper, LANG_UNIVERSAL, player);
switch (transactionType)
{
case 0: break;
case 1:
{
player->DestroyItemCount(token, count, true);
break;
}
case 2:
{
player->ModifyMoney(-money);
break;
}
case 3:
{
player->DestroyItemCount(token, count, true);
player->ModifyMoney(-money);
break;
}
default:
break;
}
CloseGossipMenuFor(player);
}
return true;
}
void InstanceResetWorldConfig::OnBeforeConfigLoad(bool /*reload*/)
{
enable = sConfigMgr->GetOption<bool>("instanceReset.Enable", true);
transactionType = sConfigMgr->GetOption<uint32>("instanceReset.TransactionType", 0);
token = sConfigMgr->GetOption<uint32>("instanceReset.TokenID", 49426);
count = sConfigMgr->GetOption<uint16>("instanceReset.TokenCount", 26);
money = sConfigMgr->GetOption<uint32>("instanceReset.MoneyCount", 10000000);
}