root/trunk/src/game/DuelHandler.cpp @ 42

Revision 2, 2.8 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "Common.h"
20#include "WorldPacket.h"
21#include "WorldSession.h"
22#include "World.h"
23#include "Log.h"
24#include "Opcodes.h"
25#include "UpdateData.h"
26#include "MapManager.h"
27#include "Player.h"
28
29void WorldSession::HandleDuelAcceptedOpcode(WorldPacket& recvPacket)
30{
31    CHECK_PACKET_SIZE(recvPacket,8);
32
33    uint64 guid;
34    Player *pl;
35    Player *plTarget;
36
37    if(!GetPlayer()->duel)                                  // ignore accept from duel-sender
38        return;
39
40    recvPacket >> guid;
41
42    pl       = GetPlayer();
43    plTarget = pl->duel->opponent;
44
45    if(pl == pl->duel->initiator || !plTarget || pl == plTarget || pl->duel->startTime != 0 || plTarget->duel->startTime != 0)
46        return;
47
48    //sLog.outDebug( "WORLD: received CMSG_DUEL_ACCEPTED" );
49    DEBUG_LOG("Player 1 is: %u (%s)", pl->GetGUIDLow(),pl->GetName());
50    DEBUG_LOG("Player 2 is: %u (%s)", plTarget->GetGUIDLow(),plTarget->GetName());
51
52    time_t now = time(NULL);
53    pl->duel->startTimer = now;
54    plTarget->duel->startTimer = now;
55
56    WorldPacket data(SMSG_DUEL_COUNTDOWN, 4);
57    data << (uint32)3000;                                   // 3 seconds
58    pl->GetSession()->SendPacket(&data);
59    plTarget->GetSession()->SendPacket(&data);
60}
61
62void WorldSession::HandleDuelCancelledOpcode(WorldPacket& recvPacket)
63{
64    CHECK_PACKET_SIZE(recvPacket,8);
65
66    //sLog.outDebug( "WORLD: received CMSG_DUEL_CANCELLED" );
67
68    // no duel requested
69    if(!GetPlayer()->duel)
70        return;
71
72    // player surrendered in a duel using /forfeit
73    if(GetPlayer()->duel->startTime != 0)
74    {
75        GetPlayer()->CombatStopWithPets(true);
76        if(GetPlayer()->duel->opponent)
77            GetPlayer()->duel->opponent->CombatStopWithPets(true);
78
79        GetPlayer()->CastSpell(GetPlayer(), 7267, true);    // beg
80        GetPlayer()->DuelComplete(DUEL_WON);
81        return;
82    }
83
84    // player either discarded the duel using the "discard button"
85    // or used "/forfeit" before countdown reached 0
86    uint64 guid;
87    recvPacket >> guid;
88
89    GetPlayer()->DuelComplete(DUEL_INTERUPTED);
90}
Note: See TracBrowser for help on using the browser.