Skip to content

Commit

Permalink
Core/Misc: Reduce code differences between branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Feb 2, 2025
1 parent 7782a17 commit 00875fe
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 55 deletions.
56 changes: 31 additions & 25 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16674,14 +16674,17 @@ void Player::SendQuestReward(Quest const* quest, uint32 XP) const
{
uint32 questId = quest->GetQuestId();
sGameEventMgr->HandleQuestComplete(questId);
WorldPacket data(SMSG_QUESTGIVER_QUEST_COMPLETE, (4+4+4+4+4));
data << uint32(questId);

uint32 xp;

if (!IsMaxLevel())
data << uint32(XP);
xp = XP;
else
data << uint32(0);
xp = 0;

WorldPacket data(SMSG_QUESTGIVER_QUEST_COMPLETE, (4+4+4+4+4));
data << uint32(questId);
data << uint32(xp);
data << uint32(quest->GetRewOrReqMoney(this));
data << uint32(10 * quest->CalculateHonorGain(GetQuestLevel(quest)));
data << uint32(quest->GetBonusTalents()); // bonus talents
Expand Down Expand Up @@ -20365,7 +20368,7 @@ void Player::SendResetInstanceFailed(uint32 reason, uint32 MapId) const
// 1: There are players offline in your party.
// 2>: There are players in your party attempting to zone into an instance.
*/
WorldPacket data(SMSG_INSTANCE_RESET_FAILED, 4);
WorldPacket data(SMSG_INSTANCE_RESET_FAILED, 8);
data << uint32(reason);
data << uint32(MapId);
SendDirectMessage(&data);
Expand Down Expand Up @@ -26215,6 +26218,26 @@ PetStable& Player::GetOrInitPetStable()
return *m_petStable;
}

void Player::SendItemRefundResult(Item* item, ItemExtendedCostEntry const* iece, uint8 error) const
{
WorldPacket data(SMSG_ITEM_REFUND_RESULT, 8 + 4 + 4 + 4 + 4 + 4 * 4 + 4 * 4);
data << uint64(item->GetGUID()); // item guid
data << uint32(error); // 0, or error code
if (!error)
{
data << uint32(item->GetPaidMoney()); // money cost
data << uint32(iece->HonorPoints); // honor point cost
data << uint32(iece->ArenaPoints); // arena point cost
for (uint8 i = 0; i < MAX_ITEM_EXTENDED_COST_REQUIREMENTS; ++i) // item cost data
{
data << uint32(iece->ItemID[i]);
data << uint32(iece->ItemCount[i]);
}
}

SendDirectMessage(&data);
}

