From d4af7d76a272daeb6ee35b78fc4dd7b2fb337a19 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:31:49 -0700 Subject: [PATCH] Add property behaviors migration (#790) * Add behaviors migration Add migration for behaviors. Tested that the tables get altered correctly, names are set correctly. Tested that I can place models, both regular and Brick-by-Brick ones and that they get deleted properly. Tested that picking up models and re-placing them down properly updates them in the tables. * Only update when empty --- dGame/dComponents/PropertyManagementComponent.cpp | 9 ++++++++- dGame/dGameMessages/GameMessages.cpp | 9 ++++++++- migrations/dlu/6_property_behaviors.sql | 11 +++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 migrations/dlu/6_property_behaviors.sql diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index f6954e4d..1e90e8db 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -656,7 +656,7 @@ void PropertyManagementComponent::Save() { return; } - auto* insertion = Database::CreatePreppedStmt("INSERT INTO properties_contents VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); + auto* insertion = Database::CreatePreppedStmt("INSERT INTO properties_contents VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); auto* update = Database::CreatePreppedStmt("UPDATE properties_contents SET x = ?, y = ?, z = ?, rx = ?, ry = ?, rz = ?, rw = ? WHERE id = ?;"); auto* lookup = Database::CreatePreppedStmt("SELECT id FROM properties_contents WHERE property_id = ?;"); auto* remove = Database::CreatePreppedStmt("DELETE FROM properties_contents WHERE id = ?;"); @@ -706,6 +706,13 @@ void PropertyManagementComponent::Save() { insertion->setDouble(9, rotation.y); insertion->setDouble(10, rotation.z); insertion->setDouble(11, rotation.w); + insertion->setString(12, "Objects_" + std::to_string(entity->GetLOT()) + "_name"); // Model name. TODO make this customizable + insertion->setString(13, ""); // Model description. TODO implement this. + insertion->setDouble(14, 0); // behavior 1. TODO implement this. + insertion->setDouble(15, 0); // behavior 2. TODO implement this. + insertion->setDouble(16, 0); // behavior 3. TODO implement this. + insertion->setDouble(17, 0); // behavior 4. TODO implement this. + insertion->setDouble(18, 0); // behavior 5. TODO implement this. try { insertion->execute(); } catch (sql::SQLException& ex) { diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 4efbd286..5ad8e207 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -2545,7 +2545,7 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent delete ugcs; //Insert into the db as a BBB model: - auto* stmt = Database::CreatePreppedStmt("INSERT INTO `properties_contents`(`id`, `property_id`, `ugc_id`, `lot`, `x`, `y`, `z`, `rx`, `ry`, `rz`, `rw`) VALUES (?,?,?,?,?,?,?,?,?,?,?)"); + auto* stmt = Database::CreatePreppedStmt("INSERT INTO `properties_contents` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); stmt->setUInt64(1, newIDL); stmt->setUInt64(2, propertyId); stmt->setUInt(3, blueprintIDSmall); @@ -2557,6 +2557,13 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent stmt->setDouble(9, 0.0f); // ry stmt->setDouble(10, 0.0f); // rz stmt->setDouble(11, 0.0f); // rw + stmt->setString(12, "Objects_14_name"); // Model name. TODO make this customizable + stmt->setString(13, ""); // Model description. TODO implement this. + stmt->setDouble(14, 0); // behavior 1. TODO implement this. + stmt->setDouble(15, 0); // behavior 2. TODO implement this. + stmt->setDouble(16, 0); // behavior 3. TODO implement this. + stmt->setDouble(17, 0); // behavior 4. TODO implement this. + stmt->setDouble(18, 0); // behavior 5. TODO implement this. stmt->execute(); delete stmt; diff --git a/migrations/dlu/6_property_behaviors.sql b/migrations/dlu/6_property_behaviors.sql new file mode 100644 index 00000000..b858db67 --- /dev/null +++ b/migrations/dlu/6_property_behaviors.sql @@ -0,0 +1,11 @@ +ALTER TABLE properties_contents + ADD COLUMN model_name TEXT NOT NULL DEFAULT "", + ADD COLUMN model_description TEXT NOT NULL DEFAULT "", + ADD COLUMN behavior_1 INT NOT NULL DEFAULT 0, + ADD COLUMN behavior_2 INT NOT NULL DEFAULT 0, + ADD COLUMN behavior_3 INT NOT NULL DEFAULT 0, + ADD COLUMN behavior_4 INT NOT NULL DEFAULT 0, + ADD COLUMN behavior_5 INT NOT NULL DEFAULT 0; + +UPDATE properties_contents SET model_name = CONCAT("Objects_", lot, "_name") WHERE model_name = ""; +CREATE TABLE IF NOT EXISTS behaviors (id INT NOT NULL, behavior_info TEXT NOT NULL);