From 8db3964faf09714e8eb7e74556b64fdb62bc1737 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Wed, 14 Feb 2024 22:50:34 -0300 Subject: [PATCH 1/3] 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 From bf2424a090f88193f20dd3b924a56cf1904d6e3d Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 14 Feb 2024 22:53:09 -0300 Subject: [PATCH 2/3] fix: nightmare isle and fury gates world changes (#2193) Co-authored-by: GitHub Actions Co-authored-by: Elson Costa --- data-otservbr-global/lib/core/storages.lua | 8 +- data-otservbr-global/npc/towncryer.lua | 19 +- .../{worldboard.lua => other/world_board.lua} | 25 ++- .../globalevents/worldchanges/fury_gates.lua | 183 ------------------ .../worldchanges/nightmare_isle.lua | 36 ---- .../quests/nightmare_isles/teleport.lua | 42 ---- .../nightmare_isles/teleport_ladder.lua | 53 ----- .../scripts/world_changes/fury_gates.lua | 72 +++++++ .../scripts/world_changes/nightmare_isles.lua | 119 ++++++++++++ .../oriental_trader.lua | 0 10 files changed, 221 insertions(+), 336 deletions(-) rename data-otservbr-global/scripts/actions/{worldboard.lua => other/world_board.lua} (51%) delete mode 100644 data-otservbr-global/scripts/globalevents/worldchanges/fury_gates.lua delete mode 100644 data-otservbr-global/scripts/globalevents/worldchanges/nightmare_isle.lua delete mode 100644 data-otservbr-global/scripts/movements/quests/nightmare_isles/teleport.lua delete mode 100644 data-otservbr-global/scripts/movements/quests/nightmare_isles/teleport_ladder.lua create mode 100644 data-otservbr-global/scripts/world_changes/fury_gates.lua create mode 100644 data-otservbr-global/scripts/world_changes/nightmare_isles.lua rename data-otservbr-global/scripts/{globalevents/worldchanges => world_changes}/oriental_trader.lua (100%) diff --git a/data-otservbr-global/lib/core/storages.lua b/data-otservbr-global/lib/core/storages.lua index 5ce39579eb0..78d2535646f 100644 --- a/data-otservbr-global/lib/core/storages.lua +++ b/data-otservbr-global/lib/core/storages.lua @@ -3077,6 +3077,13 @@ GlobalStorage = { OutburstHealth = 60181, OutburstChargingKilled = 60182, }, + WorldBoard = { + NightmareIsle = { + AnkrahmunNorth = 60191, + DarashiaNorth = 60192, + DarashiaWest = 60193, + }, + }, FuryGates = 65000, Yakchal = 65001, PitsOfInfernoLevers = 65002, @@ -3091,7 +3098,6 @@ GlobalStorage = { CobraBastionFlask = 65012, Inquisition = 65013, Yasir = 65014, - NightmareIsle = 65015, IceCrack = 65016, UglyMonster = 65017, KeysUpdate = 40000, -- Reserved storage from 40000 - 40000 diff --git a/data-otservbr-global/npc/towncryer.lua b/data-otservbr-global/npc/towncryer.lua index 6e17b94b420..3e6a93ad973 100644 --- a/data-otservbr-global/npc/towncryer.lua +++ b/data-otservbr-global/npc/towncryer.lua @@ -32,22 +32,15 @@ npcConfig.voices = { } local worldChanges = { - { - storage = GlobalStorage.FuryGates, - text = "Hear ye! Hear ye! A fiery gate has opened, threatening a city! Guard the people frightened, their death would be a pity!", - }, - { - storage = GlobalStorage.Yasir, - text = "Hear ye! Hear ye! What a lucky and beautiful day! Visit Carlin, Ankrahmun, or Liberty Bay. Yasir, the oriental trader might be there. Gather your creature products, for this chance is rare.", - }, - { - storage = GlobalStorage.NightmareIsle, - text = "Hear me! Hear me! A river is flooding, south of the outlaw base. Explore a new isle, an unknown place. Don't be afraid, but ready your blade.", - }, + { text = "In Ankrahmun's desert, a storm has revealed the entry to a nightmare that can't be sealed. Horrible creatures there spell instant death to all young adventurers who dare take a breath!", storage = GlobalStorage.WorldBoard.NightmareIsle.AnkrahmunNorth }, + { text = "Near Darashia's coast, a storm has revealed the entry to a nightmare that can't be sealed. Horrible creatures there spell instant death to all young adventurers who dare take a breath!", storage = GlobalStorage.WorldBoard.NightmareIsle.DarashiaNorth }, + { text = "Near Drefia's mountains, a storm has revealed the entry to a nightmare that can't be sealed. Horrible creatures there spell instant death to all young adventurers who dare take a breath!", storage = GlobalStorage.WorldBoard.NightmareIsle.DarashiaWest }, + { text = "Hear ye! Hear ye! What a lucky and beautiful day! Visit Carlin, Ankrahmun, or Liberty Bay. Yasir, the oriental trader might be there. Gather your creature products, for this chance is rare.", storage = GlobalStorage.Yasir }, + { text = "Hear ye! Hear ye! A fiery gate has opened, threatening a city! Guard the people frightened, their death would be a pity!", storage = GlobalStorage.FuryGates }, } for i = 1, #worldChanges do - if getGlobalStorageValue(worldChanges[i].storage) > 0 then + if Game.getStorageValue(worldChanges[i].storage) > 0 then table.insert(npcConfig.voices, { text = worldChanges[i].text }) end end diff --git a/data-otservbr-global/scripts/actions/worldboard.lua b/data-otservbr-global/scripts/actions/other/world_board.lua similarity index 51% rename from data-otservbr-global/scripts/actions/worldboard.lua rename to data-otservbr-global/scripts/actions/other/world_board.lua index 3d50c2fb350..c3ec43c7af5 100644 --- a/data-otservbr-global/scripts/actions/worldboard.lua +++ b/data-otservbr-global/scripts/actions/other/world_board.lua @@ -1,26 +1,35 @@ local worldBoard = Action() local communicates = { - -- Fury Gates [1] = { - globalStorage = 65000, + storageValue = GlobalStorage.FuryGates, communicate = "A fiery fury gate has opened near one of the major cities somewhere in Tibia.", }, - -- Yasir + [2] = { - globalStorage = 65014, + storageValue = GlobalStorage.Yasir, communicate = "Oriental ships sighted! A trader for exotic creature products may currently be visiting Carlin, Ankrahmun or Liberty Bay.", }, - -- Nightmare Isle + [3] = { - globalStorage = 65015, - communicate = "A sandstorm travels through Darama, leading to isles full of deadly creatures inside a nightmare. Avoid the river near Drefia/northernmost coast/Ankhramun tar pits!", + storageValue = GlobalStorage.WorldBoard.NightmareIsle.AnkrahmunNorth, + communicate = "A sandstorm travels through Darama, leading to isles full of deadly creatures inside a nightmare. Avoid the Ankhramun tar pits!.", + }, + + [4] = { + storageValue = GlobalStorage.WorldBoard.NightmareIsle.DarashiaNorth, + communicate = "A sandstorm travels through Darama, leading to isles full of deadly creatures inside a nightmare. Avoid the northernmost coast!", + }, + + [5] = { + storageValue = GlobalStorage.WorldBoard.NightmareIsle.DarashiaWest, + communicate = "A sandstorm travels through Darama, leading to isles full of deadly creatures inside a nightmare. Avoid the river near Drefia!", }, } function worldBoard.onUse(player, item, fromPosition, target, toPosition, isHotkey) for index, value in pairs(communicates) do - if getGlobalStorageValue(value.globalStorage) > 0 then + if Game.getStorageValue(value.storageValue) > 0 then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, value.communicate) end end diff --git a/data-otservbr-global/scripts/globalevents/worldchanges/fury_gates.lua b/data-otservbr-global/scripts/globalevents/worldchanges/fury_gates.lua deleted file mode 100644 index a50cc253016..00000000000 --- a/data-otservbr-global/scripts/globalevents/worldchanges/fury_gates.lua +++ /dev/null @@ -1,183 +0,0 @@ -local gates = { - -- Ab'dendriel - [1] = { - city = "Ab'dendriel", - mapName = "abdendriel", - exitPosition = Position(32680, 31720, 7), - }, - -- Ankrahmun - [2] = { - city = "Ankrahmun", - mapName = "ankrahmun", - exitPosition = Position(33269, 32841, 7), - }, - -- Carlin - [3] = { - city = "Carlin", - mapName = "carlin", - exitPosition = Position(32263, 31848, 7), - burntItems = { - { position = Position(32266, 31842, 7), itemId = 6217 }, - { position = Position(32258, 31843, 7), itemId = 6218 }, - { position = Position(32264, 31843, 7), itemId = 3917 }, - }, - }, - -- Darashia - [4] = { - city = "Darashia", - mapName = "darashia", - exitPosition = Position(33304, 32371, 7), - burntItems = { - { position = Position(33300, 32366, 7), itemId = 6217 }, - }, - }, - -- Edron - [5] = { - city = "Edron", - mapName = "edron", - exitPosition = Position(33221, 31923, 7), - }, - -- Kazordoon - [6] = { - city = "Kazordoon", - mapName = "kazordoon", - exitPosition = Position(32575, 31981, 7), - burntItems = { - { position = Position(32571, 31976, 7), itemId = 6218 }, - { position = Position(32573, 31977, 7), itemId = 6218 }, - { position = Position(32569, 31984, 7), itemId = 6217 }, - { position = Position(32572, 31984, 7), itemId = 6217 }, - { position = Position(32572, 31985, 7), itemId = 6218 }, - }, - }, - -- Liberty Bay - [7] = { - city = "Liberty Bay", - mapName = "libertybay", - exitPosition = Position(32348, 32693, 7), - }, - -- Port Hope - [8] = { - city = "Port Hope", - mapName = "porthope", - exitPosition = Position(32530, 32712, 7), - burntItems = { - { position = Position(32532, 32719, 7), itemId = 3696 }, - }, - }, - -- Thais - [9] = { - city = "Thais", - mapName = "thais", - exitPosition = Position(32265, 32164, 7), - burntItems = { - { position = Position(32269, 32157, 7), itemId = 6218 }, - { position = Position(32274, 32165, 7), itemId = 6218 }, - }, - }, - -- Venore - [10] = { - city = "Venore", - mapName = "venore", - exitPosition = Position(32834, 32082, 7), - burntItems = { - { position = Position(32836, 32079, 7), itemId = 6217 }, - { position = Position(32835, 32080, 7), itemId = 3693 }, - { position = Position(32837, 32080, 7), itemId = 6218 }, - { position = Position(32828, 32081, 7), itemId = 6217 }, - { position = Position(32836, 32081, 7), itemId = 3686 }, - { position = Position(32837, 32081, 7), itemId = 6217 }, - { position = Position(32827, 32082, 7), itemId = 6218 }, - { position = Position(32836, 32082, 7), itemId = 6218 }, - { position = Position(32834, 32084, 7), itemId = 3693 }, - { position = Position(32830, 32086, 7), itemId = 3694 }, - { position = Position(32836, 32086, 7), itemId = 3683 }, - { position = Position(32836, 32087, 7), itemId = 3686 }, - { position = Position(32838, 32087, 7), itemId = 3696 }, - { position = Position(32835, 32089, 7), itemId = 6217 }, - { position = Position(32836, 32091, 7), itemId = 3689 }, - }, - }, -} - -local function Furywebhook(message) -- New local function that runs on delay to send webhook message. - Webhook.sendMessage(":fire: " .. message, announcementChannels["serverAnnouncements"]) -end - --- FURY GATES MAP LOAD - -local furygates = GlobalEvent("furygates") - -function furygates.onStartup(interval) - local gateId = math.random(1, 10) - - -- Remove burnt items - if gates[gateId].burntItems then - local item - for i = 1, #gates[gateId].burntItems do - local tile = Tile(gates[gateId].burntItems[i].position) - if tile then - item = tile:getItemById(gates[gateId].burntItems[i].itemId) - end - if item then - item:remove() - end - end - end - - Game.loadMap(DATA_DIRECTORY .. "/world/world_changes/fury_gates/" .. gates[gateId].mapName .. ".otbm") - - setGlobalStorageValue(GlobalStorage.FuryGates, gateId) - - logger.info("Fury Gate will be active in {} today", gates[gateId].city) - local message = (string.format("Fury Gate will be active in %s today", gates[gateId].city)) -- Declaring the message to send to webhook. - addEvent(Furywebhook, 60000, message) -- Event with 1 minute delay to send webhook message after server starts. - - return true -end - -furygates:register() - --- FURY GATE TELEPORTS -local teleport = MoveEvent() - -function teleport.onStepIn(creature, item, position, fromPosition) - local player = creature:getPlayer() - if not player then - return true - end - - local gateId = Game.getStorageValue(GlobalStorage.FuryGates) - - if not gates[gateId] then - return true - end - - position:sendMagicEffect(CONST_ME_TELEPORT) - - -- Enter gates - if item.actionid == 9710 then - -- Check requirements - if not player:isPremium() or not player:isPromoted() or player:getLevel() < 60 then - player:say("Only Premium promoted players of level 60 or higher are able to enter this portal.", TALKTYPE_MONSTER_SAY, false, player, fromPosition) - player:teleportTo(fromPosition) - fromPosition:sendMagicEffect(CONST_ME_TELEPORT) - return true - end - - local destination = Position(33290, 31786, 13) - player:teleportTo(destination) - destination:sendMagicEffect(CONST_ME_TELEPORT) - -- Exit gate - elseif item.actionid == 9715 then - player:teleportTo(gates[gateId].exitPosition) - gates[gateId].exitPosition:sendMagicEffect(CONST_ME_TELEPORT) - end - - return true -end - -teleport:type("stepin") -teleport:aid(9710, 9715) - -teleport:register() diff --git a/data-otservbr-global/scripts/globalevents/worldchanges/nightmare_isle.lua b/data-otservbr-global/scripts/globalevents/worldchanges/nightmare_isle.lua deleted file mode 100644 index fb0d3b6f672..00000000000 --- a/data-otservbr-global/scripts/globalevents/worldchanges/nightmare_isle.lua +++ /dev/null @@ -1,36 +0,0 @@ -local config = { - -- ankrahmun - north - [1] = { - mapName = "ankrahmun-north", - displayName = "north of Ankrahmun", - }, - -- darashia - west - [2] = { - mapName = "darashia-west", - displayName = "west of Darashia", - }, - -- darashia - north - [3] = { - mapName = "darashia-north", - displayName = "north of Darashia", - }, -} - -local function Nightmarewebhook(message) -- New local function that runs on delay to send webhook message. - Webhook.sendMessage(":thought_balloon: " .. message, announcementChannels["serverAnnouncements"]) -end - -local NightmareIsle = GlobalEvent("NightmareIsle") -function NightmareIsle.onStartup(interval) - local select = config[math.random(#config)] - Game.loadMap(DATA_DIRECTORY .. "/world/world_changes/nightmare_isle/" .. select.mapName .. ".otbm") - logger.info("[WorldChanges] Nightmare Isle will be active {} today", select.displayName) - local message = string.format("Nightmare Isle will be active %s today", select.displayName) -- Declaring the message to send to webhook. - addEvent(Nightmarewebhook, 60000, message) -- Event with 1 minute delay to send webhook message after server starts. - - setGlobalStorageValue(GlobalStorage.NightmareIsle, 1) - - return true -end - -NightmareIsle:register() diff --git a/data-otservbr-global/scripts/movements/quests/nightmare_isles/teleport.lua b/data-otservbr-global/scripts/movements/quests/nightmare_isles/teleport.lua deleted file mode 100644 index 80dba0d59b3..00000000000 --- a/data-otservbr-global/scripts/movements/quests/nightmare_isles/teleport.lua +++ /dev/null @@ -1,42 +0,0 @@ -local setting = { - { storage = 210001, teleportPosition = Position(33032, 32400, 7) }, -- entrance teleport Darashia Northwest - { storage = 210002, teleportPosition = Position(33215, 32273, 7) }, -- entrance teleport Darashia North - { storage = 210016, teleportPosition = Position(33255, 32678, 7) }, -- entrance teleport Ankrahmun -} - -local teleports = { - [64001] = 210001, -- northwest Darashia - [64002] = 210002, -- north Darashia - [64003] = 210016, -- north Ankrahmun -} - -local teleport = MoveEvent() - -function teleport.onStepIn(creature, item, position, fromPosition) - local player = creature:getPlayer() - if not player then - return - end - - for i = 1, #setting do - local table = setting[i] - local backStorage = table.storage - if player:getStorageValue(backStorage) >= 1 then - player:teleportTo(table.teleportPosition) - player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - player:setStorageValue(backStorage, 0) - break - end - end - - local storagePortal = teleports[item.uid] - if storagePortal then - player:teleportTo(Position(33497, 32616, 8)) - player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - player:setStorageValue(storagePortal, 1) - end - return true -end - -teleport:uid(35020, 64001, 64002, 64003) -teleport:register() diff --git a/data-otservbr-global/scripts/movements/quests/nightmare_isles/teleport_ladder.lua b/data-otservbr-global/scripts/movements/quests/nightmare_isles/teleport_ladder.lua deleted file mode 100644 index 297f4585636..00000000000 --- a/data-otservbr-global/scripts/movements/quests/nightmare_isles/teleport_ladder.lua +++ /dev/null @@ -1,53 +0,0 @@ -local setting = { - [64103] = Position(33475, 32641, 10), - [64104] = Position(33473, 32647, 9), - [64105] = Position(33463, 32585, 8), - [64106] = Position(33457, 32580, 8), - [64107] = Position(33422, 32582, 8), - [64108] = Position(33430, 32600, 10), - [64109] = Position(33420, 32604, 10), - [64120] = Position(33446, 32616, 11), - [64121] = Position(33460, 32632, 10), - [64122] = Position(33429, 32626, 10), - [64123] = Position(33425, 32633, 8), - [64124] = Position(33435, 32631, 8), - [64125] = Position(33478, 32621, 10), - [64126] = Position(33484, 32629, 8), - [64127] = Position(33452, 32617, 11), - [64128] = Position(33419, 32589, 10), -} - -local teleportLadder = MoveEvent() - -function teleportLadder.onStepIn(creature, item, position, fromPosition) - local player = creature:getPlayer() - if not player then - return true - end - - if player:getStorageValue(Storage.TheShatteredIsles.AccessToLagunaIsland) ~= 1 and item.uid == 3206 then - local accessPosition = Position(32340, 32540, 7) - player:teleportTo(accessPosition) - position:sendMagicEffect(CONST_ME_TELEPORT) - accessPosition:sendMagicEffect(CONST_ME_TELEPORT) - return true - end - - local targetPosition = setting[item.actionid] - if not targetPosition then - return true - end - - player:teleportTo(targetPosition) - position:sendMagicEffect(CONST_ME_TELEPORT) - targetPosition:sendMagicEffect(CONST_ME_TELEPORT) - return true -end - -teleportLadder:type("stepin") - -for index, value in pairs(setting) do - teleportLadder:aid(index) -end - -teleportLadder:register() diff --git a/data-otservbr-global/scripts/world_changes/fury_gates.lua b/data-otservbr-global/scripts/world_changes/fury_gates.lua new file mode 100644 index 00000000000..96700d0971a --- /dev/null +++ b/data-otservbr-global/scripts/world_changes/fury_gates.lua @@ -0,0 +1,72 @@ +local function furyWebhook(message) + Webhook.sendMessage(":fire: " .. message, announcementChannels["serverAnnouncements"]) +end + +local gates = { + { city = "Ab'dendriel", mapName = "abdendriel", exitPosition = Position(32680, 31720, 7) }, + { city = "Ankrahmun", mapName = "ankrahmun", exitPosition = Position(33269, 32841, 7) }, + { city = "Carlin", mapName = "carlin", exitPosition = Position(32263, 31848, 7) }, + { city = "Darashia", mapName = "darashia", exitPosition = Position(33304, 32371, 7) }, + { city = "Edron", mapName = "edron", exitPosition = Position(33221, 31923, 7) }, + { city = "Kazordoon", mapName = "kazordoon", exitPosition = Position(32575, 31981, 7) }, + { city = "Liberty Bay", mapName = "libertybay", exitPosition = Position(32348, 32693, 7) }, + { city = "Port Hope", mapName = "porthope", exitPosition = Position(32530, 32712, 7) }, + { city = "Thais", mapName = "thais", exitPosition = Position(32265, 32164, 7) }, + { city = "Venore", mapName = "venore", exitPosition = Position(32834, 32082, 7) }, +} + +local furyGates = GlobalEvent("Load Fury Gates") + +function furyGates.onStartup(interval) + local totalGates = #gates + if totalGates == 0 then + return true + end + + local gateId = math.random(1, totalGates) + local selectedGate = gates[gateId] + Game.loadMap(DATA_DIRECTORY .. "/world/world_changes/fury_gates/" .. selectedGate.mapName .. ".otbm") + Game.setStorageValue(GlobalStorage.FuryGates, gateId) + + logger.info("[World Change] Fury Gate has arrived in {}!", selectedGate.city) + addEvent(furyWebhook, 60000, (string.format("Fury Gate will be active in %s today", selectedGate.city))) + return true +end + +furyGates:register() + +local furyGatesTeleports = MoveEvent() + +function furyGatesTeleports.onStepIn(creature, item, position, fromPosition) + local player = creature:getPlayer() + if not player then + return true + end + + local gateId = Game.getStorageValue(GlobalStorage.FuryGates) + if not gates[gateId] then + return true + end + + if item.actionid == 9710 then + if not player:isPremium() or not player:isPromoted() or player:getLevel() < 60 then + player:teleportTo(fromPosition) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + player:say("Only Premium promoted players of level 60 or higher are able to enter this portal.", TALKTYPE_MONSTER_SAY, false, player, fromPosition) + return true + end + + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + player:teleportTo(Position(33290, 31786, 13)) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + elseif item.actionid == 9715 then + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + player:teleportTo(gates[gateId].exitPosition) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + end + return true +end + +furyGatesTeleports:type("stepin") +furyGatesTeleports:aid(9710, 9715) +furyGatesTeleports:register() diff --git a/data-otservbr-global/scripts/world_changes/nightmare_isles.lua b/data-otservbr-global/scripts/world_changes/nightmare_isles.lua new file mode 100644 index 00000000000..4d35a0dde12 --- /dev/null +++ b/data-otservbr-global/scripts/world_changes/nightmare_isles.lua @@ -0,0 +1,119 @@ +local function Nightmarewebhook(message) -- New local function that runs on delay to send webhook message. + Webhook.sendMessage(":thought_balloon: " .. message, announcementChannels["serverAnnouncements"]) +end + +local nightmareIsleConfig = { + { displayName = "North of Ankrahmun", mapName = "ankrahmun-north", storage = GlobalStorage.WorldBoard.NightmareIsle.AnkrahmunNorth }, + { displayName = "North of Darashia", mapName = "darashia-north", storage = GlobalStorage.WorldBoard.NightmareIsle.DarashiaNorth }, + { displayName = "West of Darashia", mapName = "darashia-west", storage = GlobalStorage.WorldBoard.NightmareIsle.DarashiaWest }, +} + +local nightmareIsleEvent = GlobalEvent("Nightmare Isle") + +function nightmareIsleEvent.onStartup() + for _, config in ipairs(nightmareIsleConfig) do + Game.setStorageValue(config.storage, -1) + end + + local randomMap = nightmareIsleConfig[math.random(#nightmareIsleConfig)] + Game.loadMap(DATA_DIRECTORY .. "/world/world_changes/nightmare_isle/" .. randomMap.mapName .. ".otbm") + Game.setStorageValue(randomMap.storage, 1) + + logger.info("[World Change] Nightmare Isle is active in " .. randomMap.displayName) + + addEvent(Nightmarewebhook, 60000, string.format("Nightmare Isle will be active %s today", randomMap.displayName)) + return true +end + +nightmareIsleEvent:register() + +local teleportExits = { + { position = Position(33255, 32678, 7), storage = GlobalStorage.WorldBoard.NightmareIsle.AnkrahmunNorth }, + { position = Position(33215, 32273, 7), storage = GlobalStorage.WorldBoard.NightmareIsle.DarashiaNorth }, + { position = Position(33032, 32400, 7), storage = GlobalStorage.WorldBoard.NightmareIsle.DarashiaWest }, +} + +local teleportExit = MoveEvent() + +function teleportExit.onStepIn(creature, item, position, fromPosition) + local player = creature:getPlayer() + if not player then + return + end + + for _, config in ipairs(teleportExits) do + if Game.getStorageValue(config.storage) == 1 then + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + player:teleportTo(config.position) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + return true + end + end + return true +end + +teleportExit:uid(35020) +teleportExit:register() + +local teleportEntrace = MoveEvent() + +function teleportEntrace.onStepIn(creature, item, position, fromPosition) + local player = creature:getPlayer() + if not player then + return + end + + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + player:teleportTo(Position(33497, 32616, 8)) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + return true +end + +teleportEntrace:uid(64001, 64002, 64003) +teleportEntrace:register() + +local teleportPositions = { + [64103] = Position(33475, 32641, 10), + [64104] = Position(33473, 32647, 9), + [64105] = Position(33463, 32585, 8), + [64106] = Position(33457, 32580, 8), + [64107] = Position(33422, 32582, 8), + [64108] = Position(33430, 32600, 10), + [64109] = Position(33420, 32604, 10), + [64120] = Position(33446, 32616, 11), + [64121] = Position(33460, 32632, 10), + [64122] = Position(33429, 32626, 10), + [64123] = Position(33425, 32633, 8), + [64124] = Position(33435, 32631, 8), + [64125] = Position(33478, 32621, 10), + [64126] = Position(33484, 32629, 8), + [64127] = Position(33452, 32617, 11), + [64128] = Position(33419, 32589, 10), +} + +local teleportLadder = MoveEvent() + +function teleportLadder.onStepIn(creature, item, position, fromPosition) + local player = creature:getPlayer() + if not player then + return true + end + + local targetPosition = teleportPositions[item.actionid] + if not targetPosition then + return true + end + + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + player:teleportTo(targetPosition) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + return true +end + +teleportLadder:type("stepin") + +for index, value in pairs(teleportPositions) do + teleportLadder:aid(index) +end + +teleportLadder:register() diff --git a/data-otservbr-global/scripts/globalevents/worldchanges/oriental_trader.lua b/data-otservbr-global/scripts/world_changes/oriental_trader.lua similarity index 100% rename from data-otservbr-global/scripts/globalevents/worldchanges/oriental_trader.lua rename to data-otservbr-global/scripts/world_changes/oriental_trader.lua From d083d04806735c4be44365638c3b66d9cab15e59 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 14 Feb 2024 22:53:49 -0300 Subject: [PATCH 3/3] refactor: duplicate keys checking (#2198) Improves the duplicate checking logic, now redefining the seen and duplicatesValues variables before checking each table. --- .../globalevents/server_initialization.lua | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/data/scripts/globalevents/server_initialization.lua b/data/scripts/globalevents/server_initialization.lua index 26494c82ce4..8b0ff53ceb8 100644 --- a/data/scripts/globalevents/server_initialization.lua +++ b/data/scripts/globalevents/server_initialization.lua @@ -60,44 +60,41 @@ local function storeTownsInDatabase() end end --- Function to recursively check for duplicate values in a given variable's storage -local function checkDuplicateStorageValues(varTable, seen, duplicates) +-- Functions to recursively check for duplicate values in a given variable's storage and log the results +local seen, duplicatesValues + +local function checkDuplicateStorageValues(varTable) for _, value in pairs(varTable) do if type(value) == "table" then - checkDuplicateStorageValues(value, seen, duplicates) + checkDuplicateStorageValues(value) elseif seen[value] then - table.insert(duplicates, value) + table.insert(duplicatesValues, value) else seen[value] = true end end + return #duplicatesValues > 0 and duplicatesValues or false end --- Function to check for duplicate values in a given variable's storage -local function checkDuplicateStorageValuesWrapper(varName) - local seen = {} - local duplicates = {} - - local varTable = _G[varName] - if type(varTable) == "table" then - checkDuplicateStorageValues(varTable, seen, duplicates) - else - logger.warn("Warning: '" .. varName .. "' is not a table.") - end - - return #duplicates > 0 and duplicates or false -end - --- Function to check duplicated variable values and log the results -local function checkAndLogDuplicateValues(variableNames) - for _, variableName in ipairs(variableNames) do - local duplicates = checkDuplicateStorageValuesWrapper(variableName) - - if duplicates then - logger.warn("Checking " .. variableName .. ": Duplicate values found: " .. table.concat(duplicates, ", ")) +local function checkAndLogDuplicateValues(tableNames) + for _, tableName in ipairs(tableNames) do + local varTable = _G[tableName] + if type(varTable) == "table" then + seen = {} + duplicatesValues = {} + + local duplicates = checkDuplicateStorageValues(varTable) + if duplicates then + logger.warn("Checking {}: Duplicate values found: {}", tableName, table.concat(duplicates, ", ")) + else + logger.info("Checking {}: No duplicate values found.", tableName) + end else - logger.info("Checking " .. variableName .. ": No duplicate values found.") + logger.warn("{} is not a table. Unable to check for duplicate values.", varTable) end + + seen = nil + duplicatesValues = nil end end