void Player::RefundItem(Item* item)
{
if (!item->IsRefundable())
Expand All @@ -26226,10 +26249,7 @@ void Player::RefundItem(Item* item)
if (item->IsRefundExpired()) // item refund has expired
{
item->SetNotRefundable(this);
WorldPacket data(SMSG_ITEM_REFUND_RESULT, 8+4);
data << uint64(item->GetGUID()); // Guid
data << uint32(10); // Error!
SendDirectMessage(&data);
SendItemRefundResult(item, nullptr, 10);
return;
}

Expand Down Expand Up @@ -26267,25 +26287,11 @@ void Player::RefundItem(Item* item)

if (store_error)
{
WorldPacket data(SMSG_ITEM_REFUND_RESULT, 8+4);
data << uint64(item->GetGUID()); // Guid
data << uint32(10); // Error!
SendDirectMessage(&data);
SendItemRefundResult(item, iece, 10);
return;
}

WorldPacket data(SMSG_ITEM_REFUND_RESULT, 8+4+4+4+4+4*4+4*4);
data << uint64(item->GetGUID()); // item guid
data << uint32(0); // 0, or error code
data << uint32(item->GetPaidMoney()); // money cost
data << uint32(iece->HonorPoints); // honor point cost
data << uint32(iece->ArenaPoints); // arena point cost
for (uint8 i = 0; i < MAX_ITEM_EXTENDED_COST_REQUIREMENTS; ++i) // item cost data
{
data << uint32(iece->ItemID[i]);
data << uint32(iece->ItemCount[i]);
}
SendDirectMessage(&data);
SendItemRefundResult(item, iece, 0);

uint32 moneyRefund = item->GetPaidMoney(); // item-> will be invalidated in DestroyItem

Expand Down
2 changes: 2 additions & 0 deletions src/server/game/Entities/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct CharTitlesEntry;
struct ChatChannelsEntry;
struct CreatureTemplate;
struct FactionEntry;
struct ItemExtendedCostEntry;
struct ItemSetEffect;
struct ItemTemplate;
struct Loot;
Expand Down Expand Up @@ -2496,6 +2497,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
GuidSet m_refundableItems;
void SendRefundInfo(Item* item);
void RefundItem(Item* item);
void SendItemRefundResult(Item* item, ItemExtendedCostEntry const* iece, uint8 error) const;

// know currencies are not removed at any point (0 displayed)
void AddKnownCurrency(uint32 itemId);
Expand Down
36 changes: 16 additions & 20 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11100,8 +11100,9 @@ bool Unit::InitTamedPet(Pet* pet, uint8 level, uint32 spell_id)
// only if not player and not controlled by player pet. And not at BG
if ((durabilityLoss && !player && !victim->ToPlayer()->InBattleground()) || (player && sWorld->getBoolConfig(CONFIG_DURABILITY_LOSS_IN_PVP)))
{
TC_LOG_DEBUG("entities.unit", "We are dead, losing {} percent durability", sWorld->getRate(RATE_DURABILITY_LOSS_ON_DEATH));
plrVictim->DurabilityLossAll(sWorld->getRate(RATE_DURABILITY_LOSS_ON_DEATH), false);
double baseLoss = sWorld->getRate(RATE_DURABILITY_LOSS_ON_DEATH);
TC_LOG_DEBUG("entities.unit", "We are dead, losing {} percent durability", baseLoss);
plrVictim->DurabilityLossAll(baseLoss, false);
// durability lost message
plrVictim->SendDurabilityLoss();
}
Expand Down Expand Up @@ -12210,6 +12211,17 @@ void Unit::UpdateObjectVisibility(bool forced)
}
}

void Unit::SendMoveKnockBack(Player* player, float speedXY, float speedZ, float vcos, float vsin)
{
WorldPacket data(SMSG_MOVE_KNOCK_BACK, (8 + 4 + 4 + 4 + 4 + 4));
data << GetPackGUID();
data << uint32(0); // counter
data << TaggedPosition<Position::XY>(vcos, vsin);
data << float(speedXY); // Horizontal speed
data << float(speedZ); // Z Movement speed (vertical)
player->SendDirectMessage(&data);
}

