Core/Packets: converted more packets to class

This commit is contained in:
Ovahlord committed 2020-10-23 12:30:45 +02:00
1 parent 23d56d3bc6
commit ac8741e3bc
11 files changed
+189 -58

No files matched your search

+37 -48
View File
@@ -34,8 +34,10 @@
#include "ChannelMgr.h"
#include "CharacterCache.h"
#include "CharacterDatabaseCleaner.h"
#include "CharacterPackets.h"
#include "Chat.h"
#include "CinematicMgr.h"
#include "CombatLogPackets.h"
#include "Common.h"
#include "ConditionMgr.h"
#include "CreatureAI.h"
@@ -728,13 +730,13 @@ uint32 Player::EnvironmentalDamage(EnviromentalDamage type, uint32 damage)
DealDamageMods(this, damage, &absorb);
WorldPacket data(SMSG_ENVIRONMENTALDAMAGELOG, (21));
data << uint64(GetGUID());
data << uint8(type != DAMAGE_FALL_TO_VOID ? type : DAMAGE_FALL);
data << uint32(damage);
data << uint32(absorb);
data << uint32(resist);
SendMessageToSet(&data, true);
WorldPackets::CombatLog::EnvironmentalDamageLog environmentalDamageLog;
environmentalDamageLog.Victim = GetGUID();
environmentalDamageLog.Type = type != DAMAGE_FALL_TO_VOID ? type : DAMAGE_FALL;
environmentalDamageLog.Amount = damage;
environmentalDamageLog.Absorbed = absorb;
environmentalDamageLog.Resisted = resist;
SendMessageToSet(environmentalDamageLog.Write(), true);
uint32 final_damage = DealDamage(this, damage, nullptr, SELF_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, nullptr, false);
@@ -2218,25 +2220,6 @@ void Player::RemoveFromGroup(Group* group, ObjectGuid guid, RemoveMethod method
group->RemoveMember(guid, method, kicker, reason);
}
void Player::SendLogXPGain(uint32 GivenXP, Unit* victim, uint32 BonusXP, bool recruitAFriend, float /*group_rate*/) const
{
WorldPacket data(SMSG_LOG_XPGAIN, 21); // guess size?
data << uint64(victim ? victim->GetGUID() : ObjectGuid::Empty);
data << uint32(GivenXP + BonusXP); // given experience
data << uint8(victim ? 0 : 1); // 00-kill_xp type, 01-non_kill_xp type
if (victim)
{
data << uint32(GivenXP); // experience without bonus
// should use group_rate here but can't figure out how
data << float(1); // 1 - none 0 - 100% group bonus output
}
data << uint8(recruitAFriend ? 1 : 0); // does the GivenXP include a RaF bonus?
SendDirectMessage(&data);
}
void Player::GiveXP(uint32 xp, Unit* victim, float group_rate)
{
if (xp < 1)
@@ -2268,7 +2251,14 @@ void Player::GiveXP(uint32 xp, Unit* victim, float group_rate)
else
bonus_xp = victim ? GetXPRestBonus(xp) : 0; // XP resting bonus
SendLogXPGain(xp, victim, bonus_xp, recruitAFriend, group_rate);
WorldPackets::Character::LogXPGain packet;
packet.Victim = victim ? victim->GetGUID() : ObjectGuid::Empty;
packet.Original = xp + bonus_xp;
packet.Reason = victim ? LOG_XP_REASON_KILL : LOG_XP_REASON_NO_KILL;
packet.Amount = xp;
packet.GroupBonus = group_rate;
packet.ReferAFriendBonusType = recruitAFriend ? 1 : 0;
SendDirectMessage(packet.Write());
uint32 curXP = GetUInt32Value(PLAYER_XP);
uint32 nextLvlXP = GetUInt32Value(PLAYER_NEXT_LEVEL_XP);
@@ -23453,10 +23443,10 @@ void Player::SendInitialPacketsAfterAddToMap()
{
for (uint8 i = 0; i < MAX_RUNES; i++)
{
WorldPacket data(SMSG_CONVERT_RUNE, 2);
data << uint8(i);
data << uint8(GetCurrentRune(i));
GetSession()->SendPacket(&data);
WorldPackets::Spells::ConvertRune packet;
packet.Index = i;
packet.Rune = GetCurrentRune(i);
SendDirectMessage(packet.Write());
}
}
@@ -25424,29 +25414,27 @@ void Player::ConvertRune(uint8 index, RuneType newType)
{
SetCurrentRune(index, newType);
WorldPacket data(SMSG_CONVERT_RUNE, 2);
data << uint8(index);
data << uint8(newType);
SendDirectMessage(&data);
WorldPackets::Spells::ConvertRune packet;
packet.Index = index;
packet.Rune = newType;
SendDirectMessage(packet.Write());
}
void Player::ResyncRunes(uint8 count)
{
WorldPacket data(SMSG_RESYNC_RUNES, 4 + count * 2);
data << uint32(count);
WorldPackets::Spells::ResyncRunes packet(count);
for (uint32 i = 0; i < count; ++i)
{
data << uint8(GetCurrentRune(i)); // rune type
data << uint8(255 - (GetRuneCooldown(i) * 51)); // passed cooldown time (0-255)
}
SendDirectMessage(&data);
packet.Runes.push_back({ uint8(GetCurrentRune(i)), uint8(255 - (GetRuneCooldown(i) * 51)) });
SendDirectMessage(packet.Write());
}
void Player::AddRunePower(uint8 mask)
{
WorldPacket data(SMSG_ADD_RUNE_POWER, 4);
data << uint32(mask); // mask (0x00-0x3F probably)
SendDirectMessage(&data);
WorldPackets::Spells::AddRunePower packet;
packet.AddedRunesMask = mask; // mask (0x00-0x3F probably)
SendDirectMessage(packet.Write());
}
static RuneType runeSlotTypes[MAX_RUNES] =
@@ -28101,9 +28089,10 @@ void Player::ReadMovementInfo(WorldPacket& data, MovementInfo* mi, Movement::Ext
void Player::SendSupercededSpell(uint32 oldSpell, uint32 newSpell) const
{
WorldPacket data(SMSG_SUPERCEDED_SPELL, 8);
data << uint32(newSpell) << uint32(oldSpell);
SendDirectMessage(&data);
WorldPackets::Spells::SupercededSpells packet;
packet.SpellID = newSpell;
packet.Superceded = oldSpell;
SendDirectMessage(packet.Write());
}
bool Player::ValidateAppearance(uint8 race, uint8 class_, uint8 gender, uint8 hairID, uint8 hairColor, uint8 faceID, uint8 facialStyle, uint8 skinColor, bool create /*=false*/)
+6 -1
View File
@@ -869,6 +869,12 @@ enum PlayerCommandStates
CHEAT_WATERWALK = 0x10
};
enum PlayerLogXPReason : uint8
{
LOG_XP_REASON_KILL = 0,
LOG_XP_REASON_NO_KILL = 1
};
struct PlayerPetData
{
uint32 PetId;
@@ -1853,7 +1859,6 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) const override;
void DestroyForPlayer(Player* target, bool onDeath = false) const override;
void SendLogXPGain(uint32 GivenXP, Unit* victim, uint32 BonusXP, bool recruitAFriend = false, float group_rate=1.0f) const;
// notifiers
void SendAttackSwingCantAttack() const;
@@ -287,3 +287,18 @@ void WorldPackets::Character::PlayerLogin::Read()
_worldPacket.ReadByteSeq(Guid[1]);
_worldPacket.ReadByteSeq(Guid[4]);
}
WorldPacket const* WorldPackets::Character::LogXPGain::Write()
{
_worldPacket << Victim;
_worldPacket << int32(Original);
_worldPacket << uint8(Reason);
if (!Reason)
{
_worldPacket << int32(Amount);
_worldPacket << float(GroupBonus);
}
_worldPacket << uint8(ReferAFriendBonusType);
return &_worldPacket;
}
@@ -218,6 +218,21 @@ namespace WorldPackets
ObjectGuid Guid; ///< Guid of the player that is logging in
};
class LogXPGain final : public ServerPacket
{
public:
LogXPGain() : ServerPacket(SMSG_LOG_XP_GAIN, 30) { }
WorldPacket const* Write() override;
ObjectGuid Victim;
int32 Original = 0;
int32 Amount = 0;
float GroupBonus = 0;
uint8 Reason = 0;
uint8 ReferAFriendBonusType = 0; // 1 - 300% of normal XP; 2 - 150% of normal XP
};
}
}
@@ -79,3 +79,14 @@ WorldPacket const* WorldPackets::CombatLog::SpellEnergizeLog::Write()
return &_worldPacket;
}
WorldPacket const* WorldPackets::CombatLog::EnvironmentalDamageLog::Write()
{
_worldPacket << Victim;
_worldPacket << uint8(Type);
_worldPacket << int32(Amount);
_worldPacket << int32(Absorbed);
_worldPacket << int32(Resisted);
return &_worldPacket;
}
@@ -87,6 +87,20 @@ namespace WorldPackets
int32 Type = 0;
int32 Amount = 0;
};
class EnvironmentalDamageLog final : public ServerPacket
{
public:
EnvironmentalDamageLog() : ServerPacket(SMSG_ENVIRONMENTAL_DAMAGE_LOG, 8 + 4 + 4 + 4 + 1) { }
WorldPacket const* Write() override;
ObjectGuid Victim;
int32 Amount = 0;
int32 Resisted = 0;
int32 Absorbed = 0;
uint8 Type = 0; ///< @see enum EnviromentalDamage
};
}
}
@@ -406,3 +406,38 @@ WorldPacket const* WorldPackets::Spells::SetSpellModifier::Write()
return &_worldPacket;
}
WorldPacket const* WorldPackets::Spells::ConvertRune::Write()
{
_worldPacket << uint8(Index);
_worldPacket << uint8(Rune);
return &_worldPacket;
}
WorldPacket const* WorldPackets::Spells::ResyncRunes::Write()
{
_worldPacket << uint32(Runes.size());
for (auto const& rune : Runes)
{
_worldPacket << uint8(rune.RuneType);
_worldPacket << uint8(rune.Cooldown);
}
return &_worldPacket;
}
WorldPacket const* WorldPackets::Spells::AddRunePower::Write()
{
_worldPacket << uint32(AddedRunesMask);
return &_worldPacket;
}
WorldPacket const* WorldPackets::Spells::SupercededSpells::Write()
{
_worldPacket << int32(SpellID);
_worldPacket << int32(Superceded);
return &_worldPacket;
}
@@ -350,6 +350,53 @@ namespace WorldPackets
std::vector<SpellModifier> Modifiers;
};
class ConvertRune final : public ServerPacket
{
public:
ConvertRune() : ServerPacket(SMSG_CONVERT_RUNE, 1 + 1) { }
WorldPacket const* Write() override;
uint8 Index = 0;
uint8 Rune = 0;
};
class ResyncRunes final : public ServerPacket
{
public:
struct ResyncRune
{
uint8 RuneType = 0;
uint8 Cooldown = 0;
};
ResyncRunes(size_t size) : ServerPacket(SMSG_RESYNC_RUNES, 4 + 2 * size) { }
WorldPacket const* Write() override;
std::vector<ResyncRune> Runes;
};
class AddRunePower final : public ServerPacket
{
public:
AddRunePower() : ServerPacket(SMSG_ADD_RUNE_POWER, 4) { }
WorldPacket const* Write() override;
uint32 AddedRunesMask = 0;
};
class SupercededSpells final : public ServerPacket
{
public:
SupercededSpells() : ServerPacket(SMSG_SUPERCEDED_SPELLS, 4 + 4) { }
WorldPacket const* Write() override;
int32 SpellID;
int32 Superceded;
};
}
}
@@ -18,11 +18,11 @@
#include "WorldStatePackets.h"
WorldPackets::WorldState::InitWorldStates::InitWorldStates()
: ServerPacket(SMSG_INIT_WORLD_STATES, 14) { }
: ServerPacket(SMSG_INIT_WORLD_STATES, 4 + 4 + 4 + 2) { }
WorldPacket const* WorldPackets::WorldState::InitWorldStates::Write()
{
_worldPacket.reserve(16 + Worldstates.size() * 8);
_worldPacket.reserve(4 + 4 + 4 + 2 + Worldstates.size() * 8);
_worldPacket << int32(MapID);
_worldPacket << int32(AreaID);
@@ -39,7 +39,7 @@ WorldPacket const* WorldPackets::WorldState::InitWorldStates::Write()
}
WorldPackets::WorldState::UpdateWorldState::UpdateWorldState()
: ServerPacket(SMSG_UPDATE_WORLD_STATE, 9) { }
: ServerPacket(SMSG_UPDATE_WORLD_STATE, 4 + 4 + 1) { }
WorldPacket const* WorldPackets::WorldState::UpdateWorldState::Write()
{
+3 -3
View File
@@ -831,7 +831,7 @@ void OpcodeTable::Initialize()
DEFINE_SERVER_OPCODE_HANDLER(SMSG_ENABLE_BARBER_SHOP, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_ENCHANTMENTLOG, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_ENUM_CHARACTERS_RESULT, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_ENVIRONMENTALDAMAGELOG, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_ENVIRONMENTAL_DAMAGE_LOG, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_EQUIPMENT_SET_LIST, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_EQUIPMENT_SET_SAVED, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_EQUIPMENT_SET_USE_RESULT, STATUS_NEVER, CONNECTION_TYPE_REALM);
@@ -994,7 +994,7 @@ void OpcodeTable::Initialize()
DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOGOUT_CANCEL_ACK, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOGOUT_COMPLETE, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOGOUT_RESPONSE, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOG_XPGAIN, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOG_XP_GAIN, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOOT_ALL_PASSED, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_COIN_REMOVED, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOOT_CONTENTS, STATUS_UNHANDLED, CONNECTION_TYPE_REALM);
@@ -1275,7 +1275,7 @@ void OpcodeTable::Initialize()
DEFINE_SERVER_OPCODE_HANDLER(SMSG_STREAMING_MOVIES, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_SUMMON_CANCEL, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_SUMMON_REQUEST, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_SUPERCEDED_SPELL, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_SUPERCEDED_SPELLS, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_SUPPRESS_NPC_GREETINGS, STATUS_UNHANDLED, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_SUSPEND_COMMS, STATUS_NEVER, CONNECTION_TYPE_REALM);
DEFINE_SERVER_OPCODE_HANDLER(SMSG_SUSPEND_TOKEN, STATUS_NEVER, CONNECTION_TYPE_INSTANCE);
+3 -3
View File
@@ -768,7 +768,7 @@ enum OpcodeServer
SMSG_ENABLE_BARBER_SHOP = 0x2D16,
SMSG_ENCHANTMENTLOG = 0x6035,
SMSG_ENUM_CHARACTERS_RESULT = 0x10B0,
SMSG_ENVIRONMENTALDAMAGELOG = 0x6C05,
SMSG_ENVIRONMENTAL_DAMAGE_LOG = 0x6C05,
SMSG_EQUIPMENT_SET_LIST = 0x2E04,
SMSG_EQUIPMENT_SET_SAVED = 0x2216,
SMSG_EQUIPMENT_SET_USE_RESULT = 0x2424,
@@ -942,7 +942,7 @@ enum OpcodeServer
SMSG_LOGOUT_CANCEL_ACK = 0x6514,
SMSG_LOGOUT_COMPLETE = 0x2137,
SMSG_LOGOUT_RESPONSE = 0x0524,
SMSG_LOG_XPGAIN = 0x4514,
SMSG_LOG_XP_GAIN = 0x4514,
SMSG_LOOT_ALL_PASSED = 0x6237,
SMSG_COIN_REMOVED = 0x2B37,
SMSG_LOOT_CONTENTS = 0x11B1,
@@ -1235,7 +1235,7 @@ enum OpcodeServer
SMSG_STREAMING_MOVIES = 0x15B7,
SMSG_SUMMON_CANCEL = 0x0B34,
SMSG_SUMMON_REQUEST = 0x2A07,
SMSG_SUPERCEDED_SPELL = 0x35B0,
SMSG_SUPERCEDED_SPELLS = 0x35B0,
SMSG_SUPPRESS_NPC_GREETINGS = 0x74B1,
SMSG_SUSPEND_COMMS = 0x4140,
SMSG_SUSPEND_TOKEN = 0x14B1,