diff --git a/data-otservbr-global/scripts/actions/other/cobra_flask.lua b/data-otservbr-global/scripts/actions/other/cobra_flask.lua index 50b9c3dea08..240c055d04c 100644 --- a/data-otservbr-global/scripts/actions/other/cobra_flask.lua +++ b/data-otservbr-global/scripts/actions/other/cobra_flask.lua @@ -10,7 +10,7 @@ function cobraFlask.onUse(player, item, fromPosition, target, toPosition, isHotk doSendMagicEffect(target:getPosition(), CONST_ME_GREENSMOKE) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You carefully pour just a tiny, little, finely dosed... and there goes the whole content of the bottle. Stand back!") item:transform(31297) - setGlobalStorageValue(GlobalStorage.CobraBastionFlask, os.time() + 1800) -- 30 minutes + Game.setStorageValue(GlobalStorage.CobraBastionFlask, os.time() + 1800) -- 30 minutes end return end diff --git a/data-otservbr-global/scripts/actions/quests/oramond/glooth_fairy_lever.lua b/data-otservbr-global/scripts/actions/quests/oramond/glooth_fairy_lever.lua index 1f8ece85ae5..4c7955716d2 100644 --- a/data-otservbr-global/scripts/actions/quests/oramond/glooth_fairy_lever.lua +++ b/data-otservbr-global/scripts/actions/quests/oramond/glooth_fairy_lever.lua @@ -42,7 +42,7 @@ end local oramondGloothLever = Action() function oramondGloothLever.onUse(player, item, fromPosition, target, toPosition, isHotkey) if item.itemid == 8913 then - if getGlobalStorageValue(15560) >= os.time() then + if Game.getStorageValue(15560) >= os.time() then doPlayerSendTextMessage(player, 19, "You need to wait 15 minutes to use again.") return true end @@ -56,7 +56,7 @@ function oramondGloothLever.onUse(player, item, fromPosition, target, toPosition end spec:remove() end - setGlobalStorageValue(18081, os.time() + 15 * 60) + Game.setStorageValue(18081, os.time() + 15 * 60) player:say("Everyone in this place will be teleported into Glooth Fairy's hideout in one minute. No way back!!!", TALKTYPE_MONSTER_SAY) addEvent(PrepareEnter, 60 * 1000) end diff --git a/data-otservbr-global/scripts/actions/worldchanges/the_mummys_curse/horestis_jars.lua b/data-otservbr-global/scripts/actions/worldchanges/the_mummys_curse/horestis_jars.lua index 31af13df3e1..a2909517a2f 100644 --- a/data-otservbr-global/scripts/actions/worldchanges/the_mummys_curse/horestis_jars.lua +++ b/data-otservbr-global/scripts/actions/worldchanges/the_mummys_curse/horestis_jars.lua @@ -25,7 +25,7 @@ function horestisJars.onUse(cid, item, fromPosition, itemEx, toPosition) if getPlayerStorageValue(cid, Storage.TheMummysCurse.Time1) <= os.time() then if chances == 1 then doTransformItem(item.uid, 12506) - setGlobalStorageValue(GlobalStorage.TheMummysCurse, 1) + Game.setStorageValue(GlobalStorage.TheMummysCurse, 1) else player:say(failMessages[math.random(#failMessages)], TALKTYPE_ORANGE_1) player:getPosition():sendMagicEffect(CONST_ME_POFF) @@ -37,11 +37,11 @@ function horestisJars.onUse(cid, item, fromPosition, itemEx, toPosition) end elseif item.actionid == 50007 then if item.itemid == 12511 then - if getGlobalStorageValue(GlobalStorage.TheMummysCurse) == 1 then + if Game.getStorageValue(GlobalStorage.TheMummysCurse) == 1 then if getPlayerStorageValue(cid, Storage.TheMummysCurse.Time2) <= os.time() then if chances == 1 then doTransformItem(item.uid, 12506) - setGlobalStorageValue(GlobalStorage.TheMummysCurse, 2) + Game.setStorageValue(GlobalStorage.TheMummysCurse, 2) else player:say(failMessages[math.random(#failMessages)], TALKTYPE_ORANGE_1) player:getPosition():sendMagicEffect(CONST_ME_POFF) @@ -56,11 +56,11 @@ function horestisJars.onUse(cid, item, fromPosition, itemEx, toPosition) end elseif item.actionid == 50008 then if item.itemid == 12511 then - if getGlobalStorageValue(GlobalStorage.TheMummysCurse) == 2 then + if Game.getStorageValue(GlobalStorage.TheMummysCurse) == 2 then if getPlayerStorageValue(cid, Storage.TheMummysCurse.Time3) <= os.time() then if chances == 1 then doTransformItem(item.uid, 12506) - setGlobalStorageValue(GlobalStorage.TheMummysCurse, 3) + Game.setStorageValue(GlobalStorage.TheMummysCurse, 3) else player:say(failMessages[math.random(#failMessages)], TALKTYPE_ORANGE_1) player:getPosition():sendMagicEffect(CONST_ME_POFF) @@ -75,11 +75,11 @@ function horestisJars.onUse(cid, item, fromPosition, itemEx, toPosition) end elseif item.actionid == 50009 then if item.itemid == 12511 then - if getGlobalStorageValue(GlobalStorage.TheMummysCurse) == 3 then + if Game.getStorageValue(GlobalStorage.TheMummysCurse) == 3 then if getPlayerStorageValue(cid, Storage.TheMummysCurse.Time4) <= os.time() then if chances == 1 then doTransformItem(item.uid, 12506) - setGlobalStorageValue(GlobalStorage.TheMummysCurse, 4) + Game.setStorageValue(GlobalStorage.TheMummysCurse, 4) else player:say(failMessages[math.random(#failMessages)], TALKTYPE_ORANGE_1) player:getPosition():sendMagicEffect(CONST_ME_POFF) @@ -94,7 +94,7 @@ function horestisJars.onUse(cid, item, fromPosition, itemEx, toPosition) end elseif item.actionid == 50010 then if item.itemid == 12511 then - if getGlobalStorageValue(GlobalStorage.TheMummysCurse) == 4 then + if Game.getStorageValue(GlobalStorage.TheMummysCurse) == 4 then doTransformItem(item.uid, 12506) -- Remover Barreira e Sumonar Boss doRemoveItem(getTileItemById({ x = 32941, y = 32754, z = 12 }, 3514).uid, 1) diff --git a/data-otservbr-global/scripts/creaturescripts/quests/raging_mage_tower/energized_raging_mage_kill.lua b/data-otservbr-global/scripts/creaturescripts/quests/raging_mage_tower/energized_raging_mage_kill.lua index d04b37bf6ee..429c9e4e593 100644 --- a/data-otservbr-global/scripts/creaturescripts/quests/raging_mage_tower/energized_raging_mage_kill.lua +++ b/data-otservbr-global/scripts/creaturescripts/quests/raging_mage_tower/energized_raging_mage_kill.lua @@ -1,6 +1,6 @@ local deathEvent = CreatureEvent("EnergizedRagingMageDeath") function deathEvent.onDeath(creature) - if getGlobalStorageValue(673003) < 2000 then + if Game.getStorageValue(673003) < 2000 then return true end @@ -8,7 +8,7 @@ function deathEvent.onDeath(creature) monster:setReward(true) doCreatureSayWithRadius(creature, "GNAAAAAHRRRG!! WHAT? WHAT DID YOU DO TO ME!! I... I feel the energies crawling away... from me... DIE!!!", TALKTYPE_ORANGE_1, 35, 71) - setGlobalStorageValue(673003, 0) + Game.setStorageValue(673003, 0) return true end diff --git a/data-otservbr-global/scripts/creaturescripts/quests/raging_mage_tower/yielothax_kill.lua b/data-otservbr-global/scripts/creaturescripts/quests/raging_mage_tower/yielothax_kill.lua index 8ff28ceb824..ffb343e5154 100644 --- a/data-otservbr-global/scripts/creaturescripts/quests/raging_mage_tower/yielothax_kill.lua +++ b/data-otservbr-global/scripts/creaturescripts/quests/raging_mage_tower/yielothax_kill.lua @@ -1,6 +1,6 @@ local yielothaxKill = CreatureEvent("YielothaxDeath") function yielothaxKill.onDeath(creature) - setGlobalStorageValue(673003, getGlobalStorageValue(673003) + 1) + Game.setStorageValue(673003, Game.getStorageValue(673003) + 1) return true end diff --git a/data-otservbr-global/startup/others/functions.lua b/data-otservbr-global/startup/others/functions.lua index 8624dc8b268..0c1864ab83d 100644 --- a/data-otservbr-global/startup/others/functions.lua +++ b/data-otservbr-global/startup/others/functions.lua @@ -159,7 +159,7 @@ end function updateKeysStorage(tablename) -- It updates old storage keys from quests for all players local newUpdate = tablename[0].latest - local oldUpdate = getGlobalStorage(GlobalStorage.KeysUpdate) + local oldUpdate = Game.getStorageValue(GlobalStorage.KeysUpdate) if newUpdate <= oldUpdate then return true end @@ -168,11 +168,13 @@ function updateKeysStorage(tablename) if oldUpdate < 1 then oldUpdate = 1 end + for u = oldUpdate, newUpdate do for i = 1, #tablename[u] do db.query("UPDATE `player_storage` SET `key` = '" .. tablename[u][i].new .. "' WHERE `key` = '" .. tablename[u][i].old .. "';") end end - setGlobalStorage(GlobalStorage.KeysUpdate, newUpdate) + + Game.setStorageValue(GlobalStorage.KeysUpdate, newUpdate) logger.info("Storage Keys Updated") end diff --git a/data/libs/compat/compat.lua b/data/libs/compat/compat.lua index cd9b8146763..0561d0ddf7c 100644 --- a/data/libs/compat/compat.lua +++ b/data/libs/compat/compat.lua @@ -1423,15 +1423,6 @@ end saveData = saveServer -function getGlobalStorageValue(key) - return Game.getStorageValue(key) or -1 -end - -function setGlobalStorageValue(key, value) - Game.setStorageValue(key, value) - return true -end - getWorldType = Game.getWorldType numberToVariant = Variant diff --git a/data/libs/functions/game.lua b/data/libs/functions/game.lua index e4d40bef318..b35b96dfb3d 100644 --- a/data/libs/functions/game.lua +++ b/data/libs/functions/game.lua @@ -1,36 +1,3 @@ -function getGlobalStorage(key) - local keyNumber = tonumber(key) - if not keyNumber then - key = "'" .. key .. "'" - end - local resultId = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key) - if resultId ~= false then - local isNumber = tonumber(Result.getString(resultId, "value")) - if isNumber then - local val = Result.getNumber(resultId, "value") - Result.free(resultId) - return val - else - local val = Result.getString(resultId, "value") - Result.free(resultId) - return val - end - end - return -1 -end - -function setGlobalStorage(key, value) - local keyNumber = tonumber(key) - if not keyNumber then - key = "'" .. key .. "'" - end - local valueNumber = tonumber(value) - if not valueNumber then - value = "'" .. value .. "'" - end - db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (" .. key .. ", " .. value .. ") ON DUPLICATE KEY UPDATE `value` = " .. value) -end - function Game.broadcastMessage(message, messageType) if not messageType then messageType = MESSAGE_GAME_HIGHLIGHT diff --git a/data/libs/systems/daily_reward.lua b/data/libs/systems/daily_reward.lua index 232d4826021..67fc874e04e 100644 --- a/data/libs/systems/daily_reward.lua +++ b/data/libs/systems/daily_reward.lua @@ -83,19 +83,5 @@ function string.diff(self) end function GetDailyRewardLastServerSave() - return RetrieveGlobalStorage(DailyReward.storages.lastServerSave) -end - -function UpdateDailyRewardGlobalStorage(key, value) - db.query("INSERT INTO `global_storage` (`key`, `value`) VALUES (" .. key .. ", " .. value .. ") ON DUPLICATE KEY UPDATE `value` = " .. value) -end - -function RetrieveGlobalStorage(key) - local resultId = db.storeQuery("SELECT `value` FROM `global_storage` WHERE `key` = " .. key) - if resultId ~= false then - local val = Result.getNumber(resultId, "value") - Result.free(resultId) - return val - end - return 1 + return Game.getStorageValue(DailyReward.storages.lastServerSave) end diff --git a/data/scripts/eventcallbacks/monster/on_spawn.lua b/data/scripts/eventcallbacks/monster/on_spawn.lua index e0480d8e325..2c91d6bb747 100644 --- a/data/scripts/eventcallbacks/monster/on_spawn.lua +++ b/data/scripts/eventcallbacks/monster/on_spawn.lua @@ -1,6 +1,6 @@ local function handleCobra(monster) if monster:getName():lower() == "cobra scout" or monster:getName():lower() == "cobra vizier" or monster:getName():lower() == "cobra assassin" then - if getGlobalStorageValue(GlobalStorage.CobraBastionFlask) >= os.time() then + if Game.getStorageValue(GlobalStorage.CobraBastionFlask) >= os.time() then monster:setHealth(monster:getMaxHealth() * 0.75) end end diff --git a/data/scripts/globalevents/global_server_save.lua b/data/scripts/globalevents/global_server_save.lua index 00eaebbc3c3..a56de30e15f 100644 --- a/data/scripts/globalevents/global_server_save.lua +++ b/data/scripts/globalevents/global_server_save.lua @@ -10,7 +10,7 @@ local function ServerSave() end -- Update daily reward next server save timestamp - UpdateDailyRewardGlobalStorage(DailyReward.storages.lastServerSave, os.time()) + Game.setStorageValue(DailyReward.storages.lastServerSave, os.time()) end local function ServerSaveWarning(time) diff --git a/schema.sql b/schema.sql index 1eeb78fcd14..5ebcdf3cb0e 100644 --- a/schema.sql +++ b/schema.sql @@ -279,13 +279,6 @@ CREATE TABLE IF NOT EXISTS `forge_history` ( FOREIGN KEY (`player_id`) REFERENCES `players` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- Table structure `global_storage` -CREATE TABLE IF NOT EXISTS `global_storage` ( - `key` varchar(32) NOT NULL, - `value` text NOT NULL, - CONSTRAINT `global_storage_unique` UNIQUE (`key`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -- Table structure `guilds` CREATE TABLE IF NOT EXISTS `guilds` ( `id` int(11) NOT NULL AUTO_INCREMENT,