Skip to content

Commit

Permalink
fix: lloyd and thorn knight boss fights (opentibiabr#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
luan authored and marcusvcj committed Nov 20, 2023
1 parent 00a3014 commit 505230e
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,95 @@
local config = {
boss = {
name = "The Enraged Thorn Knight",
createFunction = function()
return Game.createMonster("Mounted Thorn Knight", Position(32624, 32880, 14), true, true)
end,
},
requiredLevel = 250,
bossName = "Thorn Knight",
timeToFightAgain = 20, -- In hour
timeToDefeat = 15, -- In minutes
playerPositions = {
{ pos = Position(32657, 32877, 14), teleport = Position(32624, 32886, 14), effect = CONST_ME_TELEPORT },
{ pos = Position(32657, 32878, 14), teleport = Position(32624, 32886, 14), effect = CONST_ME_TELEPORT },
{ pos = Position(32657, 32879, 14), teleport = Position(32624, 32886, 14), effect = CONST_ME_TELEPORT },
{ pos = Position(32657, 32880, 14), teleport = Position(32624, 32886, 14), effect = CONST_ME_TELEPORT },
{ pos = Position(32657, 32881, 14), teleport = Position(32624, 32886, 14), effect = CONST_ME_TELEPORT },
},
onUseExtra = function(player)
for d = 1, 6 do
Game.createMonster("possessed tree", Position(math.random(32619, 32629), math.random(32877, 32884), 14), true, true)
end
end,
bossPosition = Position(32624, 32880, 14),
specPos = {
from = Position(32613, 32869, 14),
to = Position(32636, 32892, 14),
},
exit = Position(32678, 32888, 14),
}

local lever = BossLever(config)
lever:position(Position(32657, 32876, 14))
lever:register()
local forgottenKnowledgeThorn = Action()
function forgottenKnowledgeThorn.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if config.playerPositions[1].pos ~= player:getPosition() then
return false
end

local spec = Spectators()
spec:setOnlyPlayer(false)
spec:setRemoveDestination(config.exit)
spec:setCheckPosition(config.specPos)
spec:check()

if spec:getPlayers() > 0 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There's someone fighting with " .. config.bossName .. ".")
return true
end

local lever = Lever()
lever:setPositions(config.playerPositions)
lever:setCondition(function(creature)
if not creature or not creature:isPlayer() then
return true
end

if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face " .. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
return false
end
return true
end)

lever:checkPositions()
if lever:checkConditions() then
spec:removeMonsters()
for d = 1, 6 do
Game.createMonster("possessed tree", Position(math.random(32619, 32629), math.random(32877, 32884), 14), true, true)
end
local monster = Game.createMonster("mounted thorn knight", config.bossPosition, true, true)
if not monster then
return true
end
lever:teleportPlayers()
lever:setCooldownAllPlayers("The Enraged Thorn Knight", os.time() + config.timeToFightAgain * 3600)
addEvent(function()
local old_players = lever:getInfoPositions()
spec:clearCreaturesCache()
spec:setOnlyPlayer(true)
spec:check()
local player_remove = {}
for i, v in pairs(spec:getCreatureDetect()) do
for _, v_old in pairs(old_players) do
if v_old.creature == nil or v_old.creature:isMonster() then
break
end
if v:getName() == v_old.creature:getName() then
table.insert(player_remove, v_old.creature)
break
end
end
end
spec:removePlayers(player_remove)
end, config.timeToDefeat * 60 * 1000)
end
end

forgottenKnowledgeThorn:position(Position(32657, 32876, 14))
forgottenKnowledgeThorn:register()
Original file line number Diff line number Diff line change
@@ -1,27 +1,99 @@
local config = {
boss = {
name = "The Time Guardian",
position = Position(32977, 31662, 14),
},
requiredLevel = 250,
bossName = "The Time Guardian",
timeToFightAgain = 20, -- In hour
timeToDefeat = 15, -- In minutes
playerPositions = {
{ pos = Position(33010, 31660, 14), teleport = Position(32977, 31667, 14) },
{ pos = Position(33010, 31661, 14), teleport = Position(32977, 31667, 14) },
{ pos = Position(33010, 31662, 14), teleport = Position(32977, 31667, 14) },
{ pos = Position(33010, 31663, 14), teleport = Position(32977, 31667, 14) },
{ pos = Position(33010, 31664, 14), teleport = Position(32977, 31667, 14) },
{ pos = Position(33010, 31660, 14), teleport = Position(32977, 31667, 14), effect = CONST_ME_TELEPORT },
{ pos = Position(33010, 31661, 14), teleport = Position(32977, 31667, 14), effect = CONST_ME_TELEPORT },
{ pos = Position(33010, 31662, 14), teleport = Position(32977, 31667, 14), effect = CONST_ME_TELEPORT },
{ pos = Position(33010, 31663, 14), teleport = Position(32977, 31667, 14), effect = CONST_ME_TELEPORT },
{ pos = Position(33010, 31664, 14), teleport = Position(32977, 31667, 14), effect = CONST_ME_TELEPORT },
},
monsters = {
{ name = "The Freezing Time Guardian", pos = Position(32975, 31664, 13) },
{ name = "The Blazing Time Guardian", pos = Position(32980, 31664, 13) },
bosses = {
{ bossPosition = Position(32977, 31662, 14), bossName = "The Time Guardian" },
{ bossPosition = Position(32975, 31664, 13), bossName = "The Freezing Time Guardian" },
{ bossPosition = Position(32980, 31664, 13), bossName = "The Blazing Time Guardian" },
},
specPos = {
from = Position(32967, 31654, 14),
from = Position(32967, 31654, 13),
to = Position(32989, 31677, 14),
},
exit = Position(32870, 32724, 14),
}

local lever = BossLever(config)
lever:position(Position(33010, 31659, 14))
lever:register()
local forgottenKnowledgeGuardianLever = Action()
function forgottenKnowledgeGuardianLever.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if config.playerPositions[1].pos ~= player:getPosition() then
return false
end

local spec = Spectators()
spec:setOnlyPlayer(false)
spec:setRemoveDestination(config.exit)
spec:setCheckPosition(config.specPos)
spec:setMultiFloor(true)
spec:check()

if spec:getPlayers() > 0 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There's someone fighting with " .. config.bossName .. ".")
return true
end

local lever = Lever()
lever:setPositions(config.playerPositions)
lever:setCondition(function(creature)
if not creature or not creature:isPlayer() then
return true
end

if creature:getStorageValue(config.storage) > os.time() then
local info = lever:getInfoPositions()
for _, v in pairs(info) do
local newPlayer = v.creature
if newPlayer then
newPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You or a member in your team have to wait " .. config.timeToFightAgain .. " hours to face " .. config.bossName .. " again!")
if newPlayer:getStorageValue(config.storage) > os.time() then
newPlayer:getPosition():sendMagicEffect(CONST_ME_POFF)
end
end
end
return false
end
return true
end)

lever:checkPositions()
if lever:checkConditions() then
spec:removeMonsters()
for b = 1, #config.bosses do
local monster = Game.createMonster(config.bosses[b].bossName, config.bosses[b].bossPosition, true, true)
if not monster then
return true
end
end
lever:teleportPlayers()
lever:setCooldownAllPlayers(config.bossName, os.time() + config.timeToFightAgain * 3600)
addEvent(function()
local old_players = lever:getInfoPositions()
spec:clearCreaturesCache()
spec:setOnlyPlayer(true)
spec:check()
local player_remove = {}
for i, v in pairs(spec:getCreatureDetect()) do
for _, v_old in pairs(old_players) do
if v_old.creature == nil or v_old.creature:isMonster() then
break
end
if v:getName() == v_old.creature:getName() then
table.insert(player_remove, v_old.creature)
break
end
end
end
spec:removePlayers(player_remove)
end, config.timeToDefeat * 60 * 1000)
end
end

forgottenKnowledgeGuardianLever:position(Position(33010, 31659, 14))
forgottenKnowledgeGuardianLever:register()
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@ local function revertLloyd(prismId)
local lloydTile = Tile(Position(32799, 32826, 14))
if lloydTile then
local lloyd = lloydTile:getTopCreature()
lloyd:teleportTo(Position(32799, 32829, 14))
lloyd:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
if lloyd then
lloyd:teleportTo(Position(32799, 32829, 14))
lloyd:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
end

local tile = Tile(monsters[prismId].pos)
if tile then
local creature = tile:getTopCreature()
if creature then
creature:remove()
local creatures = tile:getCreatures()
for _, creature in ipairs(creatures) do
if creature:isMonster() then
creature:remove()
end
end
Game.createMonster(monsters[prismId].cosmicInvu, Position(monsters[prismId].pos), true, true)
end
end

local lloydPrepareDeath = CreatureEvent("LloydPrepareDeath")
function lloydPrepareDeath.onPrepareDeath(creature, lastHitKiller, mostDamageKiller)
local targetMonster = creature:getMonster()
if not creature or not targetMonster then
return true
end

local prismCount = 1
for m = 1, #monsters do
local cosmic = Tile(Position(monsters[m].pos)):getTopCreature()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ deathEvent:register()

local serverstartup = GlobalEvent("KillingInTheNameOfMonsterDeathStartup")
function serverstartup.onStartup()
logger.info("[KillingInTheNameOfMonsterDeathStartup] registering monsters")
local monsters = Set({}, { insensitive = true })
for _, task in pairs(tasks.GrizzlyAdams) do
monsters = monsters:union(task.creatures)
Expand Down
9 changes: 6 additions & 3 deletions data/scripts/reward_chest/boss_death.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local bossDeath = CreatureEvent("BossDeath")

function bossDeath.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
if not corpse or corpse == 0 then
return true
end
-- Deny summons and players
if not creature or creature:isPlayer() or creature:getMaster() then
return true
Expand All @@ -10,15 +13,15 @@ function bossDeath.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUn
local monsterType = creature:getType()
-- Make sure it is a boss
if monsterType and monsterType:isRewardBoss() then
if not corpse or not corpse.isContainer or not corpse:isContainer() then
if not corpse.isContainer or not corpse:isContainer() then
if corpse.getId then
logger.warn("[bossDeath.onDeath] Corpse (id: {}, name: {}) for reward boss {} is not a container.", corpse:getId(), corpse:getName(), creature:getName())
else
logger.warn("[bossDeath.onDeath] Error to get corpseId from boss: {}", creature:getName())
end
corpse = Game.createItem(ITEM_BAG, 1)
else
corpse:registerReward()
end
corpse:registerReward()
local bossId = creature:getId()
local rewardId = corpse:getAttribute(ITEM_ATTRIBUTE_DATE)

Expand Down

0 comments on commit 505230e

Please sign in to comment.