2021-12-05 17:54:36 +00:00
|
|
|
#include "Item.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "../dWorldServer/ObjectIDManager.h"
|
|
|
|
#include "GeneralUtils.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "Game.h"
|
|
|
|
#include "dLogger.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "RenderComponent.h"
|
2022-09-02 18:49:19 +00:00
|
|
|
#include "PossessableComponent.h"
|
|
|
|
#include "CharacterComponent.h"
|
|
|
|
#include "eItemType.h"
|
2022-11-01 18:21:26 +00:00
|
|
|
#include "AssetManager.h"
|
2022-12-18 15:46:04 +00:00
|
|
|
#include "InventoryComponent.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "Loot.h"
|
2023-03-04 07:16:37 +00:00
|
|
|
#include "eReplicaComponentType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-17 14:36:21 +00:00
|
|
|
#include "CDBrickIDTableTable.h"
|
|
|
|
#include "CDObjectSkillsTable.h"
|
|
|
|
#include "CDComponentsRegistryTable.h"
|
|
|
|
#include "CDPackageComponentTable.h"
|
|
|
|
|
2022-04-23 12:13:06 +00:00
|
|
|
Item::Item(const LWOOBJID id, const LOT lot, Inventory* inventory, const uint32_t slot, const uint32_t count, const bool bound, const std::vector<LDFBaseData*>& config, const LWOOBJID parent, LWOOBJID subKey, eLootSourceType lootSourceType) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!Inventory::IsValidItem(lot)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
this->id = id;
|
|
|
|
this->lot = lot;
|
|
|
|
this->inventory = inventory;
|
|
|
|
this->slot = slot;
|
|
|
|
this->count = count;
|
|
|
|
this->bound = bound;
|
|
|
|
this->config = config;
|
|
|
|
this->parent = parent;
|
|
|
|
this->info = &Inventory::FindItemComponent(lot);
|
|
|
|
this->preconditions = new PreconditionExpression(this->info->reqPrecondition);
|
|
|
|
this->subKey = subKey;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
inventory->AddManagedItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Item::Item(
|
|
|
|
const LOT lot,
|
|
|
|
Inventory* inventory,
|
|
|
|
const uint32_t slot,
|
|
|
|
const uint32_t count,
|
|
|
|
const std::vector<LDFBaseData*>& config,
|
|
|
|
const LWOOBJID parent,
|
|
|
|
bool showFlyingLoot,
|
|
|
|
bool isModMoveAndEquip,
|
|
|
|
LWOOBJID subKey,
|
2022-04-23 12:13:06 +00:00
|
|
|
bool bound,
|
|
|
|
eLootSourceType lootSourceType) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!Inventory::IsValidItem(lot)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isModMoveAndEquip) {
|
|
|
|
showFlyingLoot = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->lot = lot;
|
|
|
|
this->inventory = inventory;
|
|
|
|
this->slot = slot;
|
|
|
|
this->count = count;
|
|
|
|
this->config = config;
|
|
|
|
this->parent = parent;
|
|
|
|
this->id = LWOOBJID_EMPTY;
|
|
|
|
this->info = &Inventory::FindItemComponent(lot);
|
|
|
|
this->bound = info->isBOP || bound;
|
|
|
|
this->preconditions = new PreconditionExpression(this->info->reqPrecondition);
|
|
|
|
this->subKey = subKey;
|
|
|
|
|
|
|
|
LWOOBJID id = ObjectIDManager::GenerateRandomObjectID();
|
|
|
|
|
|
|
|
id = GeneralUtils::SetBit(id, OBJECT_BIT_CHARACTER);
|
|
|
|
id = GeneralUtils::SetBit(id, OBJECT_BIT_PERSISTENT);
|
|
|
|
|
2022-09-02 18:49:19 +00:00
|
|
|
const auto type = static_cast<eItemType>(info->itemType);
|
|
|
|
|
|
|
|
if (type == eItemType::MOUNT) {
|
|
|
|
id = GeneralUtils::SetBit(id, OBJECT_BIT_CLIENT);
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
this->id = id;
|
|
|
|
|
|
|
|
inventory->AddManagedItem(this);
|
|
|
|
|
|
|
|
auto* entity = inventory->GetComponent()->GetParent();
|
2022-04-23 12:13:06 +00:00
|
|
|
GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, static_cast<int>(this->count), subKey, lootSourceType);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (isModMoveAndEquip) {
|
|
|
|
Equip();
|
|
|
|
|
2022-07-25 02:26:51 +00:00
|
|
|
Game::logger->Log("Item", "Move and equipped (%i) from (%i)", this->lot, this->inventory->GetType());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(inventory->GetComponent()->GetParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LWOOBJID Item::GetId() const {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOT Item::GetLot() const {
|
|
|
|
return lot;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Item::GetCount() const {
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Item::GetSlot() const {
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<LDFBaseData*>& Item::GetConfig() {
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CDItemComponent& Item::GetInfo() const {
|
|
|
|
return *info;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Item::GetBound() const {
|
|
|
|
return bound;
|
|
|
|
}
|
|
|
|
|
|
|
|
Inventory* Item::GetInventory() const {
|
|
|
|
return inventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
LWOOBJID Item::GetParent() const {
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
LWOOBJID Item::GetSubKey() const {
|
|
|
|
return subKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreconditionExpression* Item::GetPreconditionExpression() const {
|
|
|
|
return preconditions;
|
|
|
|
}
|
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
void Item::SetCount(const uint32_t value, const bool silent, const bool disassemble, const bool showFlyingLoot, eLootSourceType lootSourceType) {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (value == count) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto delta = std::abs(static_cast<int32_t>(value) - static_cast<int32_t>(count));
|
|
|
|
|
|
|
|
const auto type = static_cast<eItemType>(info->itemType);
|
|
|
|
|
|
|
|
if (disassemble) {
|
|
|
|
if (value < count) {
|
|
|
|
for (auto i = 0; i < delta; ++i) {
|
|
|
|
Disassemble();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!silent) {
|
|
|
|
auto* entity = inventory->GetComponent()->GetParent();
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (value > count) {
|
2022-04-24 03:35:34 +00:00
|
|
|
GameMessages::SendAddItemToInventoryClientSync(entity, entity->GetSystemAddress(), this, id, showFlyingLoot, delta, LWOOBJID_EMPTY, lootSourceType);
|
2021-12-05 17:54:36 +00:00
|
|
|
} else {
|
|
|
|
GameMessages::SendRemoveItemFromInventory(entity, entity->GetSystemAddress(), id, lot, inventory->GetType(), delta, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
count = value;
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
RemoveFromInventory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::SetSlot(const uint32_t value) {
|
|
|
|
if (slot == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& pair : inventory->GetItems()) {
|
|
|
|
auto* item = pair.second;
|
|
|
|
|
|
|
|
if (item->slot == value) {
|
|
|
|
item->slot = slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
slot = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::SetBound(const bool value) {
|
|
|
|
bound = value;
|
|
|
|
}
|
|
|
|
|
2022-07-25 02:26:51 +00:00
|
|
|
void Item::SetSubKey(LWOOBJID value) {
|
2021-12-05 17:54:36 +00:00
|
|
|
subKey = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::SetInventory(Inventory* value) {
|
|
|
|
inventory->RemoveManagedItem(this);
|
|
|
|
|
|
|
|
inventory = value;
|
|
|
|
|
|
|
|
inventory->AddManagedItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::Equip(const bool skipChecks) {
|
|
|
|
if (IsEquipped()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inventory->GetComponent()->EquipItem(this, skipChecks);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::UnEquip() {
|
|
|
|
if (!IsEquipped()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inventory->GetComponent()->UnEquipItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Item::IsEquipped() const {
|
|
|
|
auto* component = inventory->GetComponent();
|
|
|
|
|
|
|
|
for (const auto& pair : component->GetEquippedItems()) {
|
|
|
|
const auto item = pair.second;
|
|
|
|
|
|
|
|
if (item.id == id) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Item::Consume() {
|
2023-03-17 14:36:21 +00:00
|
|
|
auto* skillsTable = CDClientManager::Instance().GetTable<CDObjectSkillsTable>();
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto skills = skillsTable->Query([=](const CDObjectSkills entry) {
|
|
|
|
return entry.objectTemplate == static_cast<uint32_t>(lot);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto success = false;
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
for (auto& skill : skills) {
|
|
|
|
if (skill.castOnType == 3) // Consumable type
|
|
|
|
{
|
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-11 08:27:01 +00:00
|
|
|
Game::logger->LogDebug("Item", "Consumed LOT (%i) itemID (%llu). Success=(%d)", lot, id, success);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
GameMessages::SendUseItemResult(inventory->GetComponent()->GetParent(), lot, success);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
inventory->GetComponent()->RemoveItem(lot, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2022-12-24 22:41:13 +00:00
|
|
|
void Item::UseNonEquip(Item* item) {
|
2022-12-11 08:27:01 +00:00
|
|
|
LOT thisLot = this->GetLot();
|
|
|
|
if (!GetInventory()) {
|
|
|
|
Game::logger->LogDebug("Item", "item %i has no inventory??", this->GetLot());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* playerInventoryComponent = GetInventory()->GetComponent();
|
|
|
|
if (!playerInventoryComponent) {
|
|
|
|
Game::logger->LogDebug("Item", "no inventory component attached to item id %llu lot %i", this->GetId(), this->GetLot());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* playerEntity = playerInventoryComponent->GetParent();
|
|
|
|
if (!playerEntity) {
|
|
|
|
Game::logger->LogDebug("Item", "no player entity attached to inventory? item id is %llu", this->GetId());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-02 18:49:19 +00:00
|
|
|
const auto type = static_cast<eItemType>(info->itemType);
|
|
|
|
if (type == eItemType::MOUNT) {
|
2022-12-11 08:27:01 +00:00
|
|
|
playerInventoryComponent->HandlePossession(this);
|
|
|
|
// TODO Check if mounts are allowed to be spawned
|
2022-09-02 18:49:19 +00:00
|
|
|
} else if (type == eItemType::PET_INVENTORY_ITEM && subKey != LWOOBJID_EMPTY) {
|
2022-12-11 08:27:01 +00:00
|
|
|
const auto& databasePet = playerInventoryComponent->GetDatabasePet(subKey);
|
2021-12-05 17:54:36 +00:00
|
|
|
if (databasePet.lot != LOT_NULL) {
|
2022-12-11 08:27:01 +00:00
|
|
|
playerInventoryComponent->SpawnPet(this);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-12-11 08:27:01 +00:00
|
|
|
// This precondition response is taken care of in SpawnPet().
|
2022-09-05 22:28:32 +00:00
|
|
|
} else {
|
2022-12-24 22:41:13 +00:00
|
|
|
bool success = false;
|
|
|
|
auto inventory = item->GetInventory();
|
|
|
|
if (inventory && inventory->GetType() == eInventoryType::ITEMS) {
|
2023-03-17 14:36:21 +00:00
|
|
|
auto* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
|
2023-03-04 07:16:37 +00:00
|
|
|
const auto packageComponentId = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::PACKAGE);
|
2022-12-24 22:41:13 +00:00
|
|
|
|
|
|
|
if (packageComponentId == 0) return;
|
|
|
|
|
2023-03-17 14:36:21 +00:00
|
|
|
auto* packCompTable = CDClientManager::Instance().GetTable<CDPackageComponentTable>();
|
2022-12-24 22:41:13 +00:00
|
|
|
auto packages = packCompTable->Query([=](const CDPackageComponent entry) {return entry.id == static_cast<uint32_t>(packageComponentId); });
|
|
|
|
|
|
|
|
auto success = !packages.empty();
|
|
|
|
if (success) {
|
|
|
|
if (this->GetPreconditionExpression()->Check(playerInventoryComponent->GetParent())) {
|
|
|
|
auto* entityParent = playerInventoryComponent->GetParent();
|
|
|
|
// Roll the loot for all the packages then see if it all fits. If it fits, give it to the player, otherwise don't.
|
|
|
|
std::unordered_map<LOT, int32_t> rolledLoot{};
|
|
|
|
for (auto& pack : packages) {
|
|
|
|
auto thisPackage = LootGenerator::Instance().RollLootMatrix(entityParent, pack.LootMatrixIndex);
|
|
|
|
for (auto& loot : thisPackage) {
|
|
|
|
// If we already rolled this lot, add it to the existing one, otherwise create a new entry.
|
|
|
|
auto existingLoot = rolledLoot.find(loot.first);
|
|
|
|
if (existingLoot == rolledLoot.end()) {
|
|
|
|
rolledLoot.insert(loot);
|
|
|
|
} else {
|
|
|
|
existingLoot->second += loot.second;
|
|
|
|
}
|
2022-12-11 08:27:01 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-24 22:41:13 +00:00
|
|
|
if (playerInventoryComponent->HasSpaceForLoot(rolledLoot)) {
|
|
|
|
LootGenerator::Instance().GiveLoot(playerInventoryComponent->GetParent(), rolledLoot, eLootSourceType::LOOT_SOURCE_CONSUMPTION);
|
|
|
|
item->SetCount(item->GetCount() - 1);
|
|
|
|
} else {
|
|
|
|
success = false;
|
|
|
|
}
|
2022-12-11 08:27:01 +00:00
|
|
|
} else {
|
2022-12-24 22:41:13 +00:00
|
|
|
GameMessages::SendUseItemRequirementsResponse(
|
|
|
|
playerInventoryComponent->GetParent()->GetObjectID(),
|
|
|
|
playerInventoryComponent->GetParent()->GetSystemAddress(),
|
|
|
|
UseItemResponse::FailedPrecondition
|
|
|
|
);
|
2022-12-11 08:27:01 +00:00
|
|
|
success = false;
|
2022-09-02 18:49:19 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-11 08:27:01 +00:00
|
|
|
Game::logger->LogDebug("Item", "Player %llu %s used item %i", playerEntity->GetObjectID(), success ? "successfully" : "unsuccessfully", thisLot);
|
|
|
|
GameMessages::SendUseItemResult(playerInventoryComponent->GetParent(), thisLot, success);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::Disassemble(const eInventoryType inventoryType) {
|
|
|
|
for (auto* data : config) {
|
|
|
|
if (data->GetKey() == u"assemblyPartLOTs") {
|
|
|
|
auto modStr = data->GetValueAsString();
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-12-31 19:44:09 +00:00
|
|
|
// This shouldn't be null but always check your pointers.
|
|
|
|
if (GetInventory()) {
|
|
|
|
auto inventoryComponent = GetInventory()->GetComponent();
|
|
|
|
if (inventoryComponent) {
|
|
|
|
auto entity = inventoryComponent->GetParent();
|
|
|
|
if (entity) entity->SetVar<std::string>(u"currentModifiedBuild", modStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<LOT> modArray;
|
|
|
|
|
|
|
|
std::stringstream ssData(modStr);
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::string token;
|
|
|
|
|
|
|
|
const auto deliminator = '+';
|
|
|
|
|
|
|
|
while (std::getline(ssData, token, deliminator)) {
|
|
|
|
const auto modLot = std::stoi(token.substr(2, token.size() - 1));
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
modArray.push_back(modLot);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto mod : modArray) {
|
2022-04-24 03:35:34 +00:00
|
|
|
inventory->GetComponent()->AddItem(mod, 1, eLootSourceType::LOOT_SOURCE_DELETION, inventoryType);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::DisassembleModel() {
|
2023-03-17 14:36:21 +00:00
|
|
|
auto* table = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-04 07:16:37 +00:00
|
|
|
const auto componentId = table->GetByIDAndType(GetLot(), eReplicaComponentType::RENDER);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2022-01-13 03:48:27 +00:00
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt(
|
|
|
|
"SELECT render_asset FROM RenderComponent WHERE id = ?;");
|
|
|
|
query.bind(1, (int)componentId);
|
|
|
|
|
|
|
|
auto result = query.execQuery();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (result.eof()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::string renderAsset = result.fieldIsNull(0) ? "" : std::string(result.getStringField(0));
|
|
|
|
std::vector<std::string> renderAssetSplit = GeneralUtils::SplitString(renderAsset, '\\');
|
|
|
|
|
2022-11-01 18:21:26 +00:00
|
|
|
std::string lxfmlPath = "BrickModels/" + GeneralUtils::SplitString(renderAssetSplit.back(), '.').at(0) + ".lxfml";
|
|
|
|
auto buffer = Game::assetManager->GetFileAsBuffer(lxfmlPath.c_str());
|
|
|
|
|
2022-11-10 18:59:31 +00:00
|
|
|
if (!buffer.m_Success) {
|
|
|
|
Game::logger->Log("Item", "Failed to load %s to disassemble model into bricks, check that this file exists", lxfmlPath.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-01 18:21:26 +00:00
|
|
|
std::istream file(&buffer);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
result.finalize();
|
|
|
|
|
|
|
|
if (!file.good()) {
|
2022-11-01 18:21:26 +00:00
|
|
|
buffer.close();
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::stringstream data;
|
|
|
|
data << file.rdbuf();
|
|
|
|
|
2022-11-01 18:21:26 +00:00
|
|
|
buffer.close();
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (data.str().empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* doc = new tinyxml2::XMLDocument();
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doc->Parse(data.str().c_str(), data.str().size()) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> parts;
|
|
|
|
|
|
|
|
auto* lxfml = doc->FirstChildElement("LXFML");
|
|
|
|
auto* bricks = lxfml->FirstChildElement("Bricks");
|
|
|
|
std::string searchTerm = "Brick";
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!bricks) {
|
|
|
|
searchTerm = "Part";
|
|
|
|
bricks = lxfml->FirstChildElement("Scene")->FirstChildElement("Model")->FirstChildElement("Group");
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!bricks) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* currentBrick = bricks->FirstChildElement(searchTerm.c_str());
|
|
|
|
while (currentBrick) {
|
2022-07-25 02:26:51 +00:00
|
|
|
if (currentBrick->Attribute("designID") != nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
parts.push_back(std::stoi(currentBrick->Attribute("designID")));
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
currentBrick = currentBrick->NextSiblingElement(searchTerm.c_str());
|
|
|
|
}
|
|
|
|
|
2023-03-17 14:36:21 +00:00
|
|
|
auto* brickIDTable = CDClientManager::Instance().GetTable<CDBrickIDTableTable>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
for (unsigned int part : parts) {
|
|
|
|
const auto brickID = brickIDTable->Query([=](const CDBrickIDTable& entry) {
|
|
|
|
return entry.LEGOBrickID == part;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (brickID.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2022-04-24 03:35:34 +00:00
|
|
|
GetInventory()->GetComponent()->AddItem(brickID[0].NDObjectID, 1, eLootSourceType::LOOT_SOURCE_DELETION);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Item::RemoveFromInventory() {
|
|
|
|
UnEquip();
|
2022-07-25 02:26:51 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
count = 0;
|
|
|
|
|
|
|
|
inventory->RemoveManagedItem(this);
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Item::~Item() {
|
|
|
|
delete preconditions;
|
|
|
|
|
|
|
|
for (auto* value : config) {
|
|
|
|
delete value;
|
|
|
|
}
|
|
|
|
|
|
|
|
config.clear();
|
|
|
|
}
|