[General] Modernize packet style for PlayerQuickKeys

pull/546/head
David Cernat 5 years ago
parent 4f98d67ed4
commit 0206d1813c

@ -89,7 +89,7 @@ void GUIFunctions::ClearQuickKeyChanges(unsigned short pid) noexcept
Player *player;
GET_PLAYER(pid, player, );
player->quickKeyChanges.quickKeys.clear();
player->quickKeyChanges.clear();
}
unsigned int GUIFunctions::GetQuickKeyChangesSize(unsigned short pid) noexcept
@ -97,7 +97,7 @@ unsigned int GUIFunctions::GetQuickKeyChangesSize(unsigned short pid) noexcept
Player *player;
GET_PLAYER(pid, player, 0);
return player->quickKeyChanges.count;
return player->quickKeyChanges.size();
}
int GUIFunctions::GetQuickKeySlot(unsigned short pid, unsigned int index) noexcept
@ -105,10 +105,10 @@ int GUIFunctions::GetQuickKeySlot(unsigned short pid, unsigned int index) noexce
Player *player;
GET_PLAYER(pid, player, 0);
if (index >= player->quickKeyChanges.count)
if (index >= player->quickKeyChanges.size())
return 0;
return player->quickKeyChanges.quickKeys.at(index).slot;
return player->quickKeyChanges.at(index).slot;
}
int GUIFunctions::GetQuickKeyType(unsigned short pid, unsigned int index) noexcept
@ -116,10 +116,10 @@ int GUIFunctions::GetQuickKeyType(unsigned short pid, unsigned int index) noexce
Player *player;
GET_PLAYER(pid, player, 0);
if (index >= player->quickKeyChanges.count)
if (index >= player->quickKeyChanges.size())
return 0;
return player->quickKeyChanges.quickKeys.at(index).type;
return player->quickKeyChanges.at(index).type;
}
const char *GUIFunctions::GetQuickKeyItemId(unsigned short pid, unsigned int index) noexcept
@ -127,10 +127,10 @@ const char *GUIFunctions::GetQuickKeyItemId(unsigned short pid, unsigned int ind
Player *player;
GET_PLAYER(pid, player, "");
if (index >= player->quickKeyChanges.count)
if (index >= player->quickKeyChanges.size())
return "invalid";
return player->quickKeyChanges.quickKeys.at(index).itemId.c_str();
return player->quickKeyChanges.at(index).itemId.c_str();
}
void GUIFunctions::AddQuickKey(unsigned short pid, unsigned short slot, int type, const char* itemId) noexcept
@ -143,7 +143,7 @@ void GUIFunctions::AddQuickKey(unsigned short pid, unsigned short slot, int type
quickKey.type = type;
quickKey.itemId = itemId;
player->quickKeyChanges.quickKeys.push_back(quickKey);
player->quickKeyChanges.push_back(quickKey);
}
void GUIFunctions::SendQuickKeyChanges(unsigned short pid) noexcept

@ -1232,7 +1232,7 @@ void LocalPlayer::setQuickKeys()
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_PLAYER_QUICKKEYS from server");
for (const auto &quickKey : quickKeyChanges.quickKeys)
for (const auto &quickKey : quickKeyChanges)
{
LOG_APPEND(TimedLog::LOG_INFO, "- slot: %i, type: %i, itemId: %s", quickKey.slot, quickKey.type, quickKey.itemId.c_str());
@ -1494,7 +1494,7 @@ void LocalPlayer::sendSpellChange(std::string id, unsigned int action)
void LocalPlayer::sendQuickKey(unsigned short slot, int type, const std::string& itemId)
{
quickKeyChanges.quickKeys.clear();
quickKeyChanges.clear();
mwmp::QuickKey quickKey;
quickKey.slot = slot;
@ -1504,7 +1504,7 @@ void LocalPlayer::sendQuickKey(unsigned short slot, int type, const std::string&
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending ID_PLAYER_QUICKKEYS", itemId.c_str());
LOG_APPEND(TimedLog::LOG_INFO, "- slot: %i, type: %i, itemId: %s", quickKey.slot, quickKey.type, quickKey.itemId.c_str());
quickKeyChanges.quickKeys.push_back(quickKey);
quickKeyChanges.push_back(quickKey);
getNetworking()->getPlayerPacket(ID_PLAYER_QUICKKEYS)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_QUICKKEYS)->Send();

@ -141,12 +141,6 @@ namespace mwmp
int action; // 0 - Clear and set in entirety, 1 - Add spell, 2 - Remove spell
};
struct QuickKeyChanges
{
std::vector<QuickKey> quickKeys;
unsigned int count;
};
struct CellStateChanges
{
std::vector<CellState> cellStates;
@ -238,7 +232,7 @@ namespace mwmp
InventoryChanges inventoryChanges;
SpellbookChanges spellbookChanges;
QuickKeyChanges quickKeyChanges;
std::vector<QuickKey> quickKeyChanges;
std::vector<JournalItem> journalChanges;
FactionChanges factionChanges;
TopicChanges topicChanges;

@ -13,28 +13,25 @@ void PacketPlayerQuickKeys::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
uint32_t count;
if (send)
player->quickKeyChanges.count = (unsigned int) (player->quickKeyChanges.quickKeys.size());
else
player->quickKeyChanges.quickKeys.clear();
count = static_cast<uint32_t>(player->quickKeyChanges.size());
RW(player->quickKeyChanges.count, send);
RW(count, send);
for (unsigned int i = 0; i < player->quickKeyChanges.count; i++)
if (!send)
{
QuickKey quickKey;
if (send)
quickKey = player->quickKeyChanges.quickKeys.at(i);
player->quickKeyChanges.clear();
player->quickKeyChanges.resize(count);
}
for (auto &&quickKey : player->quickKeyChanges)
{
RW(quickKey.type, send);
RW(quickKey.slot, send);
if (quickKey.type != QuickKey::UNASSIGNED)
RW(quickKey.itemId, send);
if (!send)
player->quickKeyChanges.quickKeys.push_back(quickKey);
}
}

Loading…
Cancel
Save