root/trunk/src/game/CombatHandler.cpp @ 52

Revision 44, 3.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

Original author: Seline
Date: 2008-10-14 11:57:03-05:00

Line 
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 "Log.h"
23#include "WorldPacket.h"
24#include "WorldSession.h"
25#include "World.h"
26#include "ObjectAccessor.h"
27#include "CreatureAI.h"
28#include "ObjectDefines.h"
29
30void WorldSession::HandleAttackSwingOpcode( WorldPacket & recv_data )
31{
32    CHECK_PACKET_SIZE(recv_data,8);
33
34    uint64 guid;
35    recv_data >> guid;
36
37    DEBUG_LOG( "WORLD: Recvd CMSG_ATTACKSWING Message guidlow:%u guidhigh:%u", GUID_LOPART(guid), GUID_HIPART(guid) );
38
39    Unit *pEnemy = ObjectAccessor::GetUnit(*_player, guid);
40
41    if(!pEnemy)
42    {
43        if(!IS_UNIT_GUID(guid))
44            sLog.outError("WORLD: Object %u (TypeID: %u) isn't player, pet or creature",GUID_LOPART(guid),GuidHigh2TypeId(GUID_HIPART(guid)));
45        else
46            sLog.outError( "WORLD: Enemy %s %u not found",GetLogNameForGuid(guid),GUID_LOPART(guid));
47
48        // stop attack state at client
49        SendAttackStop(NULL);
50        return;
51    }
52
53    if(_player->IsFriendlyTo(pEnemy) || pEnemy->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE))
54    {
55        sLog.outError( "WORLD: Enemy %s %u is friendly",(IS_PLAYER_GUID(guid) ? "player" : "creature"),GUID_LOPART(guid));
56
57        // stop attack state at client
58        SendAttackStop(pEnemy);
59        return;
60    }
61
62    if(!pEnemy->isAlive())
63    {
64        // client can generate swing to known dead target if autoswitch between autoshot and autohit is enabled in client options
65        // stop attack state at client
66        SendAttackStop(pEnemy);
67        return;
68    }
69
70    _player->Attack(pEnemy,true);
71}
72
73void WorldSession::HandleAttackStopOpcode( WorldPacket & /*recv_data*/ )
74{
75    GetPlayer()->AttackStop();
76}
77
78void WorldSession::HandleSetSheathedOpcode( WorldPacket & recv_data )
79{
80    CHECK_PACKET_SIZE(recv_data,4);
81
82    uint32 sheathed;
83    recv_data >> sheathed;
84
85    //sLog.outDebug( "WORLD: Recvd CMSG_SETSHEATHED Message guidlow:%u value1:%u", GetPlayer()->GetGUIDLow(), sheathed );
86
87    GetPlayer()->SetSheath(sheathed);
88}
89
90void WorldSession::SendAttackStop(Unit const* enemy)
91{
92    WorldPacket data( SMSG_ATTACKSTOP, (4+20) );            // we guess size
93    data.append(GetPlayer()->GetPackGUID());
94    data.append(enemy ? enemy->GetPackGUID() : 0);          // must be packed guid
95    data << uint32(0);                                      // unk, can be 1 also
96    SendPacket(&data);
97}
Note: See TracBrowser for help on using the browser.