OregonCore  revision 3611e8a-git
Your Favourite TBC server
DuelHandler.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Common.h"
19 #include "WorldPacket.h"
20 #include "WorldSession.h"
21 #include "World.h"
22 #include "Log.h"
23 #include "MapManager.h"
24 #include "Player.h"
25 
27 {
28  recvPacket >> Unused<uint64>(); // guid
29 
30  if (!GetPlayer()->duel) // ignore accept from duel-sender
31  return;
32 
33  Player* pl = GetPlayer();
34  Player* plTarget = pl->duel->opponent;
35 
36  if (pl == pl->duel->initiator || !plTarget || pl == plTarget || pl->duel->startTime != 0 || plTarget->duel->startTime != 0)
37  return;
38 
39  //sLog.outDebug("WORLD: received CMSG_DUEL_ACCEPTED");
40  DEBUG_LOG("Player 1 is: %u (%s)", pl->GetGUIDLow(), pl->GetName());
41  DEBUG_LOG("Player 2 is: %u (%s)", plTarget->GetGUIDLow(), plTarget->GetName());
42 
43  time_t now = time(NULL);
44  pl->duel->startTimer = now;
45  plTarget->duel->startTimer = now;
46 
47  if (sWorld.getConfig(CONFIG_DUEL_MOD))
48  {
49  pl->ResetAllPowers();
50  plTarget->ResetAllPowers();
51 
52  if (sWorld.getConfig(CONFIG_DUEL_CD_RESET) && !pl->GetMap()->IsDungeon())
54 
55  if (sWorld.getConfig(CONFIG_DUEL_CD_RESET) && !plTarget->GetMap()->IsDungeon())
56  plTarget->RemoveArenaSpellCooldowns();
57  }
58 
60  data << (uint32)3000; // 3 seconds
61  pl->GetSession()->SendPacket(&data);
62  plTarget->GetSession()->SendPacket(&data);
63 }
64 
66 {
67  //sLog.outDebug("WORLD: received CMSG_DUEL_CANCELLED");
68 
69  recvPacket >> Unused<uint64>(); // guid
70 
71  // no duel requested
72  if (!GetPlayer()->duel)
73  return;
74 
75  // player surrendered in a duel using /forfeit
76  if (GetPlayer()->duel->startTime != 0)
77  {
79  if (GetPlayer()->duel->opponent)
81 
82  GetPlayer()->CastSpell(GetPlayer(), SPELL_DUEL_BEG, true); // beg
84  return;
85  }
86 
87  // player either discarded the duel using the "discard button"
88  // or used "/forfeit" before countdown reached 0
90 }
91 
time_t startTime
Definition: Player.h:235
Map * GetMap() const
Definition: Object.h:829
DuelInfo * duel
Definition: Player.h:1809
void HandleDuelCancelledOpcode(WorldPacket &recvPacket)
Definition: DuelHandler.cpp:65
void CombatStopWithPets(bool cast=false)
Definition: Unit.cpp:7459
bool IsDungeon() const
Definition: Map.h:427
Player * GetPlayer() const
Definition: WorldSession.h:104
uint32 GetGUIDLow() const
Definition: Object.h:160
time_t startTimer
Definition: Player.h:234
void SendPacket(WorldPacket const *packet)
void RemoveArenaSpellCooldowns()
Definition: Player.cpp:3375
Player * initiator
Definition: Player.h:232
void CastSpell(Unit *Victim, uint32 spellId, bool triggered, Item *castItem=NULL, Aura *triggeredByAura=NULL, uint64 originalCaster=0)
Definition: Unit.cpp:1174
#define DEBUG_LOG(...)
Definition: Log.h:194
void ResetAllPowers()
Definition: Player.cpp:2154
void DuelComplete(DuelCompleteType type)
Definition: Player.cpp:6461
const char * GetName() const
Definition: Object.h:692
void HandleDuelAcceptedOpcode(WorldPacket &recvPacket)
Definition: DuelHandler.cpp:26
Player * opponent
Definition: Player.h:233
WorldSession * GetSession() const
Definition: Player.h:1959
#define sWorld
Definition: World.h:860
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Player.h:922