Skip to content

Commit

Permalink
fix: some functions and their usages (opentibiabr#1847)
Browse files Browse the repository at this point in the history
- Fixed clearBossRoom and roomIsOccupied functions, and their usages.
- Removed unused functions.
- Improved checkBoss function globally.
  • Loading branch information
elsongabriel authored Nov 20, 2023
1 parent 9857758 commit 8993119
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 36 additions & 40 deletions data-otservbr-global/scripts/actions/quests/first_dragon/lever.lua
Original file line number Diff line number Diff line change
@@ -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) },
Expand Down Expand Up @@ -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.")
Expand All @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 2 additions & 26 deletions data-otservbr-global/scripts/actions/roshamuul/prison/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading

0 comments on commit 8993119

Please sign in to comment.