TrinityCore
Loading...
Searching...
No Matches
DuelHandler.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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 "GameTime.h"
22#include "Log.h"
23#include "Player.h"
24
26{
27 Player* player = GetPlayer();
28 if (!player->duel || player == player->duel->Initiator || player->duel->State != DUEL_STATE_CHALLENGED)
29 return;
30
31 ObjectGuid guid;
32 recvPacket >> guid;
33
34 Player* target = player->duel->Opponent;
35 if (target->GetGuidValue(PLAYER_DUEL_ARBITER) != guid)
36 return;
37
38 //TC_LOG_DEBUG("network", "WORLD: Received CMSG_DUEL_ACCEPTED");
39 TC_LOG_DEBUG("network", "Player 1 is: {} ({})", player->GetGUID().ToString(), player->GetName());
40 TC_LOG_DEBUG("network", "Player 2 is: {} ({})", target->GetGUID().ToString(), target->GetName());
41
42 time_t now = GameTime::GetGameTime();
43 player->duel->StartTime = now + 3;
44 target->duel->StartTime = now + 3;
45
46 player->duel->State = DUEL_STATE_COUNTDOWN;
47 target->duel->State = DUEL_STATE_COUNTDOWN;
48
49 player->SendDuelCountdown(3000);
50 target->SendDuelCountdown(3000);
51}
52
54{
55 TC_LOG_DEBUG("network", "WORLD: Received CMSG_DUEL_CANCELLED");
56 Player* player = GetPlayer();
57
58 ObjectGuid guid;
59 recvPacket >> guid;
60
61 // no duel requested
62 if (!player->duel || player->duel->State == DUEL_STATE_COMPLETED)
63 return;
64
65 // player surrendered in a duel using /forfeit
66 if (GetPlayer()->duel->State == DUEL_STATE_IN_PROGRESS)
67 {
69 GetPlayer()->duel->Opponent->CombatStopWithPets(true);
70
71 GetPlayer()->CastSpell(GetPlayer(), 7267, true); // beg
73 return;
74 }
75
77}
#define TC_LOG_DEBUG(filterType__,...)
Definition Log.h:156
@ DUEL_STATE_CHALLENGED
Definition Player.h:253
@ DUEL_STATE_COUNTDOWN
Definition Player.h:254
@ DUEL_STATE_COMPLETED
Definition Player.h:256
@ DUEL_STATE_IN_PROGRESS
Definition Player.h:255
@ DUEL_WON
@ DUEL_INTERRUPTED
@ PLAYER_DUEL_ARBITER
std::string ToString() const
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
ObjectGuid GetGuidValue(uint16 index) const
Definition Object.cpp:281
void DuelComplete(DuelCompleteType type)
Definition Player.cpp:6937
void SendDuelCountdown(uint32 counter)
Definition Player.cpp:25901
std::unique_ptr< DuelInfo > duel
Definition Player.h:1602
void CombatStopWithPets(bool includingCast=false)
Definition Unit.cpp:5710
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2832
std::string const & GetName() const
Definition Object.h:382
Player * GetPlayer() const
void HandleDuelAcceptedOpcode(WorldPacket &recvPacket)
void HandleDuelCancelledOpcode(WorldPacket &recvPacket)
time_t GetGameTime()
Definition GameTime.cpp:42