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 "DuelPackets.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 Player* target = player->duel->Opponent;
32 if (target->GetGuidValue(PLAYER_DUEL_ARBITER) != duelResponse.ArbiterGUID)
33 return;
34
35 TC_LOG_DEBUG("network", "Player 1 is: {} ({})", player->GetGUID().ToString(), player->GetName());
36 TC_LOG_DEBUG("network", "Player 2 is: {} ({})", target->GetGUID().ToString(), target->GetName());
37
38 time_t now = GameTime::GetGameTime();
39 player->duel->StartTime = now + 3;
40 target->duel->StartTime = now + 3;
41
42 player->duel->State = DUEL_STATE_COUNTDOWN;
43 target->duel->State = DUEL_STATE_COUNTDOWN;
44
45 player->SendDuelCountdown(3000);
46 target->SendDuelCountdown(3000);
47}
48
50{
51 Player* player = GetPlayer();
52
53 // no duel requested
54 if (!player->duel || player->duel->State == DUEL_STATE_COMPLETED)
55 return;
56
57 // player surrendered in a duel using /forfeit
58 if (GetPlayer()->duel->State == DUEL_STATE_IN_PROGRESS)
59 {
61 GetPlayer()->duel->Opponent->CombatStopWithPets(true);
62
63 GetPlayer()->CastSpell(GetPlayer(), 7267, true); // beg
65 return;
66 }
67
69}
#define TC_LOG_DEBUG(filterType__,...)
Definition Log.h:156
@ DUEL_STATE_CHALLENGED
Definition Player.h:255
@ DUEL_STATE_COUNTDOWN
Definition Player.h:256
@ DUEL_STATE_COMPLETED
Definition Player.h:258
@ DUEL_STATE_IN_PROGRESS
Definition Player.h:257
@ 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:273
void DuelComplete(DuelCompleteType type)
Definition Player.cpp:6938
void SendDuelCountdown(uint32 counter)
Definition Player.cpp:25856
std::unique_ptr< DuelInfo > duel
Definition Player.h:1587
void CombatStopWithPets(bool includingCast=false)
Definition Unit.cpp:5652
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2833
std::string const & GetName() const
Definition Object.h:384
void HandleDuelCancelled(WorldPackets::Duel::DuelResponse &duelResponse)
Player * GetPlayer() const
void HandleDuelAccepted(WorldPackets::Duel::DuelResponse &duelResponse)
time_t GetGameTime()
Definition GameTime.cpp:42