Skip to content

Commit

Permalink
[12111] Add Unit::KnockBackWithAngle function
Browse files Browse the repository at this point in the history
Also wrap up the packet sending for a knockbacked player to WorldSession::SendKnockBack

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
  • Loading branch information
Reamer authored and Schmoozerd committed Aug 23, 2012
1 parent e479a84 commit 493dfc2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/game/MovementHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,21 @@ void WorldSession::HandleMoveKnockBackAck(WorldPacket& recv_data)
mover->SendMessageToSetExcept(&data, _player);
}

void WorldSession::SendKnockBack(float angle, float horizontalSpeed, float verticalSpeed)
{
float vsin = sin(angle);
float vcos = cos(angle);

WorldPacket data(SMSG_MOVE_KNOCK_BACK, 9 + 4 + 4 + 4 + 4 + 4);
data << GetPlayer()->GetPackGUID();
data << uint32(0); // Sequence
data << float(vcos); // x direction
data << float(vsin); // y direction
data << float(horizontalSpeed); // Horizontal speed
data << float(-verticalSpeed); // Z Movement speed (vertical)
SendPacket(&data);
}

void WorldSession::HandleMoveHoverAck(WorldPacket& recv_data)
{
DEBUG_LOG("CMSG_MOVE_HOVER_ACK");
Expand Down
17 changes: 7 additions & 10 deletions src/game/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10675,22 +10675,19 @@ void Unit::SetFFAPvP(bool state)
void Unit::KnockBackFrom(Unit* target, float horizontalSpeed, float verticalSpeed)
{
float angle = this == target ? GetOrientation() + M_PI_F : target->GetAngle(this);
float vsin = sin(angle);
float vcos = cos(angle);
KnockBackWithAngle(angle, horizontalSpeed, verticalSpeed);
}

void Unit::KnockBackWithAngle(float angle, float horizontalSpeed, float verticalSpeed)
{
if (GetTypeId() == TYPEID_PLAYER)
{
WorldPacket data(SMSG_MOVE_KNOCK_BACK, 9 + 4 + 4 + 4 + 4 + 4);
data << GetPackGUID();
data << uint32(0); // Sequence
data << float(vcos); // x direction
data << float(vsin); // y direction
data << float(horizontalSpeed); // Horizontal speed
data << float(-verticalSpeed); // Z Movement speed (vertical)
((Player*)this)->GetSession()->SendPacket(&data);
((Player*)this)->GetSession()->SendKnockBack(angle, horizontalSpeed, verticalSpeed);
}
else
{
float vsin = sin(angle);
float vcos = cos(angle);
float moveTimeHalf = verticalSpeed / Movement::gravity;
float max_height = -Movement::computeFallElevation(moveTimeHalf, false, -verticalSpeed);

Expand Down
1 change: 1 addition & 0 deletions src/game/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void SetSpeedRate(UnitMoveType mtype, float rate, bool forced = false);

void KnockBackFrom(Unit* target, float horizontalSpeed, float verticalSpeed);
void KnockBackWithAngle(float angle, float horizontalSpeed, float verticalSpeed);

void _RemoveAllAuraMods();
void _ApplyAllAuraMods();
Expand Down
1 change: 1 addition & 0 deletions src/game/WorldSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ class MANGOS_DLL_SPEC WorldSession

// Knockback
void HandleMoveKnockBackAck(WorldPacket& recvPacket);
void SendKnockBack(float angle, float horizontalSpeed, float verticalSpeed);

void HandleMoveTeleportAckOpcode(WorldPacket& recvPacket);
void HandleForceSpeedChangeAckOpcodes(WorldPacket& recv_data);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12110"
#define REVISION_NR "12111"
#endif // __REVISION_NR_H__

0 comments on commit 493dfc2

Please sign in to comment.