From 0364ba62ed705ba3c67e99ed5cea068978969997 Mon Sep 17 00:00:00 2001 From: ErikasKontenis Date: Mon, 30 Dec 2019 16:41:03 +0200 Subject: [PATCH] fix parchment room quest demons spawning: https://github.com/TwistedScorpio/Nostalrius/issues/18 --- data/lib/core/game.lua | 11 +++++++ data/movements/scripts/nostalrius/234.lua | 39 +++++++++++++++++------ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/data/lib/core/game.lua b/data/lib/core/game.lua index 12c7c92..fc900f7 100644 --- a/data/lib/core/game.lua +++ b/data/lib/core/game.lua @@ -55,6 +55,17 @@ function Game.isPlayerThere(position) return false end +function Game.isMonsterThere(position, monsterName) + local tile = Tile(position) + local creatures = tile:getCreatures() + for _, creature in ipairs(creatures) do + if creature:isMonster() and creature:getName():lower() == monsterName:lower() then + return creature + end + end + return nil +end + function Game.broadcastMessage(message, messageType) if messageType == nil then messageType = MESSAGE_STATUS_WARNING diff --git a/data/movements/scripts/nostalrius/234.lua b/data/movements/scripts/nostalrius/234.lua index e536b42..78e0196 100644 --- a/data/movements/scripts/nostalrius/234.lua +++ b/data/movements/scripts/nostalrius/234.lua @@ -1,10 +1,31 @@ function onRemoveItem(item, tileitem, position) - doRelocate({x = 33336, y = 31954, z = 15},{x = 33060, y = 31623, z = 15}) - doRelocate({x = 33340, y = 31954, z = 15},{x = 33066, y = 31623, z = 15}) - doRelocate({x = 33340, y = 31958, z = 15},{x = 33066, y = 31627, z = 15}) - doRelocate({x = 33336, y = 31958, z = 15},{x = 33060, y = 31627, z = 15}) - Game.sendMagicEffect({x = 33060, y = 31622, z = 15}, 14) - Game.sendMagicEffect({x = 33066, y = 31622, z = 15}, 14) - Game.sendMagicEffect({x = 33066, y = 31628, z = 15}, 14) - Game.sendMagicEffect({x = 33060, y = 31628, z = 15}, 14) -end + local demonsInRoomCount = 0; + local spectators = Game.getSpectators(Position(33063, 31624, 15), false, false, 20, 20, 20, 20) + for i = 1, #spectators do + local creature = spectators[i] + if creature:getName():lower() == "demon" then + demonsInRoomCount = demonsInRoomCount + 1 + end + end + + if (demonsInRoomCount <= 1) then + local demon1 = Game.isMonsterThere({x = 33336, y = 31954, z = 15}, "Demon") + local demon2 = Game.isMonsterThere({x = 33340, y = 31954, z = 15}, "Demon") + local demon3 = Game.isMonsterThere({x = 33340, y = 31958, z = 15}, "Demon") + local demon4 = Game.isMonsterThere({x = 33336, y = 31958, z = 15}, "Demon") + if demon1 ~= nil and demon2 ~= nil and demon3 ~= nil and demon4 ~= nil then + demon1:addHealth(-demon1:getMaxHealth()) + demon2:addHealth(-demon2:getMaxHealth()) + demon3:addHealth(-demon3:getMaxHealth()) + demon4:addHealth(-demon4:getMaxHealth()) + Game.createMonster("Demon", {x = 33060, y = 31623, z = 15}) + Game.createMonster("Demon", {x = 33066, y = 31623, z = 15}) + Game.createMonster("Demon", {x = 33066, y = 31627, z = 15}) + Game.createMonster("Demon", {x = 33060, y = 31627, z = 15}) + Game.sendMagicEffect({x = 33060, y = 31622, z = 15}, 14) + Game.sendMagicEffect({x = 33066, y = 31622, z = 15}, 14) + Game.sendMagicEffect({x = 33066, y = 31628, z = 15}, 14) + Game.sendMagicEffect({x = 33060, y = 31628, z = 15}, 14) + end + end +end \ No newline at end of file