TrinityCore
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 "GameTime.h"
21#include "WorldSession.h"
22#include "Log.h"
23#include "Player.h"
24#include "ObjectAccessor.h"
25
26#define SPELL_DUEL 7266
27#define SPELL_MOUNTED_DUEL 62875
28
30{
32
33 if (!player)
34 return;
35
37 response.TargetGUID = packet.TargetGUID;
38 response.Result = !player->duel;
39 SendPacket(response.Write());
40
41 if (response.Result)
42 {
43 if (_player->IsMounted())
45 else
47 }
48}
49
51{
52 if (duelResponse.Accepted && !duelResponse.Forfeited)
53 HandleDuelAccepted(duelResponse.ArbiterGUID);
54 else
56}
57
59{
60 Player* player = GetPlayer();
61 if (!player->duel || player == player->duel->Initiator || player->duel->State != DUEL_STATE_CHALLENGED)
62 return;
63
64 Player* target = player->duel->Opponent;
65 if (*target->m_playerData->DuelArbiter != arbiterGuid)
66 return;
67
68 TC_LOG_DEBUG("network", "Player 1 is: {} ({})", player->GetGUID().ToString(), player->GetName());
69 TC_LOG_DEBUG("network", "Player 2 is: {} ({})", target->GetGUID().ToString(), target->GetName());
70
71 time_t now = GameTime::GetGameTime();
72 player->duel->StartTime = now + 3;
73 target->duel->StartTime = now + 3;
74
75 player->duel->State = DUEL_STATE_COUNTDOWN;
76 target->duel->State = DUEL_STATE_COUNTDOWN;
77
78 WorldPackets::Duel::DuelCountdown packet(3000); // milliseconds
79 WorldPacket const* worldPacket = packet.Write();
80 player->GetSession()->SendPacket(worldPacket);
81 target->GetSession()->SendPacket(worldPacket);
82 player->EnablePvpRules();
83 target->EnablePvpRules();
84}
85
87{
88 Player* player = GetPlayer();
89
90 // no duel requested
91 if (!player->duel || player->duel->State == DUEL_STATE_COMPLETED)
92 return;
93
94 // player surrendered in a duel using /forfeit
95 if (GetPlayer()->duel->State == DUEL_STATE_IN_PROGRESS)
96 {
98 GetPlayer()->duel->Opponent->CombatStopWithPets(true);
99
100 GetPlayer()->CastSpell(GetPlayer(), 7267, true); // beg
102 return;
103 }
104
106}
#define SPELL_MOUNTED_DUEL
Definition: DuelHandler.cpp:27
#define SPELL_DUEL
Definition: DuelHandler.cpp:26
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
@ DUEL_STATE_CHALLENGED
Definition: Player.h:357
@ DUEL_STATE_COUNTDOWN
Definition: Player.h:358
@ DUEL_STATE_COMPLETED
Definition: Player.h:360
@ DUEL_STATE_IN_PROGRESS
Definition: Player.h:359
@ DUEL_WON
@ DUEL_INTERRUPTED
std::string ToString() const
Definition: ObjectGuid.cpp:554
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
UF::UpdateField< UF::PlayerData, 0, TYPEID_PLAYER > m_playerData
Definition: Player.h:2863
void DuelComplete(DuelCompleteType type)
Definition: Player.cpp:7741
void EnablePvpRules(bool dueToCombat=false)
Definition: Player.cpp:27040
WorldSession * GetSession() const
Definition: Player.h:2101
std::unique_ptr< DuelInfo > duel
Definition: Player.h:1972
bool IsMounted() const
Definition: Unit.h:898
void CombatStopWithPets(bool includingCast=false)
Definition: Unit.cpp:5855
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition: Object.cpp:2896
std::string const & GetName() const
Definition: Object.h:555
WorldPacket const * Write() override
Definition: DuelPackets.cpp:26
WorldPacket const * Write() override
Definition: DuelPackets.cpp:43
Player * GetPlayer() const
void HandleDuelResponseOpcode(WorldPackets::Duel::DuelResponse &duelResponse)
Definition: DuelHandler.cpp:50
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Player * _player
void HandleDuelAccepted(ObjectGuid arbiterGuid)
Definition: DuelHandler.cpp:58
void HandleDuelCancelled()
Definition: DuelHandler.cpp:86
void HandleCanDuel(WorldPackets::Duel::CanDuel &packet)
Definition: DuelHandler.cpp:29
time_t GetGameTime()
Definition: GameTime.cpp:44
TC_GAME_API Player * FindPlayer(ObjectGuid const &)