TrinityCore
Loading...
Searching...
No Matches
MovementPacketSender.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "GameClient.h"
20#include "Player.h"
21#include "WorldPacket.h"
22#include "WorldSession.h"
23
24// SMSG_SPLINE_SET_* messages are for units controlled by the server.
25// SMSG_FORCE_*_SPEED_CHANGE messages are for units controlled by a player and require the client to respond with an ACK message.
26// MSG_MOVE_SET_*_SPEED is used to broadcast changes to observers of units controlled by a player
28{
38};
39
57
59{
60 GameClient* controller = unit->GetGameClientMovingMe();
61
62 ASSERT(controller);
63
64 uint32 mCounter = unit->GetMovementCounterAndInc();
65 PlayerMovementPendingChange pendingChange;
66 pendingChange.movementCounter = mCounter;
67 pendingChange.newValue = newSpeedFlat;
69 unit->PushPendingMovementChange(pendingChange);
70
71 WorldPacket data;
72 data.Initialize(moveTypeToOpcode[mtype][1], mtype != MOVE_RUN ? 8 + 4 + 4 : 8 + 4 + 1 + 4);
73 data << unit->GetPackGUID();
74 data << mCounter;
75 if (mtype == MOVE_RUN)
76 data << uint8(1); // unknown byte added in 2.1.0
77 data << newSpeedFlat;
78 controller->SendDirectMessage(&data);
79}
80
82{
83 GameClient* controller = unit->GetGameClientMovingMe();
84
85 ASSERT(controller);
86
87 WorldPacket data;
88 data.Initialize(moveTypeToOpcode[mtype][2], 8 + 30 + 4);
90 data << newSpeedFlat;
91 unit->SendMessageToSet(&data, controller->GetBasePlayer());
92}
93
94void MovementPacketSender::SendSpeedChangeToAll(Unit* unit, UnitMoveType mtype, float newSpeedFlat)
95{
96 GameClient* controller = unit->GetGameClientMovingMe();
97
98 ASSERT(!controller);
99
100 WorldPacket data;
101 data.Initialize(moveTypeToOpcode[mtype][0], 8 + 4);
102 data << unit->GetPackGUID();
103 data << newSpeedFlat;
104 unit->SendMessageToSet(&data, true);
105}
106
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
#define ASSERT
Definition Errors.h:68
#define MAX_MOVE_TYPE
UnitMoveType
@ MOVE_FLIGHT
@ MOVE_SWIM
@ MOVE_TURN_RATE
@ MOVE_FLIGHT_BACK
@ MOVE_SWIM_BACK
@ MOVE_RUN
@ MOVE_PITCH_RATE
@ MOVE_RUN_BACK
@ MOVE_WALK
MovementChangeType
Definition Unit.h:275
void SendDirectMessage(WorldPacket const *data) const
Player * GetBasePlayer() const
Definition GameClient.h:40
static void SendSpeedChangeToMover(Unit *unit, UnitMoveType mtype, float newRate)
static MovementChangeType GetChangeTypeByMoveType(UnitMoveType moveType)
static void SendSpeedChangeToObservers(Unit *unit, UnitMoveType mtype, float newRate)
static void SendSpeedChangeToAll(Unit *unit, UnitMoveType mtype, float newRate)
static Opcodes const moveTypeToOpcode[MAX_MOVE_TYPE][3]
PackedGuid const & GetPackGUID() const
Definition Object.h:80
Definition Unit.h:769
void PushPendingMovementChange(PlayerMovementPendingChange newChange)
Definition Unit.cpp:12960
GameClient * GetGameClientMovingMe() const
Definition Unit.h:1302
uint32 GetMovementCounterAndInc()
Definition Unit.h:1772
virtual void SendMessageToSet(WorldPacket const *data, bool self) const
Definition Object.cpp:1783
MovementInfo m_movementInfo
Definition Object.h:575
void Initialize(uint16 opcode, size_t newres=200)
Definition WorldPacket.h:73
static void WriteMovementInfo(WorldPacket *data, MovementInfo *mi)
Opcodes
Definition Opcodes.h:29
@ SMSG_FORCE_TURN_RATE_CHANGE
Definition Opcodes.h:763
@ MSG_MOVE_SET_SWIM_BACK_SPEED
Definition Opcodes.h:242
@ MSG_MOVE_SET_TURN_RATE
Definition Opcodes.h:245
@ SMSG_FORCE_WALK_SPEED_CHANGE
Definition Opcodes.h:759
@ SMSG_SPLINE_SET_FLIGHT_SPEED
Definition Opcodes.h:930
@ SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE
Definition Opcodes.h:928
@ MSG_MOVE_SET_PITCH_RATE
Definition Opcodes.h:1144
@ SMSG_SPLINE_SET_SWIM_SPEED
Definition Opcodes.h:797
@ SMSG_FORCE_RUN_SPEED_CHANGE
Definition Opcodes.h:255
@ SMSG_FORCE_SWIM_BACK_SPEED_CHANGE
Definition Opcodes.h:761
@ SMSG_SPLINE_SET_FLIGHT_BACK_SPEED
Definition Opcodes.h:931
@ SMSG_FORCE_RUN_BACK_SPEED_CHANGE
Definition Opcodes.h:257
@ SMSG_FORCE_FLIGHT_SPEED_CHANGE
Definition Opcodes.h:926
@ SMSG_FORCE_SWIM_SPEED_CHANGE
Definition Opcodes.h:259
@ MSG_MOVE_SET_RUN_SPEED
Definition Opcodes.h:234
@ MSG_MOVE_SET_FLIGHT_SPEED
Definition Opcodes.h:923
@ MSG_MOVE_SET_WALK_SPEED
Definition Opcodes.h:238
@ SMSG_SPLINE_SET_WALK_SPEED
Definition Opcodes.h:798
@ SMSG_SPLINE_SET_RUN_BACK_SPEED
Definition Opcodes.h:796
@ MSG_MOVE_SET_SWIM_SPEED
Definition Opcodes.h:240
@ MSG_MOVE_SET_FLIGHT_BACK_SPEED
Definition Opcodes.h:925
@ SMSG_SPLINE_SET_RUN_SPEED
Definition Opcodes.h:795
@ SMSG_FORCE_PITCH_RATE_CHANGE
Definition Opcodes.h:1145
@ SMSG_SPLINE_SET_TURN_RATE
Definition Opcodes.h:800
@ SMSG_SPLINE_SET_PITCH_RATE
Definition Opcodes.h:1147
@ SMSG_SPLINE_SET_SWIM_BACK_SPEED
Definition Opcodes.h:799
@ MSG_MOVE_SET_RUN_BACK_SPEED
Definition Opcodes.h:236
MovementChangeType movementChangeType
Definition Unit.h:306