FEAT: Player data saving/loading

This commit is contained in:
Kolyah35
2026-03-27 21:26:25 +03:00
parent 6957f144e1
commit 61a2349b8b
7 changed files with 146 additions and 3 deletions

View File

@@ -3,13 +3,13 @@
#include "../Packet.h"
#include "world/entity/player/Inventory.h"
#include "world/inventory/FillingContainer.h"
#include <array>
class SendInventoryPacket: public Packet
{
public:
SendInventoryPacket()
{
}
SendInventoryPacket() {}
SendInventoryPacket(Player* player, bool dropItems)
: entityId(player->entityId),
@@ -22,10 +22,15 @@ public:
ItemInstance* item = inv->getItem(i);
items.push_back(item? *item : ItemInstance());
}
for (int i = 0; i < NumArmorItems; ++i) {
ItemInstance* item = player->getArmor(i);
items.push_back(item? *item : ItemInstance());
}
for (int i = 0; i < inv->numLinkedSlots; ++i) {
linkedSlot[i] = inv->linkedSlots[i];
}
}
void write(RakNet::BitStream* bitStream)
@@ -40,6 +45,13 @@ public:
// Armor
for (int i = 0; i < NumArmorItems; ++i)
PacketUtil::writeItemInstance(items[i + numItems], bitStream);
int lSlots = Inventory::MAX_SELECTION_SIZE;
// Linked slots
bitStream->Write(lSlots);
for (int i = 0; i < lSlots; ++i)
bitStream->Write(linkedSlot[i]);
}
void read(RakNet::BitStream* bitStream)
@@ -51,6 +63,12 @@ public:
// Inventory, Armor
for (int i = 0; i < numItems + NumArmorItems; ++i)
items.push_back(PacketUtil::readItemInstance(bitStream));
// Linked slots
int lSlots = 0;
bitStream->Read(lSlots);
for (int i = 0; i < lSlots; ++i)
bitStream->Read(linkedSlot[i]);
}
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
@@ -63,6 +81,8 @@ public:
short numItems;
unsigned char extra;
std::array<FillingContainer::LinkedSlot, Inventory::MAX_SELECTION_SIZE> linkedSlot;
static const int ExtraDrop = 1;
static const int NumArmorItems = 4;
};