-- Boss Configuration
local config = {
bosses = {
["Orshabaal"] = {
name = "Orshabaal",
position = Position(601, 1043, 7),
spawnDays = {"Friday"},
spawnTimes = {"15:30"}, -- Simplified format HH:MM 3:30 p.m.
deathMessage = "The mighty Wolf has been defeated!",
spawnMessage = "Wolf has spawned! Beware adventurers!"
},
["Morgaroth"] = {
name = "Morgaroth",
position = Position(2000, 2000, 7),
spawnDays = {"Monday", "Thursday"},
spawnTimes = {"15:30", "20:00"},
deathMessage = "Morgaroth has been defeated!",
spawnMessage = "Morgaroth has appeared!"
}
}
}
-- Days of the week
local daysOfWeek = {
[1] = "Sunday",
[2] = "Monday",
[3] = "Tuesday",
[4] = "Wednesday",
[5] = "Thursday",
[6] = "Friday",
[7] = "Saturday"
}
local activeBosses = {}
local defeatedBosses = {}
local BossManager = {
debug = true -- Set to true to enable debug messages
}
function BossManager:log(message)
if self.debug then
print(os.date("[%Y-%m-%d %H:%M:%S]") .. " " .. message)
end
end
function BossManager:add(bossId, bossName)
activeBosses[bossId] = bossName
self:log("Boss added: " .. bossName .. " (ID: " .. bossId .. ")")
end
function BossManager:remove(bossId)
local bossName = activeBosses[bossId]
if bossName then
activeBosses[bossId] = nil
self:log("Boss removed: " .. bossName .. " (ID: " .. bossId .. ")")
end
end
function BossManager:isActive(bossName)
for _, name in pairs(activeBosses) do
if name == bossName then
return true
end
end
return false
end
function BossManager:isDefeated(bossName)
return defeatedBosses[bossName] == true
end
function BossManager:markDefeated(bossName)
defeatedBosses[bossName] = true
self:log("Boss marked as defeated: " .. bossName)
end
local function isSpawnTime(bossConfig)
local currentTime = os.date("*t")
local currentTimeStr = string.format("%02d:%02d", currentTime.hour, currentTime.min)
for _, spawnTime in ipairs(bossConfig.spawnTimes) do
if currentTimeStr == spawnTime then
return true
end
end
return false
end
local function spawnBoss(bossConfig)
if BossManager:isActive(bossConfig.name) then
BossManager:log("Spawn canceled - " .. bossConfig.name .. " is already active.")
return false
end
if BossManager:isDefeated(bossConfig.name) then
BossManager:log("Spawn canceled - " .. bossConfig.name .. " has already been defeated today.")
return false
end
local monster = Game.createMonster(bossConfig.name, bossConfig.position)
if monster then
BossManager:add(monster:getId(), bossConfig.name)
monster:registerEvent("DailyBossDeath")
Game.broadcastMessage(bossConfig.spawnMessage, MESSAGE_STATUS_WARNING)
BossManager:log("Boss successfully spawned: " .. bossConfig.name)
return true
end
BossManager:log("Failed to spawn boss: " .. bossConfig.name)
return false
end
local DailyBossEvent = GlobalEvent("DailyBossSpawn")
function DailyBossEvent.onThink(interval)
local currentTime = os.date("*t")
local currentDay = daysOfWeek[currentTime.wday]
BossManager:log("Checking boss spawns - Current day: " .. currentDay)
for bossName, bossConfig in pairs(config.bosses) do
if table.contains(bossConfig.spawnDays, currentDay) then
if isSpawnTime(bossConfig) then
BossManager:log("Attempting to spawn " .. bossName)
spawnBoss(bossConfig)
end
end
end
return true
end
DailyBossEvent:interval(6000) -- Check every 1 minute
DailyBossEvent:register()
local creatureEvent = CreatureEvent("DailyBossDeath")
function creatureEvent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
local creatureId = creature:getId()
local bossName = activeBosses[creatureId]
if bossName then
local bossConfig = config.bosses[bossName]
if bossConfig then
BossManager:remove(creatureId)
BossManager:markDefeated(bossName)
Game.broadcastMessage(bossConfig.deathMessage, MESSAGE_STATUS_WARNING)
BossManager:log(bossName .. " was defeated by " .. (killer:getName() or "an unknown player"))
end
end
return true
end
creatureEvent:register()