Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ugc Save rocket and car modular assembly data to database #1279

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 41 additions & 39 deletions dGame/dGameMessages/GameMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5564,13 +5564,6 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity*
InventoryComponent* inv = static_cast<InventoryComponent*>(character->GetComponent(eReplicaComponentType::INVENTORY));
if (!inv) return;

LOG("Build finished");

GameMessages::SendFinishArrangingWithItem(character, entity->GetObjectID()); // kick them from modular build
GameMessages::SendModularBuildEnd(character); // i dont know if this does anything but DLUv2 did it

//inv->UnequipItem(inv->GetItemStackByLOT(6086, eInventoryType::ITEMS)); // take off the thinking cap
//Game::entityManager->SerializeEntity(entity);

uint8_t count; // 3 for rockets, 7 for cars

Expand Down Expand Up @@ -5605,50 +5598,59 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity*
}
}

const auto moduleAssembly = new LDFData<std::u16string>(u"assemblyPartLOTs", modules);
ObjectIDManager::Instance()->RequestPersistentID([=](uint32_t newId) {
LOG("Build finished");
GameMessages::SendFinishArrangingWithItem(character, entity->GetObjectID()); // kick them from modular build
GameMessages::SendModularBuildEnd(character); // i dont know if this does anything but DLUv2 did it

//inv->UnequipItem(inv->GetItemStackByLOT(6086, eInventoryType::ITEMS)); // take off the thinking cap
//Game::entityManager->SerializeEntity(entity);

std::vector<LDFBaseData*> config;
config.push_back(moduleAssembly);
const auto moduleAssembly = new LDFData<std::u16string>(u"assemblyPartLOTs", modules);

LWOOBJID newIdBig;
// Make sure a subkey isnt already in use. Persistent Ids do not make sense here since this only needs to be unique for
// this character. Because of that, we just generate a random id and check for a collision.
do {
newIdBig = ObjectIDManager::Instance()->GenerateRandomObjectID();
std::vector<LDFBaseData*> config;
config.push_back(moduleAssembly);

LWOOBJID newIdBig = newId;
GeneralUtils::SetBit(newIdBig, eObjectBits::CHARACTER);
} while (inv->FindItemBySubKey(newIdBig));

if (count == 3) {
inv->AddItem(6416, 1, eLootSourceType::QUICKBUILD, eInventoryType::MODELS, config, LWOOBJID_EMPTY, true, false, newIdBig);
} else if (count == 7) {
inv->AddItem(8092, 1, eLootSourceType::QUICKBUILD, eInventoryType::MODELS, config, LWOOBJID_EMPTY, true, false, newIdBig);
}
if (count == 3) {
inv->AddItem(6416, 1, eLootSourceType::QUICKBUILD, eInventoryType::MODELS, config, LWOOBJID_EMPTY, true, false, newIdBig);
} else if (count == 7) {
inv->AddItem(8092, 1, eLootSourceType::QUICKBUILD, eInventoryType::MODELS, config, LWOOBJID_EMPTY, true, false, newIdBig);
}

auto stmt = Database::CreatePreppedStmt("INSERT INTO ugc_modular_build (ugc_id, ldf_config) VALUES (?,?)");
stmt->setUInt64(1, newIdBig);
stmt->setString(2, GeneralUtils::UTF16ToWTF8(modules));
stmt->execute();

auto* missionComponent = character->GetComponent<MissionComponent>();
auto* missionComponent = character->GetComponent<MissionComponent>();

if (entity->GetLOT() != 9980 || Game::server->GetZoneID() != 1200) {
if (missionComponent != nullptr) {
missionComponent->Progress(eMissionTaskType::SCRIPT, entity->GetLOT(), entity->GetObjectID());
if (count >= 7 && everyPieceSwapped) missionComponent->Progress(eMissionTaskType::RACING, LWOOBJID_EMPTY, (LWOOBJID)eRacingTaskParam::MODULAR_BUILDING);
if (entity->GetLOT() != 9980 || Game::server->GetZoneID() != 1200) {
if (missionComponent != nullptr) {
missionComponent->Progress(eMissionTaskType::SCRIPT, entity->GetLOT(), entity->GetObjectID());
if (count >= 7 && everyPieceSwapped) missionComponent->Progress(eMissionTaskType::RACING, LWOOBJID_EMPTY, (LWOOBJID)eRacingTaskParam::MODULAR_BUILDING);
}
}
}
}

ScriptComponent* script = static_cast<ScriptComponent*>(entity->GetComponent(eReplicaComponentType::SCRIPT));
ScriptComponent* script = static_cast<ScriptComponent*>(entity->GetComponent(eReplicaComponentType::SCRIPT));

for (CppScripts::Script* script : CppScripts::GetEntityScripts(entity)) {
script->OnModularBuildExit(entity, character, count >= 3, modList);
}
for (CppScripts::Script* script : CppScripts::GetEntityScripts(entity)) {
script->OnModularBuildExit(entity, character, count >= 3, modList);
}

// Move remaining temp models back to models
std::vector<Item*> items;
// Move remaining temp models back to models
std::vector<Item*> items;

for (const auto& pair : temp->GetItems()) {
items.push_back(pair.second);
}
for (const auto& pair : temp->GetItems()) {
items.push_back(pair.second);
}

for (auto* item : items) {
inv->MoveItemToInventory(item, eInventoryType::MODELS, item->GetCount(), false);
for (auto* item : items) {
inv->MoveItemToInventory(item, eInventoryType::MODELS, item->GetCount(), false);
}
});
}
}

Expand Down
4 changes: 4 additions & 0 deletions migrations/dlu/12_modular_build_ugc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE IF NOT EXISTS ugc_modular_build (
EmosewaMC marked this conversation as resolved.
Show resolved Hide resolved
ugc_id BIGINT NOT NULL PRIMARY KEY,
ldf_config VARCHAR(60) NOT NULL
);
Loading