Skip to content

Instantly share code, notes, and snippets.

@cyberium
Last active August 29, 2015 14:00
Show Gist options
  • Save cyberium/11393241 to your computer and use it in GitHub Desktop.
Save cyberium/11393241 to your computer and use it in GitHub Desktop.
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index f097131..6a382c5 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -8569,33 +8569,56 @@ void Unit::SetSpeedRate(UnitMoveType mtype, float rate, bool forced)
m_speed_rate[mtype] = rate;
propagateSpeedChange();
- const uint16 SetSpeed2Opc_table[MAX_MOVE_TYPE][2] =
- {
- {MSG_MOVE_SET_WALK_SPEED, SMSG_FORCE_WALK_SPEED_CHANGE},
- {MSG_MOVE_SET_RUN_SPEED, SMSG_FORCE_RUN_SPEED_CHANGE},
- {MSG_MOVE_SET_RUN_BACK_SPEED, SMSG_FORCE_RUN_BACK_SPEED_CHANGE},
- {MSG_MOVE_SET_SWIM_SPEED, SMSG_FORCE_SWIM_SPEED_CHANGE},
- {MSG_MOVE_SET_SWIM_BACK_SPEED, SMSG_FORCE_SWIM_BACK_SPEED_CHANGE},
- {MSG_MOVE_SET_TURN_RATE, SMSG_FORCE_TURN_RATE_CHANGE},
- {MSG_MOVE_SET_FLIGHT_SPEED, SMSG_FORCE_FLIGHT_SPEED_CHANGE},
- {MSG_MOVE_SET_FLIGHT_BACK_SPEED, SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE},
- {MSG_MOVE_SET_PITCH_RATE, SMSG_FORCE_PITCH_RATE_CHANGE},
+ const uint16 SetSpeed2Opc_table[MAX_MOVE_TYPE][3] =
+ {
+ {MSG_MOVE_SET_WALK_SPEED, SMSG_FORCE_WALK_SPEED_CHANGE, SMSG_SPLINE_SET_WALK_SPEED},
+ {MSG_MOVE_SET_RUN_SPEED, SMSG_FORCE_RUN_SPEED_CHANGE, SMSG_SPLINE_SET_RUN_SPEED},
+ {MSG_MOVE_SET_RUN_BACK_SPEED, SMSG_FORCE_RUN_BACK_SPEED_CHANGE, SMSG_SPLINE_SET_RUN_BACK_SPEED},
+ {MSG_MOVE_SET_SWIM_SPEED, SMSG_FORCE_SWIM_SPEED_CHANGE, SMSG_SPLINE_SET_SWIM_SPEED},
+ {MSG_MOVE_SET_SWIM_BACK_SPEED, SMSG_FORCE_SWIM_BACK_SPEED_CHANGE, SMSG_SPLINE_SET_SWIM_BACK_SPEED},
+ {MSG_MOVE_SET_TURN_RATE, SMSG_FORCE_TURN_RATE_CHANGE, SMSG_SPLINE_SET_TURN_RATE},
+ {MSG_MOVE_SET_FLIGHT_SPEED, SMSG_FORCE_FLIGHT_SPEED_CHANGE, SMSG_SPLINE_SET_FLIGHT_SPEED},
+ {MSG_MOVE_SET_FLIGHT_BACK_SPEED, SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE, SMSG_SPLINE_SET_FLIGHT_BACK_SPEED},
+ {MSG_MOVE_SET_PITCH_RATE, SMSG_FORCE_PITCH_RATE_CHANGE, SMSG_SPLINE_SET_PITCH_RATE},
};
- if (forced && GetTypeId() == TYPEID_PLAYER)
+ switch (GetTypeId())
{
- // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
- // and do it only for real sent packets and use run for run/mounted as client expected
- ++((Player*)this)->m_forced_speed_changes[mtype];
-
- WorldPacket data(Opcodes(SetSpeed2Opc_table[mtype][1]), 18);
- data << GetPackGUID();
- data << (uint32)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
- if (mtype == MOVE_RUN)
- data << uint8(0); // new 2.1.0
- data << float(GetSpeed(mtype));
+ case TYPEID_PLAYER:
+ {
+ if (forced)
+ {
+ // register forced speed changes for WorldSession::HandleForceSpeedChangeAck
+ // and do it only for real sent packets and use run for run/mounted as client expected
+ ++((Player*)this)->m_forced_speed_changes[mtype];
+
+ WorldPacket data(Opcodes(SetSpeed2Opc_table[mtype][1]), 18);
+ data << GetPackGUID();
+ data << (uint32)0; // moveEvent, NUM_PMOVE_EVTS = 0x39
+ if (mtype == MOVE_RUN)
+ data << uint8(0); // new 2.1.0
+ data << float(GetSpeed(mtype));
+ ((Player*)this)->GetSession()->SendPacket(&data);
+ }
- ((Player*)this)->GetSession()->SendPacket(&data);
+ WorldPacket data(Opcodes(SetSpeed2Opc_table[mtype][0]), 64);
+ data << GetPackGUID();
+ data << m_movementInfo;
+ data << float(GetSpeed(mtype));
+ SendMessageToSet(&data, false);
+ break;
+ }
+ case TYPEID_UNIT:
+ {
+ WorldPacket data(Opcodes(SetSpeed2Opc_table[mtype][2]), 12);
+ data << GetPackGUID();
+ data << float(GetSpeed(mtype));
+ SendMessageToSet(&data, false);
+ break;
+ }
+ default:
+ sLog.outError("SetSpeedRate: incorrect unit type(%u), must be player(%u) or unit(%u)!", uint32(GetTypeId()), uint32(TYPEID_PLAYER), uint32(TYPEID_UNIT));
+ break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment