From 8db3964faf09714e8eb7e74556b64fdb62bc1737 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Wed, 14 Feb 2024 22:50:34 -0300 Subject: [PATCH] improve: vip storage to kv and remove storage premium (#2199) Co-authored-by: Leonardo Macedo <34727091+LeeoMacedo@users.noreply.github.com> Co-authored-by: Eduardo Dantas --- data-otservbr-global/lib/core/storages.lua | 2 - .../lib/others/vip_system.lua | 4 +- .../scripts/creaturescripts/customs/vip.lua | 2 +- .../scripts/creaturescripts/others/login.lua | 79 +++++++++---------- 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/data-otservbr-global/lib/core/storages.lua b/data-otservbr-global/lib/core/storages.lua index e67b5331c4c..5ce39579eb0 100644 --- a/data-otservbr-global/lib/core/storages.lua +++ b/data-otservbr-global/lib/core/storages.lua @@ -131,7 +131,6 @@ Storage = { -- Reserved in Global.Storage.FamiliarSummonEvent60 = 30055 ChayenneKeyTime = 30056, FreeQuests = 30057, - PremiumAccount = 30058, BattleAxeQuest = 30059, ShrineEntrance = 30060, PlayerWeaponReward = 30061, @@ -2921,7 +2920,6 @@ Storage = { }, VipSystem = { - IsVip = 150001, OnlineCoinsGain = 150002, OnlineTokensGain = 150003, }, diff --git a/data-otservbr-global/lib/others/vip_system.lua b/data-otservbr-global/lib/others/vip_system.lua index ca2aa3559f8..9b83d515378 100644 --- a/data-otservbr-global/lib/others/vip_system.lua +++ b/data-otservbr-global/lib/others/vip_system.lua @@ -31,7 +31,7 @@ function Player.onRemoveVip(self) self:setOutfit(playerOutfit) end - self:setStorageValue(Storage.VipSystem.IsVip, 0) + self:kv():scoped("account"):remove("vip-system") end function Player.onAddVip(self, days, silent) @@ -47,7 +47,7 @@ function Player.onAddVip(self, days, silent) self:addMount(mount) end - self:setStorageValue(Storage.VipSystem.IsVip, 1) + self:kv():scoped("account"):set("vip-system", true) end function CheckPremiumAndPrint(player, msgType) diff --git a/data-otservbr-global/scripts/creaturescripts/customs/vip.lua b/data-otservbr-global/scripts/creaturescripts/customs/vip.lua index 4c6485c4c6c..0ae99c00f2d 100644 --- a/data-otservbr-global/scripts/creaturescripts/customs/vip.lua +++ b/data-otservbr-global/scripts/creaturescripts/customs/vip.lua @@ -2,7 +2,7 @@ local playerLogin = CreatureEvent("VipLogin") function playerLogin.onLogin(player) if configManager.getBoolean(configKeys.VIP_SYSTEM_ENABLED) then - local wasVip = player:getStorageValue(Storage.VipSystem.IsVip) == 1 + local wasVip = player:kv():scoped("account"):get("vip-system") or false if wasVip and not player:isVip() then player:onRemoveVip() end diff --git a/data-otservbr-global/scripts/creaturescripts/others/login.lua b/data-otservbr-global/scripts/creaturescripts/others/login.lua index 852e53c2a63..897ce266cbb 100644 --- a/data-otservbr-global/scripts/creaturescripts/others/login.lua +++ b/data-otservbr-global/scripts/creaturescripts/others/login.lua @@ -53,14 +53,11 @@ function playerLogin.onLogin(player) player:setRemoveBossTime(1) end - if isPremium(player) then - player:setStorageValue(Storage.PremiumAccount, 1) - end -- Premium Ends Teleport to Temple, change addon (citizen) houseless local defaultTown = "Thais" -- default town where player is teleported if his home town is in premium area local freeTowns = { "Ab'Dendriel", "Carlin", "Kazordoon", "Thais", "Venore", "Rookgaard", "Dawnport", "Dawnport Tutorial", "Island of Destiny" } -- towns in free account area - if isPremium(player) == false and table.contains(freeTowns, player:getTown():getName()) == false then + if not player:isPremium() and not table.contains(freeTowns, player:getTown():getName()) then local town = player:getTown() local sex = player:getSex() local home = getHouseByPlayerGUID(getPlayerGUID(player)) @@ -68,13 +65,12 @@ function playerLogin.onLogin(player) player:teleportTo(town:getTemplePosition()) player:setTown(town) player:sendTextMessage(MESSAGE_FAILURE, "Your premium time has expired.") - player:setStorageValue(Storage.PremiumAccount, 0) if sex == 1 then player:setOutfit({ lookType = 128, lookFeet = 114, lookLegs = 134, lookHead = 114, lookAddons = 0 }) elseif sex == 0 then player:setOutfit({ lookType = 136, lookFeet = 114, lookLegs = 134, lookHead = 114, lookAddons = 0 }) end - if home ~= nil and not isPremium(player) then + if home and not player:isPremium() then setHouseOwner(home, 0) player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "You've lost your house because you are not premium anymore.") player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "Your items from house are send to your inbox.") @@ -96,44 +92,47 @@ function playerLogin.onLogin(player) -- Recruiter system local resultId = db.storeQuery("SELECT `recruiter` from `accounts` where `id`=" .. getAccountNumberByPlayerName(getPlayerName(player))) - local recruiterStatus = Result.getNumber(resultId, "recruiter") - local sex = player:getSex() - if recruiterStatus >= 1 then - if sex == 1 then - local outfit = player:hasOutfit(746) - if outfit == false then - player:addOutfit(746) - end - else - local outfit = player:hasOutfit(745) - if outfit == false then - player:addOutfit(745) + if resultId then + local recruiterStatus = Result.getNumber(resultId, "recruiter") + Result.free(resultId) + local sex = player:getSex() + if recruiterStatus >= 1 then + if sex == 1 then + local outfit = player:hasOutfit(746) + if outfit == false then + player:addOutfit(746) + end + else + local outfit = player:hasOutfit(745) + if outfit == false then + player:addOutfit(745) + end end end - end - if recruiterStatus >= 3 then - if sex == 1 then - local outfit = player:hasOutfit(746, 1) - if outfit == false then - player:addOutfitAddon(746, 1) - end - else - local outfit = player:hasOutfit(745, 1) - if outfit == false then - player:addOutfit(745, 1) + if recruiterStatus >= 3 then + if sex == 1 then + local outfit = player:hasOutfit(746, 1) + if outfit == false then + player:addOutfitAddon(746, 1) + end + else + local outfit = player:hasOutfit(745, 1) + if outfit == false then + player:addOutfit(745, 1) + end end end - end - if recruiterStatus >= 10 then - if sex == 1 then - local outfit = player:hasOutfit(746, 2) - if outfit == false then - player:addOutfitAddon(746, 2) - end - else - local outfit = player:hasOutfit(745, 2) - if outfit == false then - player:addOutfit(745, 2) + if recruiterStatus >= 10 then + if sex == 1 then + local outfit = player:hasOutfit(746, 2) + if outfit == false then + player:addOutfitAddon(746, 2) + end + else + local outfit = player:hasOutfit(745, 2) + if outfit == false then + player:addOutfit(745, 2) + end end end end