-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnpc_teleport.cpp
More file actions
258 lines (211 loc) · 7.88 KB
/
npc_teleport.cpp
File metadata and controls
258 lines (211 loc) · 7.88 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
* Copyright (C) 20??-2008 Wilibald09
* Copyright (C) 2011-2015 ArkCORE <http://www.arkania.net/>
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "sc_npc_teleport.h"
#include <sstream>
#define GOSSIP_SHOW_DEST 1000
#define GOSSIP_TELEPORT 1001
#define GOSSIP_NEXT_PAGEC 1002
#define GOSSIP_PREV_PAGEC 1003
#define GOSSIP_NEXT_PAGED 1004
#define GOSSIP_PREV_PAGED 1005
#define GOSSIP_MAIN_MENU 1006
#define SPELL_ID_PASSIVE_RESURRECTION_SICKNESS 15007
#define SPELL_VISUAL_TELEPORT 35517
#define NB_ITEM_PAGE 15
#define MSG_CAT 100000
#define MSG_DEST 100001
#define NEXT_PAGE "-> [Next Page]"
#define PREV_PAGE "<- [Previous Page]"
#define MAIN_MENU "<= [Main Menu]"
using namespace nsNpcTel;
namespace
{
Page PageC, PageD;
Page Cat;
// Conversion function int->string
std::string ConvertStr(const int64 &val)
{
std::ostringstream ostr;
ostr << val;
return ostr.str();
}
// Conversion function intMoney->stringMoney
std::string ConvertMoney(const uint32 &Money)
{
std::string Str(ConvertStr(Money));
uint32 SizeStr = Str.length();
if (SizeStr > 4)
Str = Str.insert(Str.length()-4, "g");
if (SizeStr > 2)
Str = Str.insert(Str.length()-2, "s");
Str += "c";
return Str;
}
// Teleport Player
void Teleport(Player * const player, const uint16 &map,
const float &X, const float &Y, const float &Z, const float &orient)
{
player->CastSpell(player, SPELL_VISUAL_TELEPORT, true);
player->TeleportTo(map, X, Y, Z, orient);
}
// Display categories
void AffichCat(Player * const player, Creature * const creature)
{
uint8 loc = player->GetSession()->GetSessionDbcLocale();
if (PageC[player] > 0)
AddGossipItemFor(player, 7, PREV_PAGE, GOSSIP_PREV_PAGEC, 0);
VCatDest_t i (PageC[player] * NB_ITEM_PAGE);
for ( ; i < TabCatDest.size() && i < (NB_ITEM_PAGE * (PageC[player] + 1)); ++i)
{
if (TabCatDest[i].IsAllowedToTeleport(player))
AddGossipItemFor(player, 3, TabCatDest[i].GetName(loc, player->IsGameMaster()).c_str(), GOSSIP_SHOW_DEST, i); //book categorie
}
if (i < TabCatDest.size())
AddGossipItemFor(player, 7, NEXT_PAGE, GOSSIP_NEXT_PAGEC, 0);
SendGossipMenuFor(player, MSG_CAT, creature);
}
// Display destination categories
void AffichDest(Player * const player, Creature * const creature)
{
uint8 loc = player->GetSession()->GetSessionDbcLocale();
if (PageD[player] > 0)
AddGossipItemFor(player,7, PREV_PAGE, GOSSIP_PREV_PAGED, 0);
CatDest::VDest_t i (PageD[player] * NB_ITEM_PAGE);
for ( ; i < TabCatDest[Cat[player]].size() && i < (NB_ITEM_PAGE * (PageD[player] + 1)); ++i)
{
std::string icon = TabCatDest[Cat[player]].GetDest(i).m_icon;
std::string size = TabCatDest[Cat[player]].GetDest(i).m_size;
std::string name = TabCatDest[Cat[player]].GetDest(i).m_name[loc];
if (name.length() == 0)
name = TabCatDest[Cat[player]].GetDest(i).m_name[0];
name = "|TInterface/ICONS/"+icon+":"+size+":"+size+"|t "+name;
AddGossipItemFor(player, 2, name.c_str(), GOSSIP_TELEPORT, i); //taxi destination
}
if (i < TabCatDest[Cat[player]].size())
AddGossipItemFor(player, 7, NEXT_PAGE, GOSSIP_NEXT_PAGED, 0);
if (CatDest::CountOfCategoryAllowedBy(player) > 1)
AddGossipItemFor(player, 7, MAIN_MENU, GOSSIP_MAIN_MENU, 0);
SendGossipMenuFor(player,MSG_DEST, creature);
}
// Verification before teleportation
void ActionTeleport(Player * const player, Creature * const creature, const uint32 &id)
{
Dest dest (TabCatDest[Cat[player]].GetDest(id));
if (player->getLevel() < dest.m_level && !player->IsGameMaster())
{
LocaleConstant loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
char const* text = sObjectMgr->GetTrinityString(8000, loc_idx);
std::string msg(text + (" " + ConvertStr(dest.m_level) + "."));
creature->Whisper(msg.c_str(), LANG_UNIVERSAL, player);
return;
}
if (player->GetMoney() < dest.m_cost && !player->IsGameMaster())
{
LocaleConstant loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
char const* text = sObjectMgr->GetTrinityString(8001, loc_idx);
std::string msg(text + (" " + ConvertMoney(dest.m_cost) + "."));
creature->Whisper(msg.c_str(), LANG_UNIVERSAL, player);
return;
}
if (!player->IsGameMaster() && dest.m_cost)
player->ModifyMoney(-1 * dest.m_cost);
Teleport(player, dest.m_map, dest.m_X, dest.m_Y, dest.m_Z, dest.m_orient);
}
}
class npc_teleport_gossip : public CreatureScript
{
public:
npc_teleport_gossip() : CreatureScript("npc_teleport") {}
bool OnGossipHello(Player *player, Creature *creature)
{
PageC(player) = PageD(player) = Cat(player) = 0;
if(player->IsInCombat())
{
CloseGossipMenuFor(player);
LocaleConstant loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
char const* text = sObjectMgr->GetTrinityString(8002, loc_idx);
creature->Whisper(text, LANG_UNIVERSAL, player);
return true;
}
AffichCat(player, creature);
return true;
}
bool OnGossipSelect(Player *player, Creature *creature, uint32 sender, uint32 param)
{
player->PlayerTalkClass->ClearMenus();
switch(sender)
{
// Display destinations
case GOSSIP_SHOW_DEST:
Cat(player) = param;
AffichDest(player, creature);
break;
// Previous categories page
case GOSSIP_PREV_PAGEC:
--PageC(player);
AffichCat(player, creature);
break;
// Next page categories
case GOSSIP_NEXT_PAGEC:
++PageC(player);
AffichCat(player, creature);
break;
// Previous destinations page
case GOSSIP_PREV_PAGED:
--PageD(player);
AffichDest(player, creature);
break;
// Next destination page
case GOSSIP_NEXT_PAGED:
++PageD(player);
AffichDest(player, creature);
break;
// Display main menu
case GOSSIP_MAIN_MENU:
OnGossipHello(player, creature);
break;
// Teleportation
case GOSSIP_TELEPORT:
CloseGossipMenuFor(player);
if(player->HasAura(SPELL_ID_PASSIVE_RESURRECTION_SICKNESS)) {
creature->CastSpell(player,38588,false); // Healing effect
player->RemoveAurasDueToSpell(SPELL_ID_PASSIVE_RESURRECTION_SICKNESS);
}
ActionTeleport(player, creature, param);
break;
}
return true;
}
};
class npc_teleport_load : public WorldScript
{
public:
npc_teleport_load() : WorldScript("npc_teleport") {}
void OnStartup() override
{
LoadNpcTele();
}
};
void AddSC_npc_teleport()
{
new npc_teleport_gossip;
new npc_teleport_load;
}
// End of TeleNPC2