forked from opentibiabr/canary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement monster respawn in Grimvale (opentibiabr#2228)
• 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
1 parent
a25b557
commit faf5d6b
Showing
9 changed files
with
93 additions
and
190 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
data-otservbr-global/scripts/globalevents/others/raids_schedule.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
59 changes: 0 additions & 59 deletions
59
data-otservbr-global/scripts/globalevents/spawn/grimvale_respawn.lua
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
data-otservbr-global/scripts/globalevents/spawn/mawhawk.lua
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
data-otservbr-global/scripts/globalevents/spawn/thawing_dragon_lord.lua
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
data-otservbr-global/scripts/world_changes/grimvale_respawn_event.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |