Files
DarkflameServer/dGame/dComponents/ItemComponent.cpp
Aaron Kimbrell 260e6cb1b1 refactor(entity): each component type has an allocator, as the client
DoObjectComponentLoad walks the client's load order and calls the type's
allocator from a table, like ObjectLoader2, instead of one 76-case switch.
Components with rules of their own have a static Allocator (the client's
LWOxComponent::Allocator); the rest share a registry allocator. The load
state moves to ObjectLoadState.h so the allocators can take it.

Construction bytes are identical for all 15,962 LOTs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 08:11:58 -05:00

26 lines
1.1 KiB
C++

#include "ItemComponent.h"
#include "Entity.h"
#include "ObjectLoadState.h"
#include "PetComponent.h"
void ItemComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
// Live wrote the user-generated-content info on every construction: the model's userModelID (a brick built model,
// LOT 14), else no UGC id (items, reward models such as LOT 8069), moderation status NoStatus, no description.
outBitStream.Write(isConstruction);
if (isConstruction) {
outBitStream.Write<LWOOBJID>(m_Parent->GetVarAs<LWOOBJID>(u"userModelID")); // ug_id
outBitStream.Write<uint32_t>(0); // ug_moderation_status NoStatus
outBitStream.Write0(); // ug_description
}
}
void ItemComponent::Allocator(Entity& entity, ObjectLoadState& state) {
// A pet takes the item (and model) component away (LWOPetComponent::Factory); models keep theirs (live: an
// item block before the model's)
PetComponent* petComponent{};
const auto itemID = state.GetComponentID(eReplicaComponentType::ITEM);
if (itemID > 0 && !entity.TryGetComponent(eReplicaComponentType::PET, petComponent)) {
entity.AddComponent<ItemComponent>(itemID);
}
}