Skip to content

Commit

Permalink
feat: implement monster respawn in Grimvale (opentibiabr#2228)
Browse files Browse the repository at this point in the history
• Adds logic for monster respawn in a specific area
• Day-based configuration to determine which monsters to respawn
• Event registered to occur at server startup
• Removing custom and duplicate spawns
  • Loading branch information
omarcopires authored Feb 15, 2024
1 parent a25b557 commit faf5d6b
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 190 deletions.
7 changes: 0 additions & 7 deletions data-otservbr-global/raids/darashia/tyrn.xml

This file was deleted.

6 changes: 0 additions & 6 deletions data-otservbr-global/raids/roshamuul/mawhawk.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
local raidSchedule = {
["Tuesday"] = {
["16:00"] = { raidName = "Midnight Panther" },
},
["Wednesday"] = {
["12:00"] = { raidName = "Draptor" },
},
["Thursday"] = {
["19:00"] = { raidName = "Undead Cavebear" },
},
["Friday"] = {
["06:00"] = { raidName = "Titanica" },
},
["Saturday"] = {
["20:00"] = { raidName = "Draptor" },
},
["Sunday"] = {
["15:00"] = { raidName = "Midnight Panther" },
["13:00"] = { raidName = "Orc Backpack" },
},
["31/10"] = {
["16:00"] = { raidName = "Halloween Hare" },
},
}

local spawnRaidsEvent = GlobalEvent("SpawnRaidsEvent")

function spawnRaidsEvent.onThink(interval, lastExecution, thinkInterval)
local currentDayOfWeek, currentDate = os.date("%A"), getRealDate()
local raidsToSpawn = {}

if raidSchedule[currentDayOfWeek] then
raidsToSpawn[#raidsToSpawn + 1] = raidSchedule[currentDayOfWeek]
end

if raidSchedule[currentDate] then
raidsToSpawn[#raidsToSpawn + 1] = raidSchedule[currentDate]
end

if #raidsToSpawn > 0 then
for i = 1, #raidsToSpawn do
local currentRaidSchedule = raidsToSpawn[i][getRealTime()]
if currentRaidSchedule and not currentRaidSchedule.alreadyExecuted then
Game.startRaid(currentRaidSchedule.raidName)
currentRaidSchedule.alreadyExecuted = true
end
end
end
return true
end

spawnRaidsEvent:interval(60000)
spawnRaidsEvent:register()

This file was deleted.

18 changes: 0 additions & 18 deletions data-otservbr-global/scripts/globalevents/spawn/mawhawk.lua

This file was deleted.

65 changes: 0 additions & 65 deletions data-otservbr-global/scripts/globalevents/spawn/raids.lua

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions data-otservbr-global/scripts/globalevents/spawn/tyrn.lua

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
local grimvaleConfig = {
position = { fromPosition = Position(33330, 31670, 7), toPosition = Position(33350, 31690, 7) },
spawnDay = 13,
}

local function createRandomMonster(position, availableMonsters)
local tile = Tile(position)
if not tile or tile:getItemById(486) or tile:hasProperty(CONST_PROP_BLOCKSOLID) or tile:getTopCreature() then
return false
end

local monsterName = availableMonsters[math.random(#availableMonsters)]
local monster = Game.createMonster(monsterName, position)
if monster then
monster:setSpawnPosition()
monster:remove()
end
return true
end

local function spawnMonsters(monstersToSpawn)
for x = grimvaleConfig.position.fromPosition.x, grimvaleConfig.position.toPosition.x do
for y = grimvaleConfig.position.fromPosition.y, grimvaleConfig.position.toPosition.y do
if math.random(1000) >= 983 then
if createRandomMonster(Position(x, y, 7), monstersToSpawn) then
break
end
end
end
end
end

local grimvaleRespawnEvent = GlobalEvent("GrimvaleRespawnEvent")

function grimvaleRespawnEvent.onStartup()
spawnMonsters(grimvaleConfig.spawnDay == tonumber(os.date("%d")) and { "wereboar", "werebadger" } or { "bandit", "badger", "blue butterfly", "yellow butterfly" })
return true
end

grimvaleRespawnEvent:register()

0 comments on commit faf5d6b

Please sign in to comment.