TrinityCore
Loading...
Searching...
No Matches
MovementPacketBuilder.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
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
19#include "ByteBuffer.h"
20#include "MoveSpline.h"
21#include "Position.h"
22
23namespace Movement
24{
25 inline void operator<<(ByteBuffer& b, Vector3 const& v)
26 {
27 b << v.x << v.y << v.z;
28 }
29
30 inline void operator>>(ByteBuffer& b, Vector3& v)
31 {
32 b >> v.x >> v.y >> v.z;
33 }
34
43
45 {
46 MoveSplineFlag splineflags = move_spline.splineflags;
47
48 data << uint8(0); // sets/unsets MOVEMENTFLAG2_UNK7 (0x40)
49 data << move_spline.spline.getPoint(move_spline.spline.first());
50 data << move_spline.GetId();
51
52 switch (splineflags & MoveSplineFlag::Mask_Final_Facing)
53 {
56 data << move_spline.facing.target;
57 break;
60 data << move_spline.facing.angle;
61 break;
64 data << move_spline.facing.f.x << move_spline.facing.f.y << move_spline.facing.f.z;
65 break;
66 default:
67 data << uint8(MonsterMoveNormal);
68 break;
69 }
70
71 data << uint32(splineflags & uint32(~MoveSplineFlag::Mask_No_Monster_Move));
72
73 if (splineflags.animation)
74 {
75 data << splineflags.animTier;
76 data << move_spline.effect_start_time;
77 }
78
79 data << move_spline.Duration();
80
81 if (splineflags.parabolic)
82 {
83 data << move_spline.vertical_acceleration;
84 data << move_spline.effect_start_time;
85 }
86 }
87
88 void PacketBuilder::WriteStopMovement(G3D::Vector3 const& pos, uint32 splineId, ByteBuffer& data)
89 {
90 data << uint8(0); // sets/unsets MOVEMENTFLAG2_UNK7 (0x40)
91 data << pos;
92 data << splineId;
93 data << uint8(MonsterMoveStop);
94 }
95
96 void WriteLinearPath(Spline<int32> const& spline, ByteBuffer& data)
97 {
98 uint32 last_idx = spline.getPointCount() - 3;
99 G3D::Vector3 const* real_path = &spline.getPoint(1);
100
101 data << last_idx;
102 data << real_path[last_idx]; // destination
103 if (last_idx > 1)
104 {
105 G3D::Vector3 middle = (real_path[0] + real_path[last_idx]) / 2.f;
106 G3D::Vector3 offset;
107 // first and last points already appended
108 for (uint32 i = 1; i < last_idx; ++i)
109 {
110 offset = middle - real_path[i];
111 data << TaggedPosition<Position::PackedXYZ>(offset.x, offset.y, offset.z);
112 }
113 }
114 }
115
117 {
118 uint32 count = spline.getPointCount() - 3;
119 data << count;
120 data.append<G3D::Vector3>(&spline.getPoint(2), count);
121 }
122
124 {
125 uint32 count = spline.getPointCount() - 4;
126 data << count;
127 data.append<Vector3>(&spline.getPoint(2), count);
128 }
129
131 {
132 WriteCommonMonsterMovePart(move_spline, data);
133
134 const Spline<int32>& spline = move_spline.spline;
135 MoveSplineFlag splineflags = move_spline.splineflags;
136 if (splineflags & MoveSplineFlag::Mask_CatmullRom)
137 {
138 if (splineflags.cyclic)
139 WriteCatmullRomCyclicPath(spline, data);
140 else
141 WriteCatmullRomPath(spline, data);
142 }
143 else
144 WriteLinearPath(spline, data);
145 }
146
147 void PacketBuilder::WriteCreate(MoveSpline const& move_spline, ByteBuffer& data)
148 {
149 //WriteClientStatus(mov, data);
150 //data.append<float>(&mov.m_float_values[SpeedWalk], SpeedMaxCount);
151 //if (mov.SplineEnabled())
152 {
153 MoveSplineFlag const& splineFlags = move_spline.splineflags;
154
155 data << splineFlags.raw();
156
157 if (splineFlags.final_angle)
158 {
159 data << move_spline.facing.angle;
160 }
161 else if (splineFlags.final_target)
162 {
163 data << move_spline.facing.target;
164 }
165 else if (splineFlags.final_point)
166 {
167 data << move_spline.facing.f.x << move_spline.facing.f.y << move_spline.facing.f.z;
168 }
169
170 data << move_spline.timePassed();
171 data << move_spline.Duration();
172 data << move_spline.GetId();
173
174 data << float(1.f); // splineInfo.duration_mod; added in 3.1
175 data << float(1.f); // splineInfo.duration_mod_next; added in 3.1
176
177 data << move_spline.vertical_acceleration; // added in 3.1
178 data << move_spline.effect_start_time; // added in 3.1
179
180 uint32 nodes = move_spline.getPath().size();
181 data << nodes;
182 data.append<G3D::Vector3>(&move_spline.getPath()[0], nodes);
183 data << uint8(move_spline.spline.mode()); // added in 3.1
184 data << (move_spline.isCyclic() ? G3D::Vector3::zero() : move_spline.FinalDestination());
185 }
186 }
187}
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
void append(T value)
Definition ByteBuffer.h:129
bool isCyclic() const
Definition MoveSpline.h:122
uint32 GetId() const
Definition MoveSpline.h:120
MySpline::ControlArray const & getPath() const
Definition MoveSpline.h:78
int32 timePassed() const
Definition MoveSpline.h:88
Vector3 FinalDestination() const
Definition MoveSpline.h:124
int32 Duration() const
Definition MoveSpline.h:89
MoveSplineFlag splineflags
Definition MoveSpline.h:62
static void WriteCreate(MoveSpline const &mov, ByteBuffer &data)
static void WriteStopMovement(G3D::Vector3 const &loc, uint32 splineId, ByteBuffer &data)
static void WriteCommonMonsterMovePart(MoveSpline const &mov, ByteBuffer &data)
static void WriteMonsterMove(MoveSpline const &mov, ByteBuffer &data)
index_type first() const
Definition Spline.h:108
Vector3 const & getPoint(index_type i) const
Definition Spline.h:117
index_type getPointCount() const
Definition Spline.h:116
EvaluationMode mode() const
Definition Spline.h:112
void WriteCatmullRomPath(Spline< int32 > const &spline, ByteBuffer &data)
void operator<<(ByteBuffer &b, Vector3 const &v)
void WriteLinearPath(Spline< int32 > const &spline, ByteBuffer &data)
void operator>>(ByteBuffer &b, Vector3 &v)
void WriteCatmullRomCyclicPath(Spline< int32 > const &spline, ByteBuffer &data)
struct Movement::FacingInfo::@263 f