void Unit::KnockbackFrom(float x, float y, float speedXY, float speedZ)
{
if (IsMovedByServer())
Expand All @@ -12220,15 +12232,7 @@ void Unit::KnockbackFrom(float x, float y, float speedXY, float speedZ)
{
float vcos, vsin;
GetSinCos(x, y, vsin, vcos);

WorldPacket data(SMSG_MOVE_KNOCK_BACK, (8 + 4 + 4 + 4 + 4 + 4));
data << GetPackGUID();
data << uint32(0); // counter
data << TaggedPosition<Position::XY>(vcos, vsin);
data << float(speedXY); // Horizontal speed
data << float(-speedZ); // Z Movement speed (vertical)

GetGameClientMovingMe()->SendDirectMessage(&data);
SendMoveKnockBack(GetGameClientMovingMe()->GetBasePlayer(), speedXY, -speedZ, vcos, vsin);

if (HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED) || HasAuraType(SPELL_AURA_FLY))
SetCanFly(true, true);
Expand Down Expand Up @@ -12474,15 +12478,7 @@ void Unit::JumpTo(float speedXY, float speedZ, bool forward, Optional<Position>
{
float vcos = std::cos(angle+GetOrientation());
float vsin = std::sin(angle+GetOrientation());

WorldPacket data(SMSG_MOVE_KNOCK_BACK, (8+4+4+4+4+4));
data << GetPackGUID();
data << uint32(0); // Sequence
data << TaggedPosition<Position::XY>(vcos, vsin);
data << float(speedXY); // Horizontal speed
data << float(-speedZ); // Z Movement speed (vertical)

ToPlayer()->SendDirectMessage(&data);
SendMoveKnockBack(ToPlayer(), speedXY, -speedZ, vcos, vsin);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,7 @@ class TC_GAME_API Unit : public WorldObject
void UpdateOrientation(float orientation);
void UpdateHeight(float newZ);

void SendMoveKnockBack(Player* player, float speedXY, float speedZ, float vcos, float vsin);
void KnockbackFrom(float x, float y, float speedXY, float speedZ);
void JumpTo(float speedXY, float speedZ, bool forward = true, Optional<Position> dest = {});
void JumpTo(WorldObject* obj, float speedZ, bool withOrientation = false);
Expand Down
10 changes: 5 additions & 5 deletions src/server/game/Handlers/ArenaTeamHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void WorldSession::HandleArenaTeamLeaderOpcode(WorldPacket& recvData)

void WorldSession::SendArenaTeamCommandResult(uint32 teamAction, const std::string& team, const std::string& player, uint32 errorId)
{
WorldPacket data(SMSG_ARENA_TEAM_COMMAND_RESULT, 4+team.length()+1+player.length()+1+4);
WorldPacket data(SMSG_ARENA_TEAM_COMMAND_RESULT, 4 + team.length() + 1 + player.length() + 1 + 4);
data << uint32(teamAction);
data << team;
data << player;
Expand All @@ -413,10 +413,10 @@ void WorldSession::SendArenaTeamCommandResult(uint32 teamAction, const std::stri

void WorldSession::SendNotInArenaTeamPacket(uint8 type)
{
WorldPacket data(SMSG_ARENA_ERROR, 4+1); // 886 - You are not in a %uv%u arena team
uint32 unk = 0;
data << uint32(unk); // unk(0)
if (!unk)
WorldPacket data(SMSG_ARENA_ERROR, 4+1);
uint32 error = 0;
data << uint32(error); // 0 = ERR_ARENA_NO_TEAM_II, 1 = ERR_ARENA_EXPIRED_CAIS, 2 = ERR_LFG_CANT_USE_BATTLEGROUND
if (!error)
data << uint8(type); // team type (2=2v2, 3=3v3, 5=5v5), can be used for custom types...
SendPacket(&data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Handlers/CharacterHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ void WorldSession::HandleAlterAppearance(WorldPacket& recvData)

// 0 - ok
// 1, 3 - not enough money
// 2 - you have to seat on barber chair
// 2 - you have to sit on barber chair
if (!_player->HasEnoughMoney(cost))
{
SendBarberShopResult(BARBER_SHOP_RESULT_NO_MONEY);
Expand Down
4 changes: 1 addition & 3 deletions src/server/game/Handlers/GroupHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,15 @@ void WorldSession::HandleRaidTargetUpdateOpcode(WorldPacket& recvData)
if (!group)
return;

uint8 x;
uint8 x;
recvData >> x;

/** error handling **/
/********************/

// everything's fine, do it
if (x == 0xFF) // target icon request
{
group->SendTargetIconList(this);
}
else // target icon update
{
if (group->isRaidGroup() && !group->IsLeader(GetPlayer()->GetGUID()) && !group->IsAssistant(GetPlayer()->GetGUID()))
Expand Down
5 changes: 5 additions & 0 deletions src/server/game/Movement/Spline/MoveSplineInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ namespace Movement
args.path[1] = transform(dest);
}

void MoveSplineInit::SetFall()
{
args.flags.EnableFalling();
}

Vector3 TransportPathTransform::operator()(Vector3 input)
{
if (_transformForTransport)
Expand Down
1 change: 0 additions & 1 deletion src/server/game/Movement/Spline/MoveSplineInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ namespace Movement
inline void MoveSplineInit::SetWalk(bool enable) { args.walk = enable; }
inline void MoveSplineInit::SetSmooth() { args.flags.EnableCatmullRom(); }
inline void MoveSplineInit::SetCyclic() { args.flags.cyclic = true; }
inline void MoveSplineInit::SetFall() { args.flags.EnableFalling(); }
inline void MoveSplineInit::SetVelocity(float vel) { args.velocity = vel; args.HasVelocity = true; }
inline void MoveSplineInit::SetBackward() { args.flags.backward = true; }
inline void MoveSplineInit::SetTransportEnter() { args.flags.EnableTransportEnter(); }
Expand Down

0 comments on commit 00875fe

Please sign in to comment.