-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattlegroundSV.cpp.txt
707 lines (593 loc) · 23.2 KB
/
BattlegroundSV.cpp.txt
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
#include "Player.h"
#include "Battleground.h"
#include "BattlegroundSV.h"
#include "Language.h"
#include "WorldPacket.h"
#include "GameObject.h"
#include "ObjectMgr.h"
#include "Vehicle.h"
#include "Transport.h"
#include "ScriptedCreature.h"
BattlegroundSV::BattlegroundSV()
{
BgObjects.resize(MAX_OBJECT_BANNER_SPAWNS + BG_SV_MAX_BUFF_SPAWNS);
BgCreatures.resize(BG_SV_MAX_SPIRIT_GUIDES_SPAWNS + BG_SV_MAX_CREATURE_SPAWNS);
StartMessageIds[BG_STARTING_EVENT_FIRST] = LANG_BG_SV_START_TWO_MINUTES;
StartMessageIds[BG_STARTING_EVENT_SECOND] = LANG_BG_SV_START_ONE_MINUTE;
StartMessageIds[BG_STARTING_EVENT_THIRD] = LANG_BG_SV_START_HALF_MINUTE;
StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_SV_HAS_BEGUN;
// Setup nodes
for (uint8 i = NODE_TYPE_FIX; i < BG_SV_MAX_NODE_TYPES; ++i)
nodePoint[i] = BG_SV_nodePointInitial[i];
// Set score
for (uint8 i = 0; i < 2; ++i)
TeamScore[i] = BEGIN_SCORE;
// Set timer
ReloadTimer = BG_SV_RELOAD_TIME;
BossSpawnTimer = BG_SV_BOSS_SPAWN_TIMER;
BossWarningTimer = BG_SV_BOSS_WARNING;
}
BattlegroundSV::~BattlegroundSV() { }
// Set Node Buff on Resurrect
void BattlegroundSV::HandlePlayerResurrect(Player* player)
{
if (nodePoint[NODE_TYPE_MINE].nodeState == (player->GetTeamId() == TEAM_ALLIANCE ? BG_SV_NODE_STATE_CONTROLLED_A : BG_SV_NODE_STATE_CONTROLLED_H))
player->CastSpell(player, BG_SV_MINE_BUFF, true);
if (nodePoint[NODE_TYPE_BOSS].nodeState == (player->GetTeamId() == TEAM_ALLIANCE ? BG_SV_NODE_STATE_CONTROLLED_A : BG_SV_NODE_STATE_CONTROLLED_H))
player->CastSpell(player, BG_SV_BOSS_BUFF, true);
}
void BattlegroundSV::PostUpdateImpl(uint32 diff)
{
if (GetStatus() != STATUS_IN_PROGRESS)
{
// roots target and update score for new players in preperation phase
if (ReloadTimer <= diff)
{
for (BattlegroundPlayerMap::const_iterator i = GetPlayers().begin(); i != GetPlayers().end(); ++i)
if (Player* player = ObjectAccessor::FindPlayer(i->first))
{
BG_SV_StartRoot(player);
}
UpdateWorldState(BG_SV_WS_ALLIANCE_SCORE, TeamScore[TEAM_ALLIANCE]);
UpdateWorldState(BG_SV_WS_HORDE_SCORE, TeamScore[TEAM_HORDE]);
ReloadTimer = BG_SV_RELOAD_TIME;
}
else ReloadTimer -= diff;
}
if (GetStatus() == STATUS_IN_PROGRESS)
{
for (uint8 i = NODE_TYPE_FIX; i < BG_SV_MAX_NODE_TYPES; ++i)
{
// the point is waiting for a change on its banner
if (nodePoint[i].needChange)
{
// the point is waiting for a change on its banner
if (nodePoint[i].needChange)
{
if (nodePoint[i].timer <= diff)
{
uint32 nextBanner = GetNextBanner(&nodePoint[i], nodePoint[i].faction, true);
nodePoint[i].last_entry = nodePoint[i].gameobject_entry;
nodePoint[i].gameobject_entry = nextBanner;
// nodePoint[i].faction = the faction should be the same one...
GameObject* banner = GetBGObject(nodePoint[i].gameobject_type);
if (!banner) // this should never happen
return;
float cords[4] = { banner->GetPositionX(), banner->GetPositionY(), banner->GetPositionZ(), banner->GetOrientation() };
DelObject(nodePoint[i].gameobject_type);
AddObject(nodePoint[i].gameobject_type, nodePoint[i].gameobject_entry, cords[0], cords[1], cords[2], cords[3], 0, 0, 0, 0, RESPAWN_ONE_DAY);
GetBGObject(nodePoint[i].gameobject_type)->SetUInt32Value(GAMEOBJECT_FACTION, nodePoint[i].faction == TEAM_ALLIANCE ? BG_SV_Factions[1] : BG_SV_Factions[0]);
BG_SV_UpdateNodeWorldState(&nodePoint[i]);
BG_SV_HandleCapturedNodes(&nodePoint[i], false);
SendMessage2ToAll(LANG_BG_SV_TAKEN, CHAT_MSG_BG_SYSTEM_NEUTRAL, NULL, (nodePoint[i].faction == TEAM_ALLIANCE ? LANG_BG_SV_ALLY : LANG_BG_SV_HORDE), nodePoint[i].string);
PlaySoundToAll(nodePoint[i].faction == TEAM_ALLIANCE ? BG_SV_SOUND_NODE_CAPTURED_ALLIANCE : BG_SV_SOUND_NODE_CAPTURED_HORDE);
nodePoint[i].needChange = false;
nodePoint[i].timer = BG_SV_BANNER_STATE_CHANGE_TIME;
}
else nodePoint[i].timer -= diff;
}
}
}
// updates Score and Buff while bg is running
if (ReloadTimer <= diff)
{
UpdateWorldStates();
ReloadTimer = BG_SV_RELAOD_TIME_INPROGRESS;
}
else ReloadTimer -= diff;
//spawn Bosses after 5 minutes | Warning after 4 minutes
if (BossSpawnAllowd == true)
{
if (BossSpawnTimer <= diff)
{
SpawnBoss();
SendMessage2ToAll(LANG_BG_SV_BOSS_INC_NOW, CHAT_MSG_BG_SYSTEM_NEUTRAL, NULL);
PlaySoundToAll(BG_SV_SOUND_BOSS_INC);
BossSpawnTimer = BG_SV_BOSS_SPAWN_TIMER;
BossSpawnAllowd = false;
}
else BossSpawnTimer -= diff;
if (BossWarningTimer <= diff)
{
SendMessage2ToAll(LANG_BG_SV_BOSS_INC_1MIN, CHAT_MSG_BG_SYSTEM_NEUTRAL, NULL);
BossWarningTimer = BG_SV_BOSS_SPAWN_TIMER;
}
else BossWarningTimer -= diff;
}
}
}
// update score and shows world states by entering the battleground
void BattlegroundSV::StartingEventCloseDoors()
{
TeamScore[TEAM_ALLIANCE] -= 1;
UpdateWorldState(BG_SV_WS_ALLIANCE_SCORE, TeamScore[TEAM_ALLIANCE]);
TeamScore[TEAM_HORDE] -= 1;
UpdateWorldState(BG_SV_WS_HORDE_SCORE, TeamScore[TEAM_HORDE]);
for (uint8 i = 0; i < 4; ++i)
{
BG_SV_UpdateNodeWorldState(&nodePoint[i]);
}
}
//unroot the players and start Boss spawn timer
void BattlegroundSV::StartingEventOpenDoors()
{
for (BattlegroundPlayerMap::const_iterator ir = GetPlayers().begin(); ir != GetPlayers().end(); ++ir)
if (Player* player = ObjectAccessor::FindPlayer(ir->first))
{
BG_SV_RemoveRoot(player);
}
BossSpawnAllowd = true;
}
// done when a player enters the battleground while running
void BattlegroundSV::AddPlayer(Player* player)
{
Battleground::AddPlayer(player);
PlayerScores[player->GetGUID().GetCounter()] = new BattlegroundSVScore(player->GetGUID());
UpdateWorldState(BG_SV_WS_HORDE_SCORE, TeamScore[TEAM_HORDE]);
UpdateWorldState(BG_SV_WS_ALLIANCE_SCORE, TeamScore[TEAM_ALLIANCE]);
for (uint8 i = 0; i < 4; ++i)
{
BG_SV_UpdateNodeWorldState(&nodePoint[i]);
}
if (nodePoint[NODE_TYPE_MINE].nodeState == (player->GetTeamId() == TEAM_ALLIANCE ? BG_SV_NODE_STATE_CONTROLLED_A : BG_SV_NODE_STATE_CONTROLLED_H))
player->CastSpell(player, BG_SV_MINE_BUFF, true);
if (nodePoint[NODE_TYPE_BOSS].nodeState == (player->GetTeamId() == TEAM_ALLIANCE ? BG_SV_NODE_STATE_CONTROLLED_A : BG_SV_NODE_STATE_CONTROLLED_H))
player->CastSpell(player, BG_SV_BOSS_BUFF, true);
}
void BattlegroundSV::UpdateWorldStates()
{
// updates score
UpdateWorldState(BG_SV_WS_HORDE_SCORE, TeamScore[TEAM_HORDE]);
UpdateWorldState(BG_SV_WS_ALLIANCE_SCORE, TeamScore[TEAM_ALLIANCE]);
// updates worldstates on the map
for (uint8 i = 0; i < 4; ++i)
{
BG_SV_UpdateNodeWorldState(&nodePoint[i]);
}
// add Node buffs and remove root
for (BattlegroundPlayerMap::const_iterator ir = GetPlayers().begin(); ir != GetPlayers().end(); ++ir)
if (Player* player = ObjectAccessor::FindPlayer(ir->first))
{
if (nodePoint[NODE_TYPE_MINE].nodeState == (player->GetTeamId() == TEAM_ALLIANCE ? BG_SV_NODE_STATE_CONTROLLED_A : BG_SV_NODE_STATE_CONTROLLED_H))
player->CastSpell(player, BG_SV_MINE_BUFF, true);
if (nodePoint[NODE_TYPE_BOSS].nodeState == (player->GetTeamId() == TEAM_ALLIANCE ? BG_SV_NODE_STATE_CONTROLLED_A : BG_SV_NODE_STATE_CONTROLLED_H))
player->CastSpell(player, BG_SV_BOSS_BUFF, true);
if (GetStatus() == IN_PROGRESS)
{
player->RemoveAura(BG_SV_ROOT);
}
}
}
// done when player leaves the battleground
void BattlegroundSV::RemovePlayer(Player* player, ObjectGuid /*guid*/, uint32 /*team*/)
{
if (player)
{
player->RemoveAura(BG_SV_ROOT);
player->RemoveAura(BG_SV_MINE_BUFF);
player->RemoveAura(BG_SV_BOSS_BUFF);
}
}
//unused
void BattlegroundSV::HandleAreaTrigger(Player* player, uint32 trigger)
{
/*if (GetStatus() != STATUS_IN_PROGRESS)
return; */
}
void BattlegroundSV::FillInitialWorldStates(WorldPacket& data)
{
// set score
data << uint32(BG_SV_WS_ALLIANCE_SCORE) << uint32(TeamScore[TEAM_ALLIANCE]);
data << uint32(BG_SV_WS_HORDE_SCORE) << uint32(TeamScore[TEAM_HORDE]);
// set world states on the map
for (uint8 i = 0; i < BG_SV_MAX_NODE_TYPES; ++i)
data << uint32(nodePoint[i].worldStates[nodePoint[i].nodeState]) << uint32(1);
}
bool BattlegroundSV::SetupBattleground()
{
for (uint8 i = 0; i < MAX_OBJECT_BANNER_SPAWNS; ++i)
{
if (!AddObject(BG_SV_ObjSpawnlocs[i].type, BG_SV_ObjSpawnlocs[i].entry, BG_SV_ObjSpawnlocs[i].x, BG_SV_ObjSpawnlocs[i].y, BG_SV_ObjSpawnlocs[i].z, BG_SV_ObjSpawnlocs[i].o, 0, 0, 0, 0, RESPAWN_ONE_DAY))
{
TC_LOG_ERROR("bg.battleground", "Slavery Valley: There was an error spawning gameobject %u", BG_SV_ObjSpawnlocs[i].entry);
return false;
}
}
for (uint8 i = 0; i < 1; ++i)
{
if (!AddCreature(BG_SV_BossSpawnlocs[i].entry, BG_SV_BossSpawnlocs[i].type, BG_SV_BossSpawnlocs[i].x, BG_SV_BossSpawnlocs[i].y, BG_SV_BossSpawnlocs[i].z, BG_SV_BossSpawnlocs[i].o, BG_SV_BossSpawnlocs[i].team, RESPAWN_ONE_DAY))
{
TC_LOG_ERROR("bg.battleground", "Slavery Valley: There was an error spawning creature %u", BG_SV_BossSpawnlocs[i].entry);
return false;
}
}
for (uint8 i = 0; i < BG_SV_MAX_BUFF_SPAWNS; ++i)
{
if (!AddObject(BG_SV_BuffSpawnlocs[i].type, BG_SV_BuffSpawnlocs[i].entry, BG_SV_BuffSpawnlocs[i].x, BG_SV_BuffSpawnlocs[i].y, BG_SV_BuffSpawnlocs[i].z, BG_SV_BuffSpawnlocs[i].o, 0, 0, 0, 0, BUFF_RESPAWN_TIME))
{
TC_LOG_ERROR("bg.battleground", "Slavery Valley: There was an error spawning buff %u", BG_SV_BuffSpawnlocs[i].entry);
return false;
}
}
if (!AddSpiritGuide(BG_SV_NPC_SPIRIT_GUIDE_1 + 2, BG_SV_SpiritGuidePos[4], TEAM_ALLIANCE)
|| !AddSpiritGuide(BG_SV_NPC_SPIRIT_GUIDE_1 + 3, BG_SV_SpiritGuidePos[5], TEAM_HORDE))
{
TC_LOG_ERROR("bg.battleground", "Isle of Conquest: Failed to spawn initial spirit guide!");
return false;
}
return true;
}
void BattlegroundSV::SpawnBoss()
{
if (BgCreatures[BG_SV_NPC_BOSS_A])
DelCreature(BG_SV_NPC_BOSS_A);
if (BgCreatures[BG_SV_NPC_BOSS_H])
DelCreature(BG_SV_NPC_BOSS_H);
for (uint8 i = 1; i < BG_SV_MAX_CREATURE_SPAWNS; ++i)
{
if (!AddCreature(BG_SV_BossSpawnlocs[i].entry, BG_SV_BossSpawnlocs[i].type, BG_SV_BossSpawnlocs[i].x, BG_SV_BossSpawnlocs[i].y, BG_SV_BossSpawnlocs[i].z, BG_SV_BossSpawnlocs[i].o, BG_SV_BossSpawnlocs[i].team, RESPAWN_ONE_DAY))
{
TC_LOG_ERROR("bg.battleground", "Slavery Valley: There was an error spawning creature %u", BG_SV_BossSpawnlocs[i].entry);
}
}
}
void BattlegroundSV::HandleKillUnit(Creature* unit, Player* killer)
{
if (GetStatus() != STATUS_IN_PROGRESS)
return;
// caused by killing a boss
uint32 entry = unit->GetEntry();
if (entry == BG_SV_ALLIANCE_BOSS)
{
if (nodePoint[NODE_TYPE_MINE].nodeState == BG_SV_NODE_STATE_CONTROLLED_H
&& nodePoint[NODE_TYPE_BOSS].nodeState == BG_SV_NODE_STATE_CONTROLLED_H
&& nodePoint[NODE_TYPE_PRISON].nodeState == BG_SV_NODE_STATE_CONTROLLED_H)
{
if (TeamScore[TEAM_ALLIANCE] < 25)
{
TeamScore[TEAM_ALLIANCE] -= TeamScore[TEAM_ALLIANCE];
}
else TeamScore[TEAM_ALLIANCE] -= 25;
}
else if (TeamScore[TEAM_ALLIANCE] < 10)
{
TeamScore[TEAM_ALLIANCE] -= TeamScore[TEAM_ALLIANCE];
}
else TeamScore[TEAM_ALLIANCE] -= 10;
DelCreature(BG_SV_NPC_BOSS_H);
BossSpawnTimer = BG_SV_BOSS_SPAWN_TIMER;
BossSpawnAllowd = true;
}
else if (entry == BG_SV_HORDE_BOSS)
{
if (nodePoint[NODE_TYPE_MINE].nodeState == BG_SV_NODE_STATE_CONTROLLED_A
&& nodePoint[NODE_TYPE_BOSS].nodeState == BG_SV_NODE_STATE_CONTROLLED_A
&& nodePoint[NODE_TYPE_PRISON].nodeState == BG_SV_NODE_STATE_CONTROLLED_A)
{
if (TeamScore[TEAM_HORDE] < 25)
{
TeamScore[TEAM_HORDE] -= TeamScore[TEAM_HORDE];
}else TeamScore[TEAM_HORDE] -= 25;
}
else if (TeamScore[TEAM_HORDE] < 10)
{
TeamScore[TEAM_HORDE] -= TeamScore[TEAM_HORDE];
}else TeamScore[TEAM_HORDE] -= 10;
DelCreature(BG_SV_NPC_BOSS_A);
BossSpawnTimer = BG_SV_BOSS_SPAWN_TIMER;
BossSpawnAllowd = true;
}
UpdateWorldState((BG_SV_WS_ALLIANCE_SCORE), TeamScore[TEAM_ALLIANCE]);
UpdateWorldState((BG_SV_WS_HORDE_SCORE), TeamScore[TEAM_HORDE]);
if (TeamScore[TEAM_ALLIANCE] < 1)
EndBattleground(TEAM_HORDE);
if (TeamScore[TEAM_HORDE] < 1)
EndBattleground(TEAM_ALLIANCE);
}
void BattlegroundSV::HandleKillPlayer(Player* player, Player* killer)
{
if (GetStatus() != STATUS_IN_PROGRESS)
return;
// suizide gives no points
if (killer->GetTeamId() == player->GetTeamId())
{
return;
}
Battleground::HandleKillPlayer(player, killer);
if (killer->GetTeamId() == TEAM_ALLIANCE)
{
if (AllianceCaptured == true && TeamScore[player->GetTeamId()] > 1)
{
TeamScore[player->GetTeamId()] -= 2;
UpdatePlayerScore(player, SCORE_KILL_POINTS, 2);
}
else
{
TeamScore[player->GetTeamId()] -= 1;
UpdatePlayerScore(player, SCORE_KILL_POINTS, 1);
}
}
if (killer->GetTeamId() == TEAM_HORDE)
{
if (HordeCaptured == true && TeamScore[player->GetTeamId()] > 1)
{
TeamScore[player->GetTeamId()] -= 2;
UpdatePlayerScore(player, SCORE_KILL_POINTS, 2);
}
else
{
TeamScore[player->GetTeamId()] -= 1;
UpdatePlayerScore(player, SCORE_KILL_POINTS, 1);
}
}
UpdateWorldState((killer->GetTeamId() == TEAM_ALLIANCE ? BG_SV_WS_ALLIANCE_SCORE : BG_SV_WS_HORDE_SCORE), TeamScore[killer->GetTeamId()]);
UpdateWorldState((player->GetTeamId() == TEAM_ALLIANCE ? BG_SV_WS_ALLIANCE_SCORE : BG_SV_WS_HORDE_SCORE), TeamScore[player->GetTeamId()]);
// we must end the battleground
if (TeamScore[player->GetTeamId()] < 1)
EndBattleground(killer->GetTeam());
}
void BattlegroundSV::EndBattleground(uint32 winner)
{
RewardHonorToTeam(BG_SV_WINNER_HONOR_AMOUNT, winner == ALLIANCE ? ALLIANCE : HORDE);
Battleground::EndBattleground(winner);
}
void BattlegroundSV::EventPlayerClickedOnFlag(Player* player, GameObject* target_obj)
{
if (GetStatus() != STATUS_IN_PROGRESS)
return;
// All the node points are iterated to find the clicked one
for (uint8 i = 0; i < BG_SV_MAX_NODE_TYPES; ++i)
{
if (nodePoint[i].gameobject_entry == target_obj->GetEntry())
{
// THIS SHOULD NEEVEER HAPPEN
if (nodePoint[i].faction == player->GetTeamId())
return;
uint32 nextBanner = GetNextBanner(&nodePoint[i], player->GetTeamId(), false);
// we set the new settings of the nodePoint
nodePoint[i].faction = player->GetTeamId();
if (nodePoint[i].gameobject_entry == BG_SV_PRISON_BANNER
|| nodePoint[i].gameobject_entry == BG_SV_MINE_BANNER
|| nodePoint[i].gameobject_entry == BG_SV_BOSS_BANNER)
{
nodePoint[i].last_entry = 0;
} else nodePoint[i].last_entry = nodePoint[i].gameobject_entry;
nodePoint[i].gameobject_entry = nextBanner;
// this is just needed if the next banner is grey
if (nodePoint[i].banners[BG_SV_BANNER_A_CONTESTED] == nextBanner || nodePoint[i].banners[BG_SV_BANNER_H_CONTESTED] == nextBanner)
{
nodePoint[i].timer = BG_SV_BANNER_STATE_CHANGE_TIME; // 1 minute for last change (real faction banner)
nodePoint[i].needChange = true;
if (nodePoint[i].nodeType != NODE_TYPE_PRISON)
{
RelocateDeadPlayers(BgCreatures[BG_SV_NPC_SPIRIT_GUIDE_1 + nodePoint[i].nodeType - 2]);
}
// if we are here means that the point has been lost, or it is the first capture
if (nodePoint[i].nodeType != NODE_TYPE_PRISON)
if (BgCreatures[BG_SV_NPC_SPIRIT_GUIDE_1 + (nodePoint[i].nodeType) - 2])
DelCreature(BG_SV_NPC_SPIRIT_GUIDE_1 + (nodePoint[i].nodeType) - 2);
SendMessage2ToAll(LANG_BG_SV_ASSAULTED, CHAT_MSG_BG_SYSTEM_NEUTRAL, player, nodePoint[i].string);
PlaySoundToAll(nodePoint[i].faction == TEAM_ALLIANCE ? BG_SV_SOUND_NODE_ASSAULTED_ALLIANCE : BG_SV_SOUND_NODE_ASSAULTED_HORDE);
BG_SV_HandleContestedNodes(&nodePoint[i]);
}
else if (nextBanner == nodePoint[i].banners[BG_SV_BANNER_A_CONTROLLED] || nextBanner == nodePoint[i].banners[BG_SV_BANNER_H_CONTROLLED]) // if we are going to spawn the definitve faction banner, we dont need the timer anymore
{
nodePoint[i].timer = BG_SV_BANNER_STATE_CHANGE_TIME;
nodePoint[i].needChange = false;
SendMessage2ToAll(LANG_BG_SV_DEFENDED, CHAT_MSG_BG_SYSTEM_NEUTRAL, player, nodePoint[i].string);
PlaySoundToAll(nodePoint[i].faction == TEAM_ALLIANCE ? BG_SV_SOUND_NODE_CAPTURED_ALLIANCE : BG_SV_SOUND_NODE_CAPTURED_HORDE);
BG_SV_HandleCapturedNodes(&nodePoint[i], true);
}
GameObject* banner = GetBGObject(nodePoint[i].gameobject_type);
if (!banner) // this should never happen
return;
float cords[4] = { banner->GetPositionX(), banner->GetPositionY(), banner->GetPositionZ(), banner->GetOrientation() };
DelObject(nodePoint[i].gameobject_type);
if (!AddObject(nodePoint[i].gameobject_type, nodePoint[i].gameobject_entry, cords[0], cords[1], cords[2], cords[3], 0, 0, 0, 0, RESPAWN_ONE_DAY))
{
TC_LOG_ERROR("bg.battleground", "Isle of Conquest: There was an error spawning a banner (type: %u, entry: %u). Isle of Conquest BG cancelled.", nodePoint[i].gameobject_type, nodePoint[i].gameobject_entry);
EndBattleground(0);
}
GetBGObject(nodePoint[i].gameobject_type)->SetUInt32Value(GAMEOBJECT_FACTION, nodePoint[i].faction == TEAM_ALLIANCE ? BG_SV_Factions[1] : BG_SV_Factions[0]);
BG_SV_UpdateNodeWorldState(&nodePoint[i]);
// we dont need iterating if we are here
// If the needChange bool was set true, we will handle the rest in the Update Map function.
return;
}
}
}
void BattlegroundSV::BG_SV_UpdateNodeWorldState(BG_SV_NodePoint* node)
{
//updating worldstate
if (node->gameobject_entry == node->banners[BG_SV_BANNER_A_CONTROLLED])
node->nodeState = BG_SV_NODE_STATE_CONTROLLED_A;
else if (node->gameobject_entry == node->banners[BG_SV_BANNER_A_CONTESTED])
node->nodeState = BG_SV_NODE_STATE_CONFLICT_A;
else if (node->gameobject_entry == node->banners[BG_SV_BANNER_H_CONTROLLED])
node->nodeState = BG_SV_NODE_STATE_CONTROLLED_H;
else if (node->gameobject_entry == node->banners[BG_SV_BANNER_H_CONTESTED])
node->nodeState = BG_SV_NODE_STATE_CONFLICT_H;
uint32 worldstate = node->worldStates[node->nodeState];
// with this we are sure we dont bug the client
for (uint8 i = 0; i < 5; ++i)
{
if (node->worldStates[i] == worldstate)
continue;
UpdateWorldState(node->worldStates[i], 0);
}
UpdateWorldState(worldstate, 1);
}
uint32 BattlegroundSV::GetNextBanner(BG_SV_NodePoint* node, uint32 team, bool returnDefinitve)
{
// this is only used in the update map function
if (returnDefinitve)
// here is a special case, here we must return the definitve faction banner after the grey banner was spawned 1 minute
return node->banners[(team == TEAM_ALLIANCE ? BG_SV_BANNER_A_CONTROLLED : BG_SV_BANNER_H_CONTROLLED)];
// there were no changes, this point has never been captured by any faction or at least clicked
if (node->last_entry == 0)
// 1 returns the CONTESTED ALLIANCE BANNER, 3 returns the HORDE one
return node->banners[(team == TEAM_ALLIANCE ? BG_SV_BANNER_A_CONTESTED : BG_SV_BANNER_H_CONTESTED)];
// If the actual banner is the definitive faction banner, we must return the grey banner of the player's faction
if (node->gameobject_entry == node->banners[BG_SV_BANNER_A_CONTROLLED] || node->gameobject_entry == node->banners[BG_SV_BANNER_H_CONTROLLED])
return node->banners[(team == TEAM_ALLIANCE ? BG_SV_BANNER_A_CONTESTED : BG_SV_BANNER_H_CONTESTED)];
// If the actual banner is the grey faction banner, we must return the previous banner
if (node->gameobject_entry == node->banners[BG_SV_BANNER_A_CONTESTED] || node->banners[BG_SV_BANNER_H_CONTESTED])
return node->last_entry;
// we should never be here...
TC_LOG_ERROR("bg.battleground", "Slavery Valley: Unexpected return in GetNextBanner function");
return 0;
}
void BattlegroundSV::BG_SV_HandleContestedNodes(BG_SV_NodePoint* node)
{
// noby has this node
if (node->nodeType == NODE_TYPE_PRISON)
{
AllianceCaptured = false;
HordeCaptured = false;
}
node->captured = false;
if (node->nodeType == NODE_TYPE_MINE)
{
RemoveAuraOnTeam(BG_SV_MINE_BUFF, TEAM_ALLIANCE);
RemoveAuraOnTeam(BG_SV_MINE_BUFF, TEAM_HORDE);
}
if (node->nodeType == NODE_TYPE_BOSS)
{
RemoveAuraOnTeam(BG_SV_BOSS_BUFF, TEAM_ALLIANCE);
RemoveAuraOnTeam(BG_SV_BOSS_BUFF, TEAM_HORDE);
}
}
void BattlegroundSV::BG_SV_HandleCapturedNodes(BG_SV_NodePoint* node, bool recapture)
{
if (node->nodeType != NODE_TYPE_FIX && node->nodeType != NODE_TYPE_PRISON)
{
if (!AddSpiritGuide(BG_SV_NPC_SPIRIT_GUIDE_1 + node->nodeType - 2, BG_SV_SpiritGuidePos[node->nodeType], node->faction))
TC_LOG_ERROR("bg.battleground", "Slavery Valley Failed to spawn spirit guide! point: %u, team: %u, ", node->nodeType, node->faction);
}
if (node->nodeType == NODE_TYPE_PRISON)
{
if (node->faction == TEAM_ALLIANCE)
{
AllianceCaptured = true;
HordeCaptured = false;
}
if (node->faction == TEAM_HORDE)
{
AllianceCaptured = false;
HordeCaptured = true;
}
}
node->captured = true;
switch (node->gameobject_type)
{
case BG_SV_GO_MINE_BANNER:
RemoveAuraOnTeam(BG_SV_MINE_BUFF, (node->faction == TEAM_ALLIANCE ? HORDE : ALLIANCE));
CastSpellOnTeam(BG_SV_MINE_BUFF, (node->faction == TEAM_ALLIANCE ? ALLIANCE : HORDE));
break;
case BG_SV_GO_BOSS_BANNER:
RemoveAuraOnTeam(BG_SV_BOSS_BUFF, (node->faction == TEAM_ALLIANCE ? HORDE : ALLIANCE));
CastSpellOnTeam(BG_SV_BOSS_BUFF, (node->faction == TEAM_ALLIANCE ? ALLIANCE : HORDE));
break;
default:
break;
}
}
void BattlegroundSV::BG_SV_StartRoot(Player* player)
{
// player position
float plr_x = player->GetPositionX();
float plr_y = player->GetPositionY();
// root point alliance
float RootPointX_A = -237.889f;
float RootPointY_A = 1295.035f;
// root point horde
float RootPointX_H = 578.759f;
float RootPointY_H = 1002.339f;
// if players distance to the root point is lower than this he get rooted
float RootDist = 27.5f*27.5f; // form: (your distance you want to root)*(your distance you want to root)
if (player->GetTeam() == ALLIANCE)
{
float distA = (RootPointX_A - plr_x)*(RootPointX_A - plr_x) + (RootPointY_A - plr_y)*(RootPointY_A - plr_y);
if (player->HasAura(BG_SV_ROOT))
{
return;
}
else
{
if (distA < RootDist)
player->CastSpell(player, BG_SV_ROOT, true);
}
}
if (player->GetTeam() == HORDE)
{
float distH = (RootPointX_H - plr_x)*(RootPointX_H - plr_x) + (RootPointY_H - plr_y)*(RootPointY_H - plr_y);
if (player->HasAura(BG_SV_ROOT))
{
return;
}
else
{
if (distH < RootDist)
player->CastSpell(player, BG_SV_ROOT, true);
}
}
}
// unused
void BattlegroundSV::BG_SV_RemoveRoot(Player* player)
{
player->RemoveAura(BG_SV_ROOT);
}
WorldSafeLocsEntry const* BattlegroundSV::GetClosestGraveYard(Player* player)
{
TeamId teamIndex = GetTeamIndexByTeamId(player->GetTeam());
// Is there any occupied node for this team?
std::vector<uint8> nodes;
for (uint8 i = 0; i < BG_SV_MAX_NODE_TYPES; ++i)
if (nodePoint[i].faction == player->GetTeamId() && nodePoint[i].captured == true)
nodes.push_back(i);
WorldSafeLocsEntry const* good_entry = NULL;
// If so, select the closest node to place ghost on
if (!nodes.empty())
{
float player_x = player->GetPositionX();
float player_y = player->GetPositionY();
float mindist = 999999.0f;
for (uint8 i = 0; i < nodes.size(); ++i)
{
WorldSafeLocsEntry const*entry = sWorldSafeLocsStore.LookupEntry(BG_SV_GraveyardIds[nodes[i]]);
if (!entry)
continue;
float dist = (entry->x - player_x)*(entry->x - player_x) + (entry->y - player_y)*(entry->y - player_y);
if (mindist > dist)
{
mindist = dist;
good_entry = entry;
}
}
nodes.clear();
}
// If not, place ghost on starting location
if (!good_entry)
good_entry = sWorldSafeLocsStore.LookupEntry(BG_SV_GraveyardIds[teamIndex + BG_SV_MAX_NODE_TYPES]);
return good_entry;
}