OregonCore  revision be9e804-git
Your Favourite TBC server
packet_builder.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of the OregonCore 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 <https://www.gnu.org/licenses/>.
16 */
17 
18 #include "packet_builder.h"
19 #include "MoveSpline.h"
20 #include "WorldPacket.h"
21 
22 namespace Movement
23 {
24  inline void operator << (ByteBuffer& b, const Vector3& v)
25  {
26  b << v.x << v.y << v.z;
27  }
28 
29  inline void operator >> (ByteBuffer& b, Vector3& v)
30  {
31  b >> v.x >> v.y >> v.z;
32  }
33 
35  {
36  MoveSplineFlag splineflags = move_spline.splineflags;
37 
38  /*if (mov.IsBoarded())
39  {
40  data.SetOpcode(SMSG_MONSTER_MOVE_TRANSPORT);
41  data << mov.GetTransport()->Owner.GetPackGUID();
42  }*/
43 
44  data << move_spline.spline.getPoint(move_spline.spline.first());
45  data << move_spline.GetId();
46 
47  switch (splineflags & MoveSplineFlag::Mask_Final_Facing)
48  {
49  default:
50  data << uint8(MonsterMoveNormal);
51  break;
54  data << move_spline.facing.target;
55  break;
58  data << move_spline.facing.angle;
59  break;
62  data << move_spline.facing.f.x << move_spline.facing.f.y << move_spline.facing.f.z;
63  break;
64  }
65 
66  // add fake Enter_Cycle flag - needed for client-side cyclic movement (client will erase first spline vertex after first cycle done)
67  splineflags.enter_cycle = move_spline.isCyclic();
68  // add fake Runmode flag - client has strange issues without that flag
70  data << move_spline.Duration();
71  }
72 
73  void WriteLinearPath(const Spline<int32>& spline, ByteBuffer& data)
74  {
75  uint32 last_idx = spline.getPointCount() - 3;
76  const Vector3* real_path = &spline.getPoint(1);
77 
78  data << last_idx;
79  data << real_path[last_idx]; // destination
80  if (last_idx > 1)
81  {
82  Vector3 middle = (real_path[0] + real_path[last_idx]) / 2.f;
83  Vector3 offset;
84  // first and last points already appended
85  for (uint32 i = 1; i < last_idx; ++i)
86  {
87  offset = middle - real_path[i];
88  data.appendPackXYZ(offset.x, offset.y, offset.z);
89  }
90  }
91  }
92 
93  void WriteCatmullRomPath(const Spline<int32>& spline, ByteBuffer& data)
94  {
95  uint32 count = spline.getPointCount() - 3;
96  data << count;
97  data.append<Vector3>(&spline.getPoint(2), count);
98  }
99 
101  {
102  uint32 count = spline.getPointCount() - 3;
103  data << uint32(count + 1);
104  data << spline.getPoint(1); // fake point, client will erase it from the spline after first cycle done
105  data.append<Vector3>(&spline.getPoint(1), count);
106  }
107 
109  {
110  WriteCommonMonsterMovePart(move_spline, data);
111 
112  const Spline<int32>& spline = move_spline.spline;
113  MoveSplineFlag splineflags = move_spline.splineflags;
114  if (splineflags & MoveSplineFlag::Mask_CatmullRom)
115  {
116  if (splineflags.cyclic)
117  WriteCatmullRomCyclicPath(spline, data);
118  else
119  WriteCatmullRomPath(spline, data);
120  }
121  else
122  WriteLinearPath(spline, data);
123  }
124 
125  void PacketBuilder::WriteCreate(const MoveSpline& move_spline, ByteBuffer& data)
126  {
127  // WriteClientStatus(mov,data);
128  // data.append<float>(&mov.m_float_values[SpeedWalk], SpeedMaxCount);
129  // if (mov.SplineEnabled())
130  {
131  MoveSplineFlag splineFlags = move_spline.splineflags;
132 
133  data << splineFlags.raw();
134 
135  if (splineFlags.final_angle)
136  {
137  data << move_spline.facing.angle;
138  }
139  else if (splineFlags.final_target)
140  {
141  data << move_spline.facing.target;
142  }
143  else if (splineFlags.final_point)
144  {
145  data << move_spline.facing.f.x << move_spline.facing.f.y << move_spline.facing.f.z;
146  }
147 
148  data << move_spline.timePassed();
149  data << move_spline.Duration();
150  data << move_spline.GetId();
151 
152  uint32 nodes = move_spline.getPath().size();
153  data << nodes;
154  data.append<Vector3>(&move_spline.getPath()[0], nodes);
155  data << (move_spline.isCyclic() ? Vector3::zero() : move_spline.FinalDestination());
156  }
157  }
158 }
void operator<<(ByteBuffer &b, const Vector3 &v)
const Vector3 FinalDestination() const
Definition: MoveSpline.h:120
MoveSplineFlag splineflags
Definition: MoveSpline.h:67
index_type first() const
Definition: spline.h:103
void appendPackXYZ(float x, float y, float z)
Definition: ByteBuffer.h:393
static void WriteCommonMonsterMovePart(const MoveSpline &mov, WorldPacket &data)
void WriteLinearPath(const Spline< int32 > &spline, ByteBuffer &data)
struct Movement::FacingInfo::@96 f
ACE_UINT8 uint8
Definition: Define.h:73
const MySpline::ControlArray & getPath() const
Definition: MoveSpline.h:76
index_type getPointCount() const
Definition: spline.h:111
const Vector3 & getPoint(index_type i) const
Definition: spline.h:112
static void WriteMonsterMove(const MoveSpline &mov, WorldPacket &data)
int32 Duration() const
Definition: MoveSpline.h:124
void append(const std::string &str)
Definition: ByteBuffer.h:358
static void WriteCreate(const MoveSpline &mov, ByteBuffer &data)
void WriteCatmullRomCyclicPath(const Spline< int32 > &spline, ByteBuffer &data)
uint32 GetId() const
Definition: MoveSpline.h:116
FacingInfo facing
Definition: MoveSpline.h:63
int32 timePassed() const
Definition: MoveSpline.h:83
void WriteCatmullRomPath(const Spline< int32 > &spline, ByteBuffer &data)
ACE_UINT32 uint32
Definition: Define.h:71
bool isCyclic() const
Definition: MoveSpline.h:118
void operator>>(ByteBuffer &b, Vector3 &v)