mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-28 21:06:41 +00:00
[General] Modernize packet style for PlayerQuickKeys
This commit is contained in:
parent
4f98d67ed4
commit
0206d1813c
4 changed files with 23 additions and 32 deletions
|
@ -89,7 +89,7 @@ void GUIFunctions::ClearQuickKeyChanges(unsigned short pid) noexcept
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, );
|
GET_PLAYER(pid, player, );
|
||||||
|
|
||||||
player->quickKeyChanges.quickKeys.clear();
|
player->quickKeyChanges.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int GUIFunctions::GetQuickKeyChangesSize(unsigned short pid) noexcept
|
unsigned int GUIFunctions::GetQuickKeyChangesSize(unsigned short pid) noexcept
|
||||||
|
@ -97,7 +97,7 @@ unsigned int GUIFunctions::GetQuickKeyChangesSize(unsigned short pid) noexcept
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
return player->quickKeyChanges.count;
|
return player->quickKeyChanges.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GUIFunctions::GetQuickKeySlot(unsigned short pid, unsigned int index) noexcept
|
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;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
if (index >= player->quickKeyChanges.count)
|
if (index >= player->quickKeyChanges.size())
|
||||||
return 0;
|
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
|
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;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
if (index >= player->quickKeyChanges.count)
|
if (index >= player->quickKeyChanges.size())
|
||||||
return 0;
|
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
|
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;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, "");
|
GET_PLAYER(pid, player, "");
|
||||||
|
|
||||||
if (index >= player->quickKeyChanges.count)
|
if (index >= player->quickKeyChanges.size())
|
||||||
return "invalid";
|
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
|
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.type = type;
|
||||||
quickKey.itemId = itemId;
|
quickKey.itemId = itemId;
|
||||||
|
|
||||||
player->quickKeyChanges.quickKeys.push_back(quickKey);
|
player->quickKeyChanges.push_back(quickKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIFunctions::SendQuickKeyChanges(unsigned short pid) noexcept
|
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");
|
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());
|
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)
|
void LocalPlayer::sendQuickKey(unsigned short slot, int type, const std::string& itemId)
|
||||||
{
|
{
|
||||||
quickKeyChanges.quickKeys.clear();
|
quickKeyChanges.clear();
|
||||||
|
|
||||||
mwmp::QuickKey quickKey;
|
mwmp::QuickKey quickKey;
|
||||||
quickKey.slot = slot;
|
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_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());
|
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)->setPlayer(this);
|
||||||
getNetworking()->getPlayerPacket(ID_PLAYER_QUICKKEYS)->Send();
|
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
|
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
|
struct CellStateChanges
|
||||||
{
|
{
|
||||||
std::vector<CellState> cellStates;
|
std::vector<CellState> cellStates;
|
||||||
|
@ -238,7 +232,7 @@ namespace mwmp
|
||||||
|
|
||||||
InventoryChanges inventoryChanges;
|
InventoryChanges inventoryChanges;
|
||||||
SpellbookChanges spellbookChanges;
|
SpellbookChanges spellbookChanges;
|
||||||
QuickKeyChanges quickKeyChanges;
|
std::vector<QuickKey> quickKeyChanges;
|
||||||
std::vector<JournalItem> journalChanges;
|
std::vector<JournalItem> journalChanges;
|
||||||
FactionChanges factionChanges;
|
FactionChanges factionChanges;
|
||||||
TopicChanges topicChanges;
|
TopicChanges topicChanges;
|
||||||
|
|
|
@ -13,28 +13,25 @@ void PacketPlayerQuickKeys::Packet(RakNet::BitStream *bs, bool send)
|
||||||
{
|
{
|
||||||
PlayerPacket::Packet(bs, send);
|
PlayerPacket::Packet(bs, send);
|
||||||
|
|
||||||
|
uint32_t count;
|
||||||
|
|
||||||
if (send)
|
if (send)
|
||||||
player->quickKeyChanges.count = (unsigned int) (player->quickKeyChanges.quickKeys.size());
|
count = static_cast<uint32_t>(player->quickKeyChanges.size());
|
||||||
else
|
|
||||||
player->quickKeyChanges.quickKeys.clear();
|
|
||||||
|
|
||||||
RW(player->quickKeyChanges.count, send);
|
RW(count, send);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < player->quickKeyChanges.count; i++)
|
if (!send)
|
||||||
{
|
{
|
||||||
QuickKey quickKey;
|
player->quickKeyChanges.clear();
|
||||||
|
player->quickKeyChanges.resize(count);
|
||||||
if (send)
|
}
|
||||||
quickKey = player->quickKeyChanges.quickKeys.at(i);
|
|
||||||
|
|
||||||
|
for (auto &&quickKey : player->quickKeyChanges)
|
||||||
|
{
|
||||||
RW(quickKey.type, send);
|
RW(quickKey.type, send);
|
||||||
RW(quickKey.slot, send);
|
RW(quickKey.slot, send);
|
||||||
|
|
||||||
if (quickKey.type != QuickKey::UNASSIGNED)
|
if (quickKey.type != QuickKey::UNASSIGNED)
|
||||||
RW(quickKey.itemId, send);
|
RW(quickKey.itemId, send);
|
||||||
|
|
||||||
if (!send)
|
|
||||||
player->quickKeyChanges.quickKeys.push_back(quickKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue