From e8b5bef009c7988ead30a308d62213b1516458e9 Mon Sep 17 00:00:00 2001
From: Marco <marcomoa@hotmail.com>
Date: Fri, 22 Mar 2024 12:54:14 -0300
Subject: [PATCH] feat: golden outfit migration

---
 .../20241711122214_golden_outfit_to_kv.lua      | 17 +++++++++++++++++
 .../{memorial.lua => outfits_memorial.lua}      |  4 ++--
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 data-otservbr-global/scripts/game_migrations/20241711122214_golden_outfit_to_kv.lua
 rename data/scripts/actions/objects/{memorial.lua => outfits_memorial.lua} (92%)

diff --git a/data-otservbr-global/scripts/game_migrations/20241711122214_golden_outfit_to_kv.lua b/data-otservbr-global/scripts/game_migrations/20241711122214_golden_outfit_to_kv.lua
new file mode 100644
index 00000000000..67d0f5fb059
--- /dev/null
+++ b/data-otservbr-global/scripts/game_migrations/20241711122214_golden_outfit_to_kv.lua
@@ -0,0 +1,17 @@
+local migration = Migration("20241711122214_golden_outfit_to_kv_storage")
+
+local function migrateGoldenOutfit(player)
+	local goldeOutfitStorageValue = 51015
+	local value = player:getPlayerStorageValue(goldeOutfitStorageValue)
+
+	if value > 0 then
+		player:kv():set("golden-outfit-quest", value)
+		player:setPlayerStorageValue(goldeOutfitStorageValue, -1)
+	end
+end
+
+function migration:onExecute()
+	self:forEachPlayer(migrateGoldenOutfit)
+end
+
+migration:register()
diff --git a/data/scripts/actions/objects/memorial.lua b/data/scripts/actions/objects/outfits_memorial.lua
similarity index 92%
rename from data/scripts/actions/objects/memorial.lua
rename to data/scripts/actions/objects/outfits_memorial.lua
index 3894fa86fd0..ce4f536c5e4 100644
--- a/data/scripts/actions/objects/memorial.lua
+++ b/data/scripts/actions/objects/outfits_memorial.lua
@@ -6,7 +6,7 @@ local function updateGoldenOutfitCache()
 		return
 	end
 
-	goldenOutfitCache = {[1] = {}, [2] = {}, [3] = {}}
+	goldenOutfitCache = { [1] = {}, [2] = {}, [3] = {} }
 
 	local resultId = db.storeQuery("SELECT `key_name`, `timestamp`, `value` FROM `kv_store` WHERE `key_name` = '" .. "golden-outfit-quest" .. "'")
 
@@ -34,7 +34,7 @@ function memorial.onUse(player, item, fromPosition, target, toPosition, isHotkey
 	local msg = NetworkMessage()
 	msg:addByte(0xB0)
 
-	local prices = {500000000, 750000000, 1000000000}
+	local prices = { 500000000, 750000000, 1000000000 }
 	for i, price in ipairs(prices) do
 		msg:addU32(price)
 	end