| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "Common.h" |
|---|
| 22 | #include "WorldPacket.h" |
|---|
| 23 | #include "WorldSession.h" |
|---|
| 24 | #include "World.h" |
|---|
| 25 | #include "Log.h" |
|---|
| 26 | #include "Opcodes.h" |
|---|
| 27 | #include "UpdateData.h" |
|---|
| 28 | #include "MapManager.h" |
|---|
| 29 | #include "Player.h" |
|---|
| 30 | |
|---|
| 31 | void WorldSession::HandleDuelAcceptedOpcode(WorldPacket& recvPacket) |
|---|
| 32 | { |
|---|
| 33 | CHECK_PACKET_SIZE(recvPacket,8); |
|---|
| 34 | |
|---|
| 35 | uint64 guid; |
|---|
| 36 | Player *pl; |
|---|
| 37 | Player *plTarget; |
|---|
| 38 | |
|---|
| 39 | if(!GetPlayer()->duel) // ignore accept from duel-sender |
|---|
| 40 | return; |
|---|
| 41 | |
|---|
| 42 | recvPacket >> guid; |
|---|
| 43 | |
|---|
| 44 | pl = GetPlayer(); |
|---|
| 45 | plTarget = pl->duel->opponent; |
|---|
| 46 | |
|---|
| 47 | if(pl == pl->duel->initiator || !plTarget || pl == plTarget || pl->duel->startTime != 0 || plTarget->duel->startTime != 0) |
|---|
| 48 | return; |
|---|
| 49 | |
|---|
| 50 | //sLog.outDebug( "WORLD: received CMSG_DUEL_ACCEPTED" ); |
|---|
| 51 | DEBUG_LOG("Player 1 is: %u (%s)", pl->GetGUIDLow(),pl->GetName()); |
|---|
| 52 | DEBUG_LOG("Player 2 is: %u (%s)", plTarget->GetGUIDLow(),plTarget->GetName()); |
|---|
| 53 | |
|---|
| 54 | time_t now = time(NULL); |
|---|
| 55 | pl->duel->startTimer = now; |
|---|
| 56 | plTarget->duel->startTimer = now; |
|---|
| 57 | |
|---|
| 58 | WorldPacket data(SMSG_DUEL_COUNTDOWN, 4); |
|---|
| 59 | data << (uint32)3000; // 3 seconds |
|---|
| 60 | pl->GetSession()->SendPacket(&data); |
|---|
| 61 | plTarget->GetSession()->SendPacket(&data); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | void WorldSession::HandleDuelCancelledOpcode(WorldPacket& recvPacket) |
|---|
| 65 | { |
|---|
| 66 | CHECK_PACKET_SIZE(recvPacket,8); |
|---|
| 67 | |
|---|
| 68 | //sLog.outDebug( "WORLD: received CMSG_DUEL_CANCELLED" ); |
|---|
| 69 | |
|---|
| 70 | // no duel requested |
|---|
| 71 | if(!GetPlayer()->duel) |
|---|
| 72 | return; |
|---|
| 73 | |
|---|
| 74 | // player surrendered in a duel using /forfeit |
|---|
| 75 | if(GetPlayer()->duel->startTime != 0) |
|---|
| 76 | { |
|---|
| 77 | GetPlayer()->CombatStopWithPets(true); |
|---|
| 78 | if(GetPlayer()->duel->opponent) |
|---|
| 79 | GetPlayer()->duel->opponent->CombatStopWithPets(true); |
|---|
| 80 | |
|---|
| 81 | GetPlayer()->CastSpell(GetPlayer(), 7267, true); // beg |
|---|
| 82 | GetPlayer()->DuelComplete(DUEL_WON); |
|---|
| 83 | return; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | // player either discarded the duel using the "discard button" |
|---|
| 87 | // or used "/forfeit" before countdown reached 0 |
|---|
| 88 | uint64 guid; |
|---|
| 89 | recvPacket >> guid; |
|---|
| 90 | |
|---|
| 91 | GetPlayer()->DuelComplete(DUEL_INTERUPTED); |
|---|
| 92 | } |
|---|