-
Notifications
You must be signed in to change notification settings - Fork 12
/
npc_arena1v1.cpp
356 lines (297 loc) · 13.5 KB
/
npc_arena1v1.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#include "ScriptMgr.h"
#include "ArenaTeamMgr.h"
#include "Common.h"
#include "DisableMgr.h"
#include "BattlegroundMgr.h"
#include "Battleground.h"
#include "ArenaTeam.h"
#include "Language.h"
#include "npc_arena1v1.h"
#include "World.h"
#include "Player.h"
#include "Chat.h"
#include "WorldSession.h"
#include "Log.h"
#include "ScriptedGossip.h"
#include "ScriptedCreature.h"
#include "CreatureAI.h"
#include "Config.h"
//#include "DatabaseEnv.h"
/*
// NPC DETAILS - WORLD DATABASE
uint64 NPC_Entry = 190001;
uint32 NPC_DisplayID = 21249;
std::string NPC_Name = "Arena 1v1";
std::string NPC_SubName = "";
uint8 NPC_MinLevel = 80;
uint8 NPC_MaxLevel = 80;
*/
class npc_1v1arena : public CreatureScript
{
public:
npc_1v1arena() : CreatureScript("npc_1v1arena") { }
struct npc_1v1arenaAI : public ScriptedAI
{
npc_1v1arenaAI(Creature* creature) : ScriptedAI(creature) { }
bool JoinQueueArena(Player* player, Creature* me, bool isRated)
{
if (!player || !me)
return false;
if (config_minLevel > player->getLevel())
return false;
ObjectGuid guid = player->GetGUID();
uint8 arenaslot = ArenaTeam::GetSlotByType(ARENA_TEAM_5v5);
uint8 arenatype = ARENA_TYPE_5v5;
uint32 arenaRating = 0;
uint32 matchmakerRating = 0;
// ignore if we already in BG or BG queue
if (player->InBattleground())
return false;
//check existance
Battleground* bg = sBattlegroundMgr->GetBattlegroundTemplate(BATTLEGROUND_AA);
if (!bg)
{
TC_LOG_ERROR("Arena", "Battleground: template bg (all arenas) not found");
return false;
}
if (DisableMgr::IsDisabledFor(DISABLE_TYPE_BATTLEGROUND, BATTLEGROUND_AA, NULL))
{
ChatHandler(player->GetSession()).PSendSysMessage(LANG_ARENA_DISABLED);
return false;
}
BattlegroundTypeId bgTypeId = bg->GetTypeID();
BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId(bgTypeId, arenatype);
PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketByLevel(bg->GetMapId(), player->getLevel());
if (!bracketEntry)
return false;
GroupJoinBattlegroundResult err = ERR_GROUP_JOIN_BATTLEGROUND_FAIL;
// check if already in queue
if (player->GetBattlegroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES)
//player is already in this queue
return false;
// check if has free queue slots
if (!player->HasFreeBattlegroundQueueId())
return false;
uint32 ateamId = 0;
if (isRated)
{
ateamId = player->GetArenaTeamId(arenaslot);
ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(ateamId);
if (!at)
{
player->GetSession()->SendNotInArenaTeamPacket(arenatype);
return false;
}
// get the team rating for queueing
arenaRating = at->GetRating();
matchmakerRating = arenaRating;
// the arenateam id must match for everyone in the group
if (arenaRating <= 0)
arenaRating = 1;
}
BattlegroundQueue &bgQueue = sBattlegroundMgr->GetBattlegroundQueue(bgQueueTypeId);
bg->SetRated(isRated);
GroupQueueInfo* ginfo = bgQueue.AddGroup(player, NULL, bgTypeId, bracketEntry, arenatype, isRated, false, arenaRating, matchmakerRating, ateamId);
uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, bracketEntry->GetBracketId());
uint32 queueSlot = player->AddBattlegroundQueueId(bgQueueTypeId);
WorldPacket data;
// send status packet (in queue)
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_WAIT_QUEUE, avgTime, 0, arenatype, 0);
player->GetSession()->SendPacket(&data);
sBattlegroundMgr->ScheduleQueueUpdate(matchmakerRating, arenatype, bgQueueTypeId, bgTypeId, bracketEntry->GetBracketId());
return true;
}
bool CreateArenateam(Player* player, Creature* me)
{
if (!player || !me)
return false;
uint8 slot = ArenaTeam::GetSlotByType(ARENA_TEAM_5v5);
if (slot >= MAX_ARENA_SLOT)
return false;
// Check if player is already in an arena team
if (player->GetArenaTeamId(slot))
{
player->GetSession()->SendArenaTeamCommandResult(ERR_ARENA_TEAM_CREATE_S, player->GetName(), "", ERR_ALREADY_IN_ARENA_TEAM);
return false;
}
// Teamname = playername
// if teamname exist, we have to choose another name (playername + number)
int i = 1;
std::stringstream teamName;
teamName << player->GetName();
do
{
if (sArenaTeamMgr->GetArenaTeamByName(teamName.str()) != NULL) // teamname exist, so choose another name
{
teamName.str(std::string());
teamName << player->GetName() << (i++);
}
else
break;
} while (i < 100); // should never happen
// Create arena team
ArenaTeam* arenaTeam = new ArenaTeam();
if (!arenaTeam->Create(player->GetGUID(), ARENA_TEAM_5v5, teamName.str(), 4283124816, 45, 4294242303, 5, 4294705149))
{
delete arenaTeam;
return false;
}
// Register arena team
sArenaTeamMgr->AddArenaTeam(arenaTeam);
arenaTeam->AddMember(player->GetGUID());
ChatHandler(player->GetSession()).SendSysMessage("|cffFF4500[1v1 Arena System]:|r Arenateam successfully created!");
return true;
}
bool GossipHello(Player* player) override
{
if (!player || !me)
return true;
if (config_Enable == false)
{
ChatHandler(player->GetSession()).SendSysMessage("|cffFF4500[1v1 Arena System]:|r 1v1 Arena is disabled!");
return true;
}
if (player->InBattlegroundQueueForBattlegroundQueueType(BATTLEGROUND_QUEUE_5v5))
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Leave queue 1v1 Arena", GOSSIP_SENDER_MAIN, 3, "Are you sure?", 0, false);
else
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Sign up 1v1 Arena (unrated)", GOSSIP_SENDER_MAIN, 20);
if (player->GetArenaTeamId(ArenaTeam::GetSlotByType(ARENA_TEAM_5v5)) == 0)
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Create new 1v1 Arenateam", GOSSIP_SENDER_MAIN, 1, "Create 1v1 arenateam?", config_Costs, false);
else
{
if (player->InBattlegroundQueueForBattlegroundQueueType(BATTLEGROUND_QUEUE_5v5) == false)
{
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Sign up 1v1 Arena (rated)", GOSSIP_SENDER_MAIN, 2);
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Disband arenateam", GOSSIP_SENDER_MAIN, 5, "Are you sure?", 0, false);
}
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Show statistics", GOSSIP_SENDER_MAIN, 4);
}
//player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Script Info", GOSSIP_SENDER_MAIN, 8);
SendGossipMenuFor(player, 68, me->GetGUID());
return true;
}
bool GossipSelect(Player* player, uint32 /*menuId*/, uint32 gossipListId) override
{
uint32 const sender = player->PlayerTalkClass->GetGossipOptionSender(gossipListId);
uint32 const action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
if (!player || !me)
return true;
ClearGossipMenuFor(player);
switch (action)
{
case 1: // Create new Arenateam
{
if (config_minLevel <= player->getLevel())
{
if (player->GetMoney() >= config_Costs && CreateArenateam(player, me))
player->ModifyMoney(config_Costs * -1);
}
else
{
ChatHandler(player->GetSession()).PSendSysMessage("|cffFF4500[1v1 Arena System]:|r You need level %u to create a 1v1 arenateam.", config_minLevel);
CloseGossipMenuFor(player);
return true;
}
}
break;
case 2: // Join Queue Arena (rated)
{
if (Arena1v1CheckTalents(player) && JoinQueueArena(player, me, true) == false)
ChatHandler(player->GetSession()).SendSysMessage("|cffFF4500[1v1 Arena System]:|r Something went wrong while join queue.");
CloseGossipMenuFor(player);
return true;
}
break;
case 20: // Join Queue Arena (unrated)
{
if (Arena1v1CheckTalents(player) && JoinQueueArena(player, me, false) == false)
ChatHandler(player->GetSession()).SendSysMessage("|cffFF4500[1v1 Arena System]:|r Something went wrong while join queue.");
CloseGossipMenuFor(player);
return true;
}
break;
case 3: // Leave Queue
{
WorldPacket Data;
Data << (uint8)0x1 << (uint8)0x0 << (uint32)BATTLEGROUND_AA << (uint16)0x0 << (uint8)0x0;
player->GetSession()->HandleBattleFieldPortOpcode(Data);
CloseGossipMenuFor(player);
return true;
}
break;
case 4: // get statistics
{
ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(player->GetArenaTeamId(ArenaTeam::GetSlotByType(ARENA_TEAM_5v5)));
if (at)
{
std::stringstream s;
s << "|cffFF4500[1v1 Arena System]:|r Your statistics ";
s << "\nRating: " << at->GetStats().Rating;
s << "\nRank: " << at->GetStats().Rank;
s << "\nSeason Games: " << at->GetStats().SeasonGames;
s << "\nSeason Wins: " << at->GetStats().SeasonWins;
s << "\nWeek Games: " << at->GetStats().WeekGames;
s << "\nWeek Wins: " << at->GetStats().WeekWins;
ChatHandler(player->GetSession()).PSendSysMessage(s.str().c_str());
}
}
break;
case 5: // Disband arenateam
{
WorldPacket Data;
Data << (uint32)player->GetArenaTeamId(ArenaTeam::GetSlotByType(ARENA_TEAM_5v5));
player->GetSession()->HandleArenaTeamLeaveOpcode(Data);
ChatHandler(player->GetSession()).SendSysMessage("|cffFF4500[1v1 Arena System]:|r Arenateam deleted!");
CloseGossipMenuFor(player);
return true;
}
break;
case 8: // Script Info
{
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Developer: Teiby", GOSSIP_SENDER_MAIN, action);
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Website: www.teiby.de", GOSSIP_SENDER_MAIN, action);
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Version: 2.1", GOSSIP_SENDER_MAIN, action);
AddGossipItemFor(player, GOSSIP_ICON_CHAT, "<-- Back", GOSSIP_SENDER_MAIN, 7);
SendGossipMenuFor(player, 68, me->GetGUID());
return true;
}
break;
}
GossipHello(player);
return true;
}
};
CreatureAI* GetAI(Creature* creature) const override
{
return new npc_1v1arenaAI(creature);
}
};
class npc_arena1v1_world : public WorldScript
{
public:
npc_arena1v1_world() : WorldScript("npc_arena1v1_world") {}
void OnConfigLoad(bool reload) override
{
if (reload) // if gm is using .reload config command // or using .reload config on worldserver console
{
MindsearIsMyHero();
TC_LOG_INFO("server.loading", "============ Re-Loaded Mod Arena 1v1... ========================");
}
else // On worldserver Startup
{
MindsearIsMyHero();
TC_LOG_INFO("server.loading", "============ Loaded Mod Arena 1v1... ===========================");
/*
WorldDatabase.PExecute("INSERT IGNORE INTO `creature_template` (`entry`, `modelid1`, `name`, `subname`, `IconName`, `minlevel`, "
"`maxlevel`, `exp`, `faction`, `npcflag`, `scale`, `baseattacktime`, `unit_class`, `type`, `type_flags`, `HoverHeight`, "
"`RegenHealth`, `ScriptName`) VALUES (%u, %u, '%s', '%s', 'Speak', %u, %u, 2, 35, 3, 1, 2000, 1, 7, "
"138936390, 1, 1, 'npc_1v1arena');", NPC_Entry, NPC_DisplayID, NPC_Name, NPC_SubName, NPC_MinLevel, NPC_MaxLevel);
*/
}
}
};
void AddSC_npc_1v1arena()
{
new npc_1v1arena();
new npc_arena1v1_world();
}