Files
TCPlayerbotCore/src/server/game/Handlers/DuelHandler.cpp
T

80 lines
2.6 KiB
C++
Raw Normal View History

/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "Log.h"
#include "Opcodes.h"
#include "UpdateData.h"
#include "Player.h"
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleDuelAcceptedOpcode(WorldPacket& recvPacket)
{
uint64 guid;
2011-11-07 11:18:00 -06:00
Player* player;
Player* plTarget;
2009-10-17 15:51:44 -07:00
recvPacket >> guid;
2010-04-07 19:14:10 +02:00
if (!GetPlayer()->duel) // ignore accept from duel-sender
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
2011-11-07 11:18:00 -06:00
player = GetPlayer();
plTarget = player->duel->opponent;
2009-10-17 15:51:44 -07:00
2011-11-07 11:18:00 -06:00
if (player == player->duel->initiator || !plTarget || player == plTarget || player->duel->startTime != 0 || plTarget->duel->startTime != 0)
2008-10-02 16:23:55 -05:00
return;
2009-10-17 15:51:44 -07:00
//sLog->outDebug(LOG_FILTER_PACKETIO, "WORLD: Received CMSG_DUEL_ACCEPTED");
sLog->outDebug(LOG_FILTER_NETWORKIO, "Player 1 is: %u (%s)", player->GetGUIDLow(), player->GetName());
sLog->outDebug(LOG_FILTER_NETWORKIO, "Player 2 is: %u (%s)", plTarget->GetGUIDLow(), plTarget->GetName());
2009-10-17 15:51:44 -07:00
time_t now = time(NULL);
2011-11-07 11:18:00 -06:00
player->duel->startTimer = now;
2008-10-02 16:23:55 -05:00
plTarget->duel->startTimer = now;
2009-10-17 15:51:44 -07:00
2011-11-07 11:18:00 -06:00
player->SendDuelCountdown(3000);
plTarget->SendDuelCountdown(3000);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleDuelCancelledOpcode(WorldPacket& recvPacket)
{
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_DUEL_CANCELLED");
uint64 guid;
recvPacket >> guid;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// no duel requested
2010-04-07 19:14:10 +02:00
if (!GetPlayer()->duel)
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
2010-04-07 19:14:10 +02:00
if (GetPlayer()->duel->startTime != 0)
2008-10-02 16:23:55 -05:00
{
GetPlayer()->CombatStopWithPets(true);
2010-04-07 19:14:10 +02:00
if (GetPlayer()->duel->opponent)
2008-10-02 16:23:55 -05: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
GetPlayer()->DuelComplete(DUEL_INTERRUPTED);
2008-10-02 16:23:55 -05:00
}