function clearBossRoom(playerId, bossId, 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:getId() == playerId then
spectator:teleportTo(boss.exitPosition)
boss.exitPosition:sendMagicEffect(CONST_ME_TELEPORT)
end
if spectator:isMonster() and spectator:getId() == bossId then
spectator:remove()
end
end
end
local function startsBoss(boss, player, item)
-- We are checking players in waitRoom and teleport to bossRoom
local spectators = Game.getSpectators(boss.waitRoom.position, false, true, boss.waitRoom.waitRoomX, boss.waitRoom.waitRoomX, boss.waitRoom.waitRoomY, boss.waitRoom.waitRoomY)
for i = 1, #spectators do
spectator = spectators[i]
spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
spectator:teleportTo(boss.newPos)
boss.newPos:sendMagicEffect(CONST_ME_TELEPORT)
end
-- Now we are sending a message
player:say(boss.message.enterBossRoom, TALKTYPE_MONSTER_SAY, false, player, boss.message.whereinBossRoom)
-- Now we create the monsters
local monster = Game.createMonster(boss.bossName, boss.bossPosition)
if not monster then
print(">> Houston, we have a problem to create boss ".. boss.bossName ..".")
return true
end
-- addEvent to clearBossRoom
addEvent(clearBossRoom, boss.bossRoom.timeToKick * 60 * 1000, player:getId(), monster:getId(), boss.centerRoom, boss.bossRoom.rangeX, boss.bossRoom.rangeY, fromPosition)
-- Back the lever
item:transform(9827)
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local boss = bosses[item.uid]
if not boss then
return true
end
-- No one will enter in the room anymore.
Game.setStorageValue(boss.globalStorage, 1)
-- Transport to Room
addEvent(startsBoss, 1 * 60 * 1000, boss:getId(), player:getId(), item:getId())
return true
end