Skip to content

Commit

Permalink
refactor: rename getGlobalStorageValue and setGlobalStorageValue
Browse files Browse the repository at this point in the history
ops
  • Loading branch information
omarcopires committed Feb 19, 2024
1 parent 1c4bea7 commit 5bbb0b0
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 82 deletions.
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/actions/other/cobra_flask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
local deathEvent = CreatureEvent("EnergizedRagingMageDeath")
function deathEvent.onDeath(creature)
if getGlobalStorageValue(673003) < 2000 then
if Game.getStorageValue(673003) < 2000 then
return true
end

local monster = Game.createMonster("Raging Mage", creature:getPosition())
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 4 additions & 2 deletions data-otservbr-global/startup/others/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
9 changes: 0 additions & 9 deletions data/libs/compat/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 0 additions & 33 deletions data/libs/functions/game.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 1 addition & 15 deletions data/libs/systems/daily_reward.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion data/scripts/eventcallbacks/monster/on_spawn.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/scripts/globalevents/global_server_save.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5bbb0b0

Please sign in to comment.