Updated Copyright year to 2013
[getmangos.git] / src / game / DuelHandler.cpp
blob2994474ec7217da1a02b46ce9720765917752325
1 /*
2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
22 #include "Log.h"
23 #include "Opcodes.h"
24 #include "UpdateData.h"
25 #include "Player.h"
27 void WorldSession::HandleDuelAcceptedOpcode(WorldPacket& recvPacket)
29 ObjectGuid guid;
30 recvPacket >> guid;
32 if (!GetPlayer()->duel) // ignore accept from duel-sender
33 return;
35 Player* pl = GetPlayer();
36 Player* plTarget = pl->duel->opponent;
38 if (pl == pl->duel->initiator || !plTarget || pl == plTarget || pl->duel->startTime != 0 || plTarget->duel->startTime != 0)
39 return;
41 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT, "WORLD: received CMSG_DUEL_ACCEPTED");
42 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT, "Player 1 is: %u (%s)", pl->GetGUIDLow(), pl->GetName());
43 DEBUG_FILTER_LOG(LOG_FILTER_COMBAT, "Player 2 is: %u (%s)", plTarget->GetGUIDLow(), plTarget->GetName());
45 time_t now = time(NULL);
46 pl->duel->startTimer = now;
47 plTarget->duel->startTimer = now;
49 pl->SendDuelCountdown(3000);
50 plTarget->SendDuelCountdown(3000);
53 void WorldSession::HandleDuelCancelledOpcode(WorldPacket& recvPacket)
55 // DEBUG_LOG( "WORLD: received CMSG_DUEL_CANCELLED" );
57 // no duel requested
58 if (!GetPlayer()->duel)
59 return;
61 // player surrendered in a duel using /forfeit
62 if (GetPlayer()->duel->startTime != 0)
64 GetPlayer()->CombatStopWithPets(true);
65 if (GetPlayer()->duel->opponent)
66 GetPlayer()->duel->opponent->CombatStopWithPets(true);
68 GetPlayer()->CastSpell(GetPlayer(), 7267, true); // beg
69 GetPlayer()->DuelComplete(DUEL_WON);
70 return;
73 // player either discarded the duel using the "discard button"
74 // or used "/forfeit" before countdown reached 0
75 ObjectGuid guid;
76 recvPacket >> guid;
78 GetPlayer()->DuelComplete(DUEL_INTERRUPTED);