[9232] Replace list bool fields with exclusive true values by subtype field in Creature.
[getmangos.git] / src / game / DuelHandler.cpp
bloba73be6f80065440d4d3c888dc6ddf4b85209e2e6
1 /*
2 * Copyright (C) 2005-2010 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 uint64 guid;
30 Player *pl;
31 Player *plTarget;
33 if(!GetPlayer()->duel) // ignore accept from duel-sender
34 return;
36 recvPacket >> guid;
38 pl = GetPlayer();
39 plTarget = pl->duel->opponent;
41 if(pl == pl->duel->initiator || !plTarget || pl == plTarget || pl->duel->startTime != 0 || plTarget->duel->startTime != 0)
42 return;
44 //sLog.outDebug( "WORLD: received CMSG_DUEL_ACCEPTED" );
45 DEBUG_LOG("Player 1 is: %u (%s)", pl->GetGUIDLow(), pl->GetName());
46 DEBUG_LOG("Player 2 is: %u (%s)", plTarget->GetGUIDLow(), plTarget->GetName());
48 time_t now = time(NULL);
49 pl->duel->startTimer = now;
50 plTarget->duel->startTimer = now;
52 pl->SendDuelCountdown(3000);
53 plTarget->SendDuelCountdown(3000);
56 void WorldSession::HandleDuelCancelledOpcode(WorldPacket& recvPacket)
58 //sLog.outDebug( "WORLD: received CMSG_DUEL_CANCELLED" );
60 // no duel requested
61 if(!GetPlayer()->duel)
62 return;
64 // player surrendered in a duel using /forfeit
65 if(GetPlayer()->duel->startTime != 0)
67 GetPlayer()->CombatStopWithPets(true);
68 if(GetPlayer()->duel->opponent)
69 GetPlayer()->duel->opponent->CombatStopWithPets(true);
71 GetPlayer()->CastSpell(GetPlayer(), 7267, true); // beg
72 GetPlayer()->DuelComplete(DUEL_WON);
73 return;
76 // player either discarded the duel using the "discard button"
77 // or used "/forfeit" before countdown reached 0
78 uint64 guid;
79 recvPacket >> guid;
81 GetPlayer()->DuelComplete(DUEL_INTERUPTED);