/// <summary> /// Constructs a waypoint packet, starting with the given firstNode (until the end of the LinkedList). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="unit"></param> /// <param name="speed">The speed that the Unit should move with in yards/second</param> /// <param name="moveFlags"></param> /// <param name="firstNode"></param> /// <returns></returns> public static RealmPacketOut ConstructMultiWaypointMovePacket <T>(Unit unit, int speed, MonsterMoveFlags moveFlags, LinkedListNode <T> firstNode) where T : IPathVertex { RealmPacketOut writer = new RealmPacketOut((PacketId)RealmServerOpCode.SMSG_MONSTER_MOVE, 39 + firstNode.List.Count * 4 * 3); unit.EntityId.WritePacked((BinaryWriter)writer); writer.Write(false); writer.Write(unit.Position); writer.Write(Utility.GetSystemTime()); writer.Write((byte)0); writer.Write((uint)moveFlags); if (moveFlags.HasFlag((Enum)MonsterMoveFlags.Flag_0x200000)) { writer.Write((byte)0); writer.Write(0); } long position1 = writer.Position; writer.Position += 4L; if (moveFlags.HasFlag((Enum)MonsterMoveFlags.Flag_0x800)) { writer.Write(0.0f); writer.Write(0); } long position2 = writer.Position; writer.Position += 4L; int num1 = (int)(1000.0 * (double)unit.Position.GetDistance(firstNode.Value.Position) / (double)speed); int num2 = 0; LinkedListNode <T> linkedListNode = firstNode; while (true) { ++num2; writer.Write(linkedListNode.Value.Position); LinkedListNode <T> next = linkedListNode.Next; if (next != null) { num1 += (int)(1000.0 * (double)linkedListNode.Value.GetDistanceToNext() / (double)speed); linkedListNode = next; } else { break; } } writer.Position = position1; writer.Write(num1); writer.Position = position2; writer.Write(num2); return(writer); }
public static RealmPacketOut ConstructMultiWaypointMovePacket <T>(Unit movingUnit, uint moveTime, MonsterMoveFlags moveFlags, IEnumerable <T> waypoints) where T : IPathVertex { int num = waypoints.Count <T>(); RealmPacketOut writer = new RealmPacketOut((PacketId)RealmServerOpCode.SMSG_MONSTER_MOVE, 38 + num * 4 * 3); movingUnit.EntityId.WritePacked((BinaryWriter)writer); writer.Write(false); writer.Write(movingUnit.Position); writer.Write(Utility.GetSystemTime()); writer.Write((byte)0); writer.Write((uint)moveFlags); if (moveFlags.HasFlag((Enum)MonsterMoveFlags.Flag_0x200000)) { writer.Write((byte)0); writer.Write(0); } writer.Write(moveTime); if (moveFlags.HasFlag((Enum)MonsterMoveFlags.Flag_0x800)) { writer.Write(0.0f); writer.Write(0); } writer.Write(num); if (moveFlags.HasAnyFlag(MonsterMoveFlags.Flag_0x2000_FullPoints_1 | MonsterMoveFlags.Flag_0x40000_FullPoints_2)) { foreach (T waypoint in waypoints) { IPathVertex pathVertex = (IPathVertex)waypoint; writer.Write(pathVertex.Position); } } else { foreach (T waypoint in waypoints) { IPathVertex pathVertex = (IPathVertex)waypoint; writer.Write(pathVertex.Position.ToDeltaPacked(movingUnit.Position, waypoints.First <T>().Position)); } } return(writer); }
/// <summary> /// Constructs a waypoint packet, starting with the given firstNode (until the end of the LinkedList). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="unit"></param> /// <param name="speed">The speed that the Unit should move with in yards/second</param> /// <param name="moveFlags"></param> /// <param name="firstNode"></param> /// <returns></returns> public static RealmPacketOut ConstructMultiWaypointMovePacket <T>(Unit unit, int speed, MonsterMoveFlags moveFlags, LinkedListNode <T> firstNode) where T : IPathVertex { var packet = new RealmPacketOut(RealmServerOpCode.SMSG_MONSTER_MOVE, (9 + 1 + 12 + 4 + 1 + 4 + 4 + 4 + (firstNode.List.Count * 4 * 3))); unit.EntityId.WritePacked(packet); // 8 packet.Write(false); // unknown flag packet.Write(unit.Position); packet.Write(Utility.GetSystemTime()); packet.Write((byte)MonsterMoveType.Normal); packet.Write((uint)moveFlags); if (moveFlags.HasFlag(MonsterMoveFlags.Flag_0x200000)) { packet.Write((byte)0); packet.Write(0); } var timePos = packet.Position; packet.Position += 4; if (moveFlags.HasFlag(MonsterMoveFlags.Flag_0x800)) { packet.Write(0.0f); packet.Write(0); } var countPos = packet.Position; packet.Position += 4; var moveTime = (int)(1000 * unit.Position.GetDistance(firstNode.Value.Position) / speed); var count = 0; var current = firstNode; while (true) { count++; packet.Write(current.Value.Position); // + 12*numWaypoints var next = current.Next; if (next != null) { moveTime += (int)(1000 * current.Value.GetDistanceToNext() / speed); current = next; } else { break; } } packet.Position = timePos; packet.Write(moveTime); packet.Position = countPos; packet.Write(count); return(packet); }
public static RealmPacketOut ConstructMultiWaypointMovePacket <T>(Unit movingUnit, uint moveTime, MonsterMoveFlags moveFlags, IEnumerable <T> waypoints) where T : IPathVertex { var numWaypoints = waypoints.Count(); var packet = new RealmPacketOut(RealmServerOpCode.SMSG_MONSTER_MOVE, (9 + 12 + 4 + 1 + 4 + 4 + 4 + (numWaypoints * 4 * 3))); movingUnit.EntityId.WritePacked(packet); //if (movingUnit.IsOnTransport) //{ // packet.OpCode = RealmServerOpCode.SMSG_MONSTER_MOVE_TRANSPORT; // movingUnit.Transport.EntityId.WritePacked(packet); // packet.Write((byte)movingUnit.TransportSeat); //} packet.Write(false); // some boolean flag packet.Write(movingUnit.Position); // OnMonsterMove_serverLoc packet.Write(Utility.GetSystemTime()); const MonsterMoveType moveType = MonsterMoveType.Normal; packet.Write((byte)moveType); switch (moveType) { case MonsterMoveType.Normal: break; // TODO: implement other cases //case MonsterMoveType.Stop: // { // return packet; // } //case MonsterMoveType.FinalFacingPoint: // { // // OnMonsterMove_final_facingSpot // packet.Write(0.0f); // packet.Write(0.0f); // packet.Write(0.0f); // } //case MonsterMoveType.FinalFacingGuid: // { // packet.Write(0ul); // } //case MonsterMoveType.FinalFacingAngle: // { // // OnMonsterMove_final_facingAngle // packet.Write(movingUnit.Orientation); // } } packet.Write((uint)moveFlags); if (moveFlags.HasFlag(MonsterMoveFlags.Flag_0x200000)) { // TODO: what does this flag mean? packet.Write((byte)0); packet.Write(0); } packet.Write(moveTime); if (moveFlags.HasFlag(MonsterMoveFlags.Flag_0x800)) { // TODO: what does this flag mean? packet.Write(0.0f); packet.Write(0); } packet.Write(numWaypoints); if (moveFlags.HasAnyFlag(MonsterMoveFlags.Flag_0x2000_FullPoints_1 | MonsterMoveFlags.Flag_0x40000_FullPoints_2)) { foreach (IPathVertex waypoint in waypoints) { packet.Write(waypoint.Position); // + 12*numWaypoints } } else { // OnMonsterMove_pathPoints_compressed foreach (IPathVertex waypoint in waypoints) { packet.Write(waypoint.Position.ToDeltaPacked(movingUnit.Position, waypoints.First().Position)); // + 12*numWaypoints } } return(packet); }