2010-10-07 15:35:36 +02:00
|
|
|
/*
|
2020-01-02 06:44:10 +01:00
|
|
|
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
2010-10-07 15:35:36 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-10-02 16:23:55 -05:00
|
|
|
*/
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Common.h"
|
2015-01-10 20:57:53 +01:00
|
|
|
#include "DuelPackets.h"
|
2017-12-10 12:39:37 +01:00
|
|
|
#include "GameTime.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "WorldSession.h"
|
|
|
|
|
#include "Log.h"
|
|
|
|
|
#include "Player.h"
|
2015-04-02 23:48:43 +02:00
|
|
|
#include "ObjectAccessor.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-04-02 18:43:33 +02:00
|
|
|
#define SPELL_DUEL 7266
|
|
|
|
|
#define SPELL_MOUNTED_DUEL 62875
|
|
|
|
|
|
|
|
|
|
void WorldSession::HandleCanDuel(WorldPackets::Duel::CanDuel& packet)
|
|
|
|
|
{
|
|
|
|
|
Player* player = ObjectAccessor::FindPlayer(packet.TargetGUID);
|
|
|
|
|
|
|
|
|
|
if (!player)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
WorldPackets::Duel::CanDuelResult response;
|
|
|
|
|
response.TargetGUID = packet.TargetGUID;
|
|
|
|
|
response.Result = !player->duel;
|
|
|
|
|
SendPacket(response.Write());
|
|
|
|
|
|
|
|
|
|
if (response.Result)
|
|
|
|
|
{
|
|
|
|
|
if (_player->IsMounted())
|
|
|
|
|
_player->CastSpell(player, SPELL_MOUNTED_DUEL);
|
|
|
|
|
else
|
|
|
|
|
_player->CastSpell(player, SPELL_DUEL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-10 20:57:53 +01:00
|
|
|
void WorldSession::HandleDuelResponseOpcode(WorldPackets::Duel::DuelResponse& duelResponse)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2018-10-04 18:50:21 +02:00
|
|
|
if (duelResponse.Accepted && !duelResponse.Forfeited)
|
2018-09-17 12:40:42 +02:00
|
|
|
HandleDuelAccepted(duelResponse.ArbiterGUID);
|
2015-01-10 20:57:53 +01:00
|
|
|
else
|
|
|
|
|
HandleDuelCancelled();
|
|
|
|
|
}
|
2011-09-05 14:54:19 +02:00
|
|
|
|
2018-09-17 12:40:42 +02:00
|
|
|
void WorldSession::HandleDuelAccepted(ObjectGuid arbiterGuid)
|
2015-01-10 20:57:53 +01:00
|
|
|
{
|
|
|
|
|
Player* player = GetPlayer();
|
2018-09-17 12:40:42 +02:00
|
|
|
if (!player->duel || player == player->duel->Initiator || player->duel->State != DUEL_STATE_CHALLENGED)
|
|
|
|
|
return;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2018-09-17 12:40:42 +02:00
|
|
|
Player* target = player->duel->Opponent;
|
|
|
|
|
if (*target->m_playerData->DuelArbiter != arbiterGuid)
|
2008-10-02 16:23:55 -05:00
|
|
|
return;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-10-22 18:12:51 +02:00
|
|
|
TC_LOG_DEBUG("network", "Player 1 is: %s (%s)", player->GetGUID().ToString().c_str(), player->GetName().c_str());
|
2018-09-17 12:40:42 +02:00
|
|
|
TC_LOG_DEBUG("network", "Player 2 is: %s (%s)", target->GetGUID().ToString().c_str(), target->GetName().c_str());
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2017-12-10 12:39:37 +01:00
|
|
|
time_t now = GameTime::GetGameTime();
|
2018-09-17 12:40:42 +02:00
|
|
|
player->duel->StartTime = now + 3;
|
|
|
|
|
target->duel->StartTime = now + 3;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2022-05-01 19:48:31 +02:00
|
|
|
player->duel->State = DUEL_STATE_COUNTDOWN;
|
|
|
|
|
target->duel->State = DUEL_STATE_COUNTDOWN;
|
|
|
|
|
|
2015-04-02 18:43:33 +02:00
|
|
|
WorldPackets::Duel::DuelCountdown packet(3000); // milliseconds
|
2015-04-02 20:59:29 +01:00
|
|
|
WorldPacket const* worldPacket = packet.Write();
|
|
|
|
|
player->GetSession()->SendPacket(worldPacket);
|
2018-09-17 12:40:42 +02:00
|
|
|
target->GetSession()->SendPacket(worldPacket);
|
2018-03-04 22:32:08 +01:00
|
|
|
player->EnablePvpRules();
|
2018-09-17 12:40:42 +02:00
|
|
|
target->EnablePvpRules();
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-01-10 20:57:53 +01:00
|
|
|
void WorldSession::HandleDuelCancelled()
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2018-09-17 12:40:42 +02:00
|
|
|
Player* player = GetPlayer();
|
|
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
// no duel requested
|
2018-09-17 12:40:42 +02:00
|
|
|
if (!player->duel || player->duel->State == DUEL_STATE_COMPLETED)
|
2008-10-02 16:23:55 -05:00
|
|
|
return;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2008-10-02 16:23:55 -05:00
|
|
|
// player surrendered in a duel using /forfeit
|
2018-09-17 12:40:42 +02:00
|
|
|
if (GetPlayer()->duel->State == DUEL_STATE_IN_PROGRESS)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
GetPlayer()->CombatStopWithPets(true);
|
2018-09-17 12:40:42 +02:00
|
|
|
GetPlayer()->duel->Opponent->CombatStopWithPets(true);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2010-02-15 18:23:39 +01:00
|
|
|
GetPlayer()->CastSpell(GetPlayer(), 7267, true); // beg
|
2008-10-02 16:23:55 -05:00
|
|
|
GetPlayer()->DuelComplete(DUEL_WON);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2011-05-11 11:17:20 +06:00
|
|
|
GetPlayer()->DuelComplete(DUEL_INTERRUPTED);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|