From 8993119c0ae358d7c14fcc2a0bf93078035fbe25 Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Sun, 19 Nov 2023 21:36:27 -0300 Subject: [PATCH] fix: some functions and their usages (#1847) - Fixed clearBossRoom and roomIsOccupied functions, and their usages. - Removed unused functions. - Improved checkBoss function globally. --- .../scripts/actions/arena_pvp/arena_10x10.lua | 2 +- .../scripts/actions/arena_pvp/arena_2x2.lua | 2 +- .../lever_death_priest_shargon.lua | 2 +- .../quests/dark_trails/lever_the_ravager.lua | 2 +- .../actions/quests/first_dragon/lever.lua | 76 +++++++++---------- .../actions/roshamuul/prison/golden.lua | 2 +- .../scripts/actions/roshamuul/prison/keys.lua | 28 +------ .../quests/cobra_minis_custodian.lua | 20 +---- .../quests/cobra_minis_gaffir.lua | 20 +---- .../globalevents/quests/cobra_minis_quaid.lua | 20 +---- .../secret_library_grand_canon_dominus.lua | 20 +---- .../secret_library_grand_chaplain_gaunder.lua | 20 +---- .../secret_library_grand_commander_soeren.lua | 22 +----- .../secret_library_preceptor_lazare.lua | 20 +---- .../scripts/globalevents/spawn/mawhawk.lua | 20 +---- .../spawn/thawing_dragon_lord.lua | 20 +---- .../scripts/globalevents/spawn/tyrn.lua | 20 +---- .../quests/first_dragon/entrance_teleport.lua | 4 +- .../quests/killing_in_the_name_of/boss.lua | 27 +------ .../movement-cave_spider_room.lua | 6 +- .../scripts/quests/the_annihilator/lever.lua | 4 +- .../movement-minotaur_boss.lua | 2 +- .../movement-kroazur_room.lua | 6 +- data/libs/functions/functions.lua | 28 +++++-- data/libs/functions/position.lua | 17 +---- 25 files changed, 93 insertions(+), 317 deletions(-) diff --git a/data-otservbr-global/scripts/actions/arena_pvp/arena_10x10.lua b/data-otservbr-global/scripts/actions/arena_pvp/arena_10x10.lua index 45144b499ae..0d8e650ddda 100644 --- a/data-otservbr-global/scripts/actions/arena_pvp/arena_10x10.lua +++ b/data-otservbr-global/scripts/actions/arena_pvp/arena_10x10.lua @@ -20,7 +20,7 @@ local arena10x10 = Action() function arena10x10.onUse(player, item, fromPosition, target, toPosition, monster, isHotkey) if toPosition == Position(32240, 32179, 8) then - if roomIsOccupied(setting.centerRoom, setting.range, setting.range) then + if roomIsOccupied(setting.centerRoom, false, setting.range, setting.range) then player:say("Please wait for the fighters come out of the arena.", TALKTYPE_ORANGE_1) return true end diff --git a/data-otservbr-global/scripts/actions/arena_pvp/arena_2x2.lua b/data-otservbr-global/scripts/actions/arena_pvp/arena_2x2.lua index 1d8e53bf420..18c88aa42a6 100644 --- a/data-otservbr-global/scripts/actions/arena_pvp/arena_2x2.lua +++ b/data-otservbr-global/scripts/actions/arena_pvp/arena_2x2.lua @@ -14,7 +14,7 @@ local arena2x2 = Action() function arena2x2.onUse(player, item, fromPosition, target, toPosition, monster, isHotkey) if toPosition == Position(32271, 32180, 8) then - if roomIsOccupied(setting.centerRoom, setting.range, setting.range) then + if roomIsOccupied(setting.centerRoom, false, setting.range, setting.range) then player:say("Please wait for the fighters come out of the arena.", TALKTYPE_ORANGE_1) return true end diff --git a/data-otservbr-global/scripts/actions/quests/dark_trails/lever_death_priest_shargon.lua b/data-otservbr-global/scripts/actions/quests/dark_trails/lever_death_priest_shargon.lua index d2074390aa8..b107ae2e449 100644 --- a/data-otservbr-global/scripts/actions/quests/dark_trails/lever_death_priest_shargon.lua +++ b/data-otservbr-global/scripts/actions/quests/dark_trails/lever_death_priest_shargon.lua @@ -32,7 +32,7 @@ local setting = { local leverDeathPriestShargon = Action() function leverDeathPriestShargon.onUse(player, item, fromPosition, target, toPosition, isHotkey) if item.itemid == 2772 then - if roomIsOccupied(setting.centerRoom, setting.range, setting.range) then + if roomIsOccupied(setting.centerRoom, false, setting.range, setting.range) then player:say("Someone is fighting against the boss! You need wait awhile.", TALKTYPE_MONSTER_SAY) return true end diff --git a/data-otservbr-global/scripts/actions/quests/dark_trails/lever_the_ravager.lua b/data-otservbr-global/scripts/actions/quests/dark_trails/lever_the_ravager.lua index f9c5d4a7231..1e76aef4112 100644 --- a/data-otservbr-global/scripts/actions/quests/dark_trails/lever_the_ravager.lua +++ b/data-otservbr-global/scripts/actions/quests/dark_trails/lever_the_ravager.lua @@ -24,7 +24,7 @@ local setting = { local leverTheRavager = Action() function leverTheRavager.onUse(player, item, fromPosition, target, toPosition, isHotkey) if item.itemid == 2772 then - if roomIsOccupied(setting.centerRoom, setting.range, setting.range) then + if roomIsOccupied(setting.centerRoom, false, setting.range, setting.range) then player:say("Someone is fighting against the boss! You need wait awhile.", TALKTYPE_MONSTER_SAY) return true end diff --git a/data-otservbr-global/scripts/actions/quests/first_dragon/lever.lua b/data-otservbr-global/scripts/actions/quests/first_dragon/lever.lua index 174455e6574..2e794aa7fa8 100644 --- a/data-otservbr-global/scripts/actions/quests/first_dragon/lever.lua +++ b/data-otservbr-global/scripts/actions/quests/first_dragon/lever.lua @@ -1,37 +1,33 @@ local lever = Action() -local setting = { +local config = { centerRoom = { x = 33616, y = 31022, z = 14 }, range = 10, -} - -local monsterPosition = { - { position = Position(33574, 31013, 14) }, - { position = Position(33592, 31013, 14) }, - { position = Position(33583, 31022, 14) }, - { position = Position(33574, 31031, 14) }, - { position = Position(33592, 31031, 14) }, -} - -local playerPositions = { - Position(33582, 30993, 14), - Position(33583, 30993, 14), - Position(33584, 30993, 14), - Position(33582, 30994, 14), - Position(33583, 30994, 14), - Position(33584, 30994, 14), - Position(33582, 30995, 14), - Position(33583, 30995, 14), - Position(33584, 30995, 14), - Position(33582, 30996, 14), - Position(33583, 30996, 14), - Position(33584, 30996, 14), - Position(33582, 30997, 14), - Position(33583, 30997, 14), - Position(33584, 30997, 14), -} - -local config = { + storage = Storage.FirstDragon.FirstDragonTimer, + monsterPosition = { + { position = Position(33574, 31013, 14) }, + { position = Position(33592, 31013, 14) }, + { position = Position(33583, 31022, 14) }, + { position = Position(33574, 31031, 14) }, + { position = Position(33592, 31031, 14) }, + }, + playerPositions = { + Position(33582, 30993, 14), + Position(33583, 30993, 14), + Position(33584, 30993, 14), + Position(33582, 30994, 14), + Position(33583, 30994, 14), + Position(33584, 30994, 14), + Position(33582, 30995, 14), + Position(33583, 30995, 14), + Position(33584, 30995, 14), + Position(33582, 30996, 14), + Position(33583, 30996, 14), + Position(33584, 30996, 14), + Position(33582, 30997, 14), + Position(33583, 30997, 14), + Position(33584, 30997, 14), + }, toPosition1 = Position(33574, 31017, 14), roomTile1 = { { fromPosition = Position(33582, 30993, 14) }, @@ -66,8 +62,8 @@ local config = { function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey) if item.itemid == 8911 then - for i = 1, #playerPositions do - local creature = Tile(playerPositions[i]):getTopCreature() + for i = 1, #config.playerPositions do + local creature = Tile(config.playerPositions[i]):getTopCreature() if not creature then item:transform(8912) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need 5 players to fight with this boss.") @@ -76,19 +72,19 @@ function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey) end end if item.itemid == 8911 then - if roomIsOccupied(setting.centerRoom, setting.range, setting.range) then + if roomIsOccupied(config.centerRoom, false, config.range, config.range) then player:say("Someone is fighting against the boss! You need wait awhile.", TALKTYPE_MONSTER_SAY) return true end for d = 1, 5 do - Game.createMonster("unbeatable dragon", position(math.random(33610, 33622), math.random(31016, 31030), 14), true, true) + Game.createMonster("unbeatable dragon", Position(math.random(33610, 33622), math.random(31016, 31030), 14), true, true) end - for b = 1, #monsterPosition do - Game.createMonster("fallen challenger", monsterPosition[b].position, true, true) + for b = 1, #config.monsterPosition do + Game.createMonster("fallen challenger", config.monsterPosition[b].position, true, true) end - for i = 1, #playerPositions do - local creature = Tile(playerPositions[i]):getTopCreature() + for i = 1, #config.playerPositions do + local creature = Tile(config.playerPositions[i]):getTopCreature() if creature then for i = 1, #config.roomTile1 do local toRoom1 = Tile(config.roomTile1[i].fromPosition):getTopCreature() @@ -113,12 +109,12 @@ function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey) end end creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - creature:setStorageValue(Storage.FirstDragon.FirstDragonTimer, os.time() + 20 * 3600) + creature:setStorageValue(config.storage, os.time() + 20 * 3600) creature:setStorageValue(Storage.FirstDragon.SomewhatBeatable, 0) end end -- One hour for clean the room - addEvent(clearRoom, 60 * 60 * 1000, Position(33583, 31022, 14), 50, 50, fromPosition) + addEvent(clearRoom, 60 * 60 * 1000, Position(33583, 31022, 14), 50, 50, config.storage) Game.createMonster("spirit of fertility", Position(33625, 31021, 14), true, true) item:transform(8912) elseif item.itemid == 8912 then diff --git a/data-otservbr-global/scripts/actions/roshamuul/prison/golden.lua b/data-otservbr-global/scripts/actions/roshamuul/prison/golden.lua index 40258b086d2..0e5c8f40934 100644 --- a/data-otservbr-global/scripts/actions/roshamuul/prison/golden.lua +++ b/data-otservbr-global/scripts/actions/roshamuul/prison/golden.lua @@ -31,7 +31,7 @@ function golden.onUse(player, item, fromPosition, target, toPosition, monster, i end if toPosition == Position(33606, 32362, 11) then - if roomIsOccupied(setting.centerRoom, setting.range, setting.range) or Game.getStorageValue(setting.clearRoomStorage) == 1 then + if roomIsOccupied(setting.centerRoom, false, setting.range, setting.range) or Game.getStorageValue(setting.clearRoomStorage) == 1 then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Someone is fighting against the boss! You need wait awhile.") return true end diff --git a/data-otservbr-global/scripts/actions/roshamuul/prison/keys.lua b/data-otservbr-global/scripts/actions/roshamuul/prison/keys.lua index f84fc173750..b8b5561bfee 100644 --- a/data-otservbr-global/scripts/actions/roshamuul/prison/keys.lua +++ b/data-otservbr-global/scripts/actions/roshamuul/prison/keys.lua @@ -37,30 +37,6 @@ local config = { }, } -local function roomIsOccupied(centerPosition, rangeX, rangeY) - local spectators = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - if #spectators ~= 0 then - return true - end - - return false -end - -local function clearBossRoom(playerId, centerPosition, rangeX, rangeY, exitPosition) - local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spectator = spectators[i] - if spectator:isPlayer() and spectator.uid == playerId then - spectator:teleportTo(exitPosition) - exitPosition:sendMagicEffect(CONST_ME_TELEPORT) - end - - if spectator:isMonster() then - spectator:remove() - end - end -end - local keys = Action() function keys.onUse(player, item, fromPosition, target, toPosition, isHotkey) @@ -78,7 +54,7 @@ function keys.onUse(player, item, fromPosition, target, toPosition, isHotkey) return true end - if roomIsOccupied(tmpConfig.centerPosition, tmpConfig.rangeX, tmpConfig.rangeY) then + if roomIsOccupied(tmpConfig.centerPosition, false, tmpConfig.rangeX, tmpConfig.rangeY) then player:sendCancelMessage("There is someone in the room.") return true end @@ -93,7 +69,7 @@ function keys.onUse(player, item, fromPosition, target, toPosition, isHotkey) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have fifteen minutes to kill and loot this boss, else you will lose that chance.") -- Let's roll - addEvent(clearBossRoom, 60 * tmpConfig.time * 1000, player:getId(), tmpConfig.centerPosition, tmpConfig.rangeX, tmpConfig.rangeY, tmpConfig.exitPosition) + addEvent(clearBossRoom, 60 * tmpConfig.time * 1000, player:getId(), tmpConfig.centerPosition, false, tmpConfig.rangeX, tmpConfig.rangeY, tmpConfig.exitPosition) item:remove() player:teleportTo(tmpConfig.newPosition) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) diff --git a/data-otservbr-global/scripts/globalevents/quests/cobra_minis_custodian.lua b/data-otservbr-global/scripts/globalevents/quests/cobra_minis_custodian.lua index 997c4bfbcdf..c21f58bb90e 100644 --- a/data-otservbr-global/scripts/globalevents/quests/cobra_minis_custodian.lua +++ b/data-otservbr-global/scripts/globalevents/quests/cobra_minis_custodian.lua @@ -6,27 +6,9 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local miniBoss = GlobalEvent("custodian") function miniBoss.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true - end - - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) + checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName, config.bossPosition) return true end diff --git a/data-otservbr-global/scripts/globalevents/quests/cobra_minis_gaffir.lua b/data-otservbr-global/scripts/globalevents/quests/cobra_minis_gaffir.lua index 722854eb021..c6f814cbc04 100644 --- a/data-otservbr-global/scripts/globalevents/quests/cobra_minis_gaffir.lua +++ b/data-otservbr-global/scripts/globalevents/quests/cobra_minis_gaffir.lua @@ -6,27 +6,9 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local miniBoss = GlobalEvent("gaffir") function miniBoss.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true - end - - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) + checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName, config.bossPosition) return true end diff --git a/data-otservbr-global/scripts/globalevents/quests/cobra_minis_quaid.lua b/data-otservbr-global/scripts/globalevents/quests/cobra_minis_quaid.lua index 7ab469e5186..3aeded3beee 100644 --- a/data-otservbr-global/scripts/globalevents/quests/cobra_minis_quaid.lua +++ b/data-otservbr-global/scripts/globalevents/quests/cobra_minis_quaid.lua @@ -6,27 +6,9 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local miniBoss = GlobalEvent("guard captain quaid") function miniBoss.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true - end - - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) + checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName, config.bossPosition) return true end diff --git a/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_canon_dominus.lua b/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_canon_dominus.lua index 4556bee10a3..c2527792c0e 100644 --- a/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_canon_dominus.lua +++ b/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_canon_dominus.lua @@ -6,27 +6,9 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local canonDominus = GlobalEvent("canon dominus") function canonDominus.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true - end - - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) + checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName, config.bossPosition) return true end diff --git a/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_chaplain_gaunder.lua b/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_chaplain_gaunder.lua index 264ea1e0f2f..402005b0aa8 100644 --- a/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_chaplain_gaunder.lua +++ b/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_chaplain_gaunder.lua @@ -6,27 +6,9 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local chaplaingaunder = GlobalEvent("chaplaingaunder") function chaplaingaunder.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true - end - - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) + checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName, config.bossPosition) return true end diff --git a/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_commander_soeren.lua b/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_commander_soeren.lua index 0804b18e3e8..64f4ab330e5 100644 --- a/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_commander_soeren.lua +++ b/data-otservbr-global/scripts/globalevents/quests/secret_library_grand_commander_soeren.lua @@ -6,29 +6,11 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local grandCommander = GlobalEvent("grand commander") function grandCommander.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true - end - - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) + checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName, config.bossPosition) return true end -grandCommander:interval(15 * 60 * 1000) +grandCommander:interval(15 * 60 * 1000) -- 15 minutes grandCommander:register() diff --git a/data-otservbr-global/scripts/globalevents/quests/secret_library_preceptor_lazare.lua b/data-otservbr-global/scripts/globalevents/quests/secret_library_preceptor_lazare.lua index 4e2a7a053d1..a279aeeb804 100644 --- a/data-otservbr-global/scripts/globalevents/quests/secret_library_preceptor_lazare.lua +++ b/data-otservbr-global/scripts/globalevents/quests/secret_library_preceptor_lazare.lua @@ -6,27 +6,9 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local preceptorLazare = GlobalEvent("preceptor lazare") function preceptorLazare.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true - end - - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) + checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName, config.bossPosition) return true end diff --git a/data-otservbr-global/scripts/globalevents/spawn/mawhawk.lua b/data-otservbr-global/scripts/globalevents/spawn/mawhawk.lua index 4ffe051e04f..36817060264 100644 --- a/data-otservbr-global/scripts/globalevents/spawn/mawhawk.lua +++ b/data-otservbr-global/scripts/globalevents/spawn/mawhawk.lua @@ -6,27 +6,11 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local mawhawk = GlobalEvent("mawhawk") function mawhawk.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true + if not checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then + addEvent(Game.broadcastMessage, 150, "Beware! Mawhawk!", MESSAGE_EVENT_ADVANCE) end - addEvent(Game.broadcastMessage, 150, "Beware! Mawhawk!", MESSAGE_EVENT_ADVANCE) - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) return true end diff --git a/data-otservbr-global/scripts/globalevents/spawn/thawing_dragon_lord.lua b/data-otservbr-global/scripts/globalevents/spawn/thawing_dragon_lord.lua index 3d47c6f2818..eecbd29022b 100644 --- a/data-otservbr-global/scripts/globalevents/spawn/thawing_dragon_lord.lua +++ b/data-otservbr-global/scripts/globalevents/spawn/thawing_dragon_lord.lua @@ -6,28 +6,10 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local thawingDragonLord = GlobalEvent("thawing dragon lord") function thawingDragonLord.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true - end - - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) + checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName, config.bossPosition) return true end diff --git a/data-otservbr-global/scripts/globalevents/spawn/tyrn.lua b/data-otservbr-global/scripts/globalevents/spawn/tyrn.lua index 674d5065695..79959d1a28d 100644 --- a/data-otservbr-global/scripts/globalevents/spawn/tyrn.lua +++ b/data-otservbr-global/scripts/globalevents/spawn/tyrn.lua @@ -6,27 +6,11 @@ local config = { rangeY = 50, } -local function checkBoss(centerPosition, rangeX, rangeY, bossName) - local spectators, spec = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spec = spectators[i] - if spec:isMonster() then - if spec:getName() == bossName then - return true - end - end - end - return false -end - local tyrn = GlobalEvent("tyrn") function tyrn.onThink(interval, lastExecution) - if checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then - return true + if not checkBoss(config.centerPosition, config.rangeX, config.rangeY, config.monsterName) then + addEvent(Game.broadcastMessage, 150, "Beware of Tyrn!", MESSAGE_EVENT_ADVANCE) end - addEvent(Game.broadcastMessage, 150, "Beware of Tyrn!", MESSAGE_EVENT_ADVANCE) - local boss = Game.createMonster(config.monsterName, config.bossPosition, true, true) - boss:setReward(true) return true end diff --git a/data-otservbr-global/scripts/movements/quests/first_dragon/entrance_teleport.lua b/data-otservbr-global/scripts/movements/quests/first_dragon/entrance_teleport.lua index f0d30494c8c..9eb046b74f7 100644 --- a/data-otservbr-global/scripts/movements/quests/first_dragon/entrance_teleport.lua +++ b/data-otservbr-global/scripts/movements/quests/first_dragon/entrance_teleport.lua @@ -49,7 +49,7 @@ function entranceTeleport.onStepIn(creature, item, position, fromPosition) return true end - if roomIsOccupied(setting.bossPos, setting.range, setting.range) then + if roomIsOccupied(setting.bossPos, false, setting.range, setting.range) then player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) player:teleportTo(fromPosition) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) @@ -84,7 +84,7 @@ function entranceTeleport.onStepIn(creature, item, position, fromPosition) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) player:say("You have ten minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.", TALKTYPE_MONSTER_SAY) player:setBossCooldown(setting.bossName, os.time() + 2 * 3600) - addEvent(clearBossRoom, 60 * 30 * 1000, player.uid, monster.uid, setting.bossPos, setting.range, fromPosition) + addEvent(clearBossRoom, 60 * 30 * 1000, player.uid, setting.bossPos, false, setting.range, setting.range, fromPosition) return true end return true diff --git a/data-otservbr-global/scripts/movements/quests/killing_in_the_name_of/boss.lua b/data-otservbr-global/scripts/movements/quests/killing_in_the_name_of/boss.lua index f0a4b171847..531e3b53526 100644 --- a/data-otservbr-global/scripts/movements/quests/killing_in_the_name_of/boss.lua +++ b/data-otservbr-global/scripts/movements/quests/killing_in_the_name_of/boss.lua @@ -1,26 +1,3 @@ -local function roomIsOccupied(centerPosition, rangeX, rangeY) - local spectators = Game.getSpectators(centerPosition, false, true, rangeX, rangeX, rangeY, rangeY) - if #spectators ~= 0 then - return true - end - return false -end - -local function clearBossRoom(playerId, bossId, centerPosition, rangeX, rangeY, exitPosition) - local spectators = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - local spectator - for i = 1, #spectators do - spectator = spectators[i] - if spectator:isPlayer() and spectator.uid == playerId then - spectator:teleportTo(exitPosition) - exitPosition:sendMagicEffect(CONST_ME_TELEPORT) - end - if spectator:isMonster() and spectator.uid == bossId then - spectator:remove() - end - end -end - local bosses = { { bossName = "the snapper", @@ -418,7 +395,7 @@ function boss.onStepIn(creature, item, position, fromPosition) end for a = 1, #bosses do if player:getPosition() == Position(bosses[a].teleportPosition) then - if player:getStorageValue(bosses[a].storage) ~= 1 or roomIsOccupied(bosses[a].centerPosition, bosses[a].rangeX, bosses[a].rangeY) then + if player:getStorageValue(bosses[a].storage) ~= 1 or roomIsOccupied(bosses[a].centerPosition, true, bosses[a].rangeX, bosses[a].rangeY) then player:teleportTo(fromPosition) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) return true @@ -436,7 +413,7 @@ function boss.onStepIn(creature, item, position, fromPosition) if not monster then return true end - addEvent(clearBossRoom, 60 * 10 * 1000, player.uid, monster.uid, bosses[a].centerPosition, bosses[a].rangeX, bosses[a].rangeY, fromPosition) + addEvent(clearBossRoom, 60 * 10 * 1000, player.uid, bosses[a].centerPosition, false, bosses[a].rangeX, bosses[a].rangeY, fromPosition) player:say("You have ten minutes to kill and loot this boss. Otherwise you will lose that chance and will be kicked out.", TALKTYPE_MONSTER_SAY) end end diff --git a/data-otservbr-global/scripts/quests/hidden_threats/movement-cave_spider_room.lua b/data-otservbr-global/scripts/quests/hidden_threats/movement-cave_spider_room.lua index 6e3f722929b..2612e99c57d 100644 --- a/data-otservbr-global/scripts/quests/hidden_threats/movement-cave_spider_room.lua +++ b/data-otservbr-global/scripts/quests/hidden_threats/movement-cave_spider_room.lua @@ -35,14 +35,14 @@ function caveSpiderRoom.onStepIn(creature, item, position, fromPosition) return true end - if roomIsOccupied(room.centerPos, room.rangeX, room.rangeY) then + if roomIsOccupied(room.centerPos, false, room.rangeX, room.rangeY) then player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) player:teleportTo(room.exitPos) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) return true end - clearRoom(room.centerPos, room.rangeX, room.rangeY, fromPosition) + clearRoom(room.centerPos, room.rangeX, room.rangeY) local monster = Game.createMonster(room.bossName, room.bossPos, true, true) for i = 1, 3 do Game.createMonster("Tarantula", room.tarantulasPos[i], true, true) @@ -54,7 +54,7 @@ function caveSpiderRoom.onStepIn(creature, item, position, fromPosition) position:sendMagicEffect(CONST_ME_TELEPORT) player:teleportTo(room.newPos) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - addEvent(clearBossRoom, 60 * room.time * 1000, player.uid, room.centerPos, room.rangeX, room.rangeY, room.exitPos) + addEvent(clearBossRoom, 60 * room.time * 1000, player.uid, room.centerPos, false, room.rangeX, room.rangeY, room.exitPos) player:setStorageValue(room.access, 10) return true end diff --git a/data-otservbr-global/scripts/quests/the_annihilator/lever.lua b/data-otservbr-global/scripts/quests/the_annihilator/lever.lua index f32e2389173..62e92e8acd6 100644 --- a/data-otservbr-global/scripts/quests/the_annihilator/lever.lua +++ b/data-otservbr-global/scripts/quests/the_annihilator/lever.lua @@ -39,7 +39,7 @@ function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey) end -- Checks if there are still players inside the room, if so, return true - if Position.hasPlayer(setting.centerDemonRoomPosition, 4, 4) then + if roomIsOccupied(setting.centerDemonRoomPosition, true, 4, 4) then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the quest room.") return true end @@ -67,7 +67,7 @@ function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey) return true end -- Not be able to push the lever back if someone is still inside the monsters room - if Position.hasPlayer(setting.centerDemonRoomPosition, 4, 4) then + if roomIsOccupied(setting.centerDemonRoomPosition, true, 4, 4) then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A team is already inside the quest room.") return true end diff --git a/data-otservbr-global/scripts/quests/the_new_frontier/movement-minotaur_boss.lua b/data-otservbr-global/scripts/quests/the_new_frontier/movement-minotaur_boss.lua index 8a1d647a7cb..9c6ff1b3593 100644 --- a/data-otservbr-global/scripts/quests/the_new_frontier/movement-minotaur_boss.lua +++ b/data-otservbr-global/scripts/quests/the_new_frontier/movement-minotaur_boss.lua @@ -25,7 +25,7 @@ function minotaurBoss.onStepIn(creature, item, position, fromPosition) return false end - if Position.hasPlayer(setting.arenaPosition, 6, 6) or player:getStorageValue(TheNewFrontier.Questline) ~= 17 then + if roomIsOccupied(setting.arenaPosition, true, 6, 6) or player:getStorageValue(TheNewFrontier.Questline) ~= 17 then player:teleportTo(fromPosition) fromPosition:sendMagicEffect(CONST_ME_TELEPORT) return player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You don't have access to this area.") diff --git a/data-otservbr-global/scripts/quests/threatened_dreams/movement-kroazur_room.lua b/data-otservbr-global/scripts/quests/threatened_dreams/movement-kroazur_room.lua index 8af4f8df79b..46b6a58bd5e 100644 --- a/data-otservbr-global/scripts/quests/threatened_dreams/movement-kroazur_room.lua +++ b/data-otservbr-global/scripts/quests/threatened_dreams/movement-kroazur_room.lua @@ -49,7 +49,7 @@ function kroazurRoom.onStepIn(creature, item, position, fromPosition) return true end - if roomIsOccupied(room.bossPos, room.rangeX, room.rangeY) then + if roomIsOccupied(room.bossPos, false, room.rangeX, room.rangeY) then position:sendMagicEffect(CONST_ME_TELEPORT) player:teleportTo(fromPosition, true) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) @@ -57,7 +57,7 @@ function kroazurRoom.onStepIn(creature, item, position, fromPosition) return true end - clearRoom(room.bossPos, room.rangeX, room.rangeY, fromPosition) + clearRoom(room.bossPos, room.rangeX, room.rangeY) local monster = Game.createMonster(room.bossName, room.bossPos, true, true) if not monster then return true @@ -67,7 +67,7 @@ function kroazurRoom.onStepIn(creature, item, position, fromPosition) player:teleportTo(room.newPos) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) player:say("You have ten minutes to kill and loot this boss, else you will lose that chance and will be kicked out.", TALKTYPE_MONSTER_SAY) - addEvent(clearBossRoom, 60 * room.time * 1000, player.uid, room.centerPos, room.rangeX, room.rangeY, room.exitPos) + addEvent(clearBossRoom, 60 * room.time * 1000, player.uid, room.centerPos, false, room.rangeX, room.rangeY, room.exitPos) player:setBossCooldown(room.bossName, os.time() + 2 * 3600) return true end diff --git a/data/libs/functions/functions.lua b/data/libs/functions/functions.lua index b30aa93272b..95e6ccb3e3a 100644 --- a/data/libs/functions/functions.lua +++ b/data/libs/functions/functions.lua @@ -244,8 +244,26 @@ function setPlayerMarriageStatus(id, val) db.query("UPDATE `players` SET `marriage_status` = " .. val .. " WHERE `id` = " .. id) end -function clearBossRoom(playerId, bossId, centerPosition, rangeX, rangeY, exitPosition) - local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) +function checkBoss(centerPosition, rangeX, rangeY, bossName, bossPos) + local spectators, found = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY), false + for i = 1, #spectators do + local spec = spectators[i] + if spec:isMonster() then + if spec:getName() == bossName then + found = true + break + end + end + end + if not found then + local boss = Game.createMonster(bossName, bossPos, true, true) + boss:setReward(true) + end + return found +end + +function clearBossRoom(playerId, centerPosition, onlyPlayers, rangeX, rangeY, exitPosition) + local spectators, spectator = Game.getSpectators(centerPosition, false, onlyPlayers, rangeX, rangeX, rangeY, rangeY) for i = 1, #spectators do spectator = spectators[i] if spectator:isPlayer() and spectator.uid == playerId then @@ -267,13 +285,13 @@ function clearRoom(centerPosition, rangeX, rangeY, resetGlobalStorage) spectator:remove() end end - if Game.getStorageValue(resetGlobalStorage) == 1 then + if resetGlobalStorage ~= nil and Game.getStorageValue(resetGlobalStorage) == 1 then Game.setStorageValue(resetGlobalStorage, -1) end end -function roomIsOccupied(centerPosition, rangeX, rangeY) - local spectators = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) +function roomIsOccupied(centerPosition, onlyPlayers, rangeX, rangeY) + local spectators = Game.getSpectators(centerPosition, false, onlyPlayers, rangeX, rangeX, rangeY, rangeY) if #spectators ~= 0 then return true end diff --git a/data/libs/functions/position.lua b/data/libs/functions/position.lua index d3ac6667be3..2ba38968f5f 100644 --- a/data/libs/functions/position.lua +++ b/data/libs/functions/position.lua @@ -127,23 +127,8 @@ function Position:compare(position) return self.x == position.x and self.y == position.y and self.z == position.z end -function Position.hasPlayer(centerPosition, rangeX, rangeY) - local spectators = Game.getSpectators(centerPosition, false, true, rangeX, rangeX, rangeY, rangeY) - if #spectators ~= 0 then - return true - end - return false -end - function Position.removeMonster(centerPosition, rangeX, rangeY) - local spectators = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - local spectators, spectator = Game.getSpectators(centerPosition, false, false, rangeX, rangeX, rangeY, rangeY) - for i = 1, #spectators do - spectator = spectators[i] - if spectator:isMonster() then - spectator:remove() - end - end + clearRoom(centerPosition, false, false) end function Position.getFreePosition(from, to)