Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lua] remove duplicate code for Eldieme Necropolis candles #6900

Open
wants to merge 1 commit into
base: base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 69 additions & 43 deletions scripts/zones/The_Eldieme_Necropolis/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,54 @@
local ID = zones[xi.zone.THE_ELDIEME_NECROPOLIS]
-----------------------------------

-- Handle 7 Sins Skeleton NMs Spawns
local skullTrade = function(player, npc)
local candleCount =
{
ID.text.SKULL_FIVE_REMAIN,
ID.text.SKULL_FOUR_REMAIN,
ID.text.SKULL_THREE_REMAIN,
ID.text.SKULL_TWO_REMAIN,
ID.text.SKULL_ONE_REMAIN,
ID.text.SKULL_SPAWN,
}

local tradeCount = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullTradeCount') -- Track how many candles have been lit
local tradeWindow = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullTradeTimer') -- Track how much time before candles reset
local active = npc:getLocalVar('candleActive') -- Track if current candle has already been lit

for i = 1, 5 do
if tradeCount == 6 and os.time() < tradeWindow and os.time() > active then -- Final candle, spawn Skulls
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', 0)
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullRespawn', os.time() + 3600) -- 1 hour cooldown to respawn skulls
player:messageSpecial(ID.text.SKULL_SPAWN)
player:confirmTrade()

-- Spawn all 7 Skulls
for skull = 1, 7 do
SpawnMob(ID.mob.LICH_C_MAGNUS + skull) -- IDs based off Lich C Magnus
end

break
elseif tradeCount == i and os.time() < tradeWindow and os.time() > active then -- Candle trades 2 through 6
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', i + 1)
npc:setLocalVar('candleActive', os.time() + 10)
player:messageSpecial(ID.text.THE_BRAZIER_IS_LIT)
player:messageSpecial(candleCount[i])
player:confirmTrade()
break
elseif os.time() > tradeWindow and os.time() > active then -- First candle trade to start timer
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', 1)
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeTimer', os.time() + 40)
npc:setLocalVar('candleActive', os.time() + 10)
player:messageSpecial(ID.text.THE_BRAZIER_IS_LIT)
player:messageSpecial(ID.text.SKULL_SIX_REMAIN)
player:confirmTrade()
break
end
end
end

local eldiemeGlobal =
{
-- Click on any of the intersection gates
Expand Down Expand Up @@ -38,53 +86,31 @@ local eldiemeGlobal =
end
end,

-- Handle 7 Sins Skeleton NMs Spawns
skullTrade = function(player, npc)
local candleCount =
{
ID.text.SKULL_FIVE_REMAIN,
ID.text.SKULL_FOUR_REMAIN,
ID.text.SKULL_THREE_REMAIN,
ID.text.SKULL_TWO_REMAIN,
ID.text.SKULL_ONE_REMAIN,
ID.text.SKULL_SPAWN,
}

local tradeCount = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullTradeCount') -- Track how many candles have been lit
local tradeWindow = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullTradeTimer') -- Track how much time before candles reset
local active = npc:getLocalVar('candleActive') -- Track if current candle has already been lit
handleCandleTrade = function(player, npc, trade)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls

for i = 1, 5 do
if tradeCount == 6 and os.time() < tradeWindow and os.time() > active then -- Final candle, spawn Skulls
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', 0)
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullRespawn', os.time() + 3600) -- 1 hour cooldown to respawn skulls
player:messageSpecial(ID.text.SKULL_SPAWN)
player:confirmTrade()
if
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE) and
os.time() > timer
then
skullTrade(player, npc)
elseif os.time() < timer then
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
end,

-- Spawn all 7 Skulls
for skull = 1, 7 do
SpawnMob(ID.mob.LICH_C_MAGNUS + skull) -- IDs based off Lich C Magnus
end
handleCandleTrigger = function(player, npc)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls
local active = npc:getLocalVar('candlesActive')

break
elseif tradeCount == i and os.time() < tradeWindow and os.time() > active then -- Candle trades 2 through 6
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', i + 1)
npc:setLocalVar('candleActive', os.time() + 10)
player:messageSpecial(ID.text.THE_BRAZIER_IS_LIT)
player:messageSpecial(candleCount[i])
player:confirmTrade()
break
elseif os.time() > tradeWindow and os.time() > active then -- First candle trade to start timer
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeCount', 1)
GetNPCByID(ID.npc.CANDLE_OFFSET):setLocalVar('SkullTradeTimer', os.time() + 40)
npc:setLocalVar('candleActive', os.time() + 10)
player:messageSpecial(ID.text.THE_BRAZIER_IS_LIT)
player:messageSpecial(ID.text.SKULL_SIX_REMAIN)
player:confirmTrade()
break
end
if os.time() < active then
player:messageSpecial(ID.text.BRAZIER_ACTIVE)
elseif os.time() > timer and os.time() > active then
player:messageSpecial(ID.text.BRAZIER_OUT, 0, xi.item.FLINT_STONE)
else
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
end,
end
}

return eldiemeGlobal
27 changes: 4 additions & 23 deletions scripts/zones/The_Eldieme_Necropolis/npcs/_5fu.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
-----------------------------------
-- Area: The Eldieme Necropolis
-- NPC: Tallow Candle
-- NPC: Tallow Candle
-- !pos 15.19 -18.30 339.80
-----------------------------------
local ID = zones[xi.zone.THE_ELDIEME_NECROPOLIS]
local func = require('scripts/zones/The_Eldieme_Necropolis/globals')
local necropolisGlobal = require('scripts/zones/The_Eldieme_Necropolis/globals')
-----------------------------------
---@type TNpcEntity
local entity = {}

entity.onTrade = function(player, npc, trade)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls

if
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE) and
os.time() > timer
then
func.skullTrade(player, npc)
elseif os.time() < timer then
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrade(player, npc, trade)
end

entity.onTrigger = function(player, npc)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls
local active = npc:getLocalVar('candlesActive')

if os.time() < active then
player:messageSpecial(ID.text.BRAZIER_ACTIVE)
elseif os.time() > timer and os.time() > active then
player:messageSpecial(ID.text.BRAZIER_OUT, 0, xi.item.FLINT_STONE)
else
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrigger(player, npc)
end

return entity
27 changes: 4 additions & 23 deletions scripts/zones/The_Eldieme_Necropolis/npcs/_5fv.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
-----------------------------------
-- Area: The Eldieme Necropolis
-- NPC: Tallow Candle
-- NPC: Tallow Candle
-- !pos 139.96 -18.29 306.27
-----------------------------------
local ID = zones[xi.zone.THE_ELDIEME_NECROPOLIS]
local func = require('scripts/zones/The_Eldieme_Necropolis/globals')
local necropolisGlobal = require('scripts/zones/The_Eldieme_Necropolis/globals')
-----------------------------------
---@type TNpcEntity
local entity = {}

entity.onTrade = function(player, npc, trade)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls

if
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE) and
os.time() > timer
then
func.skullTrade(player, npc)
elseif os.time() < timer then
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrade(player, npc, trade)
end

entity.onTrigger = function(player, npc)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls
local active = npc:getLocalVar('candlesActive')

if os.time() < active then
player:messageSpecial(ID.text.BRAZIER_ACTIVE)
elseif os.time() > timer and os.time() > active then
player:messageSpecial(ID.text.BRAZIER_OUT, 0, xi.item.FLINT_STONE)
else
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrigger(player, npc)
end

return entity
27 changes: 4 additions & 23 deletions scripts/zones/The_Eldieme_Necropolis/npcs/_5fw.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
-----------------------------------
-- Area: The Eldieme Necropolis
-- NPC: Tallow Candle
-- NPC: Tallow Candle
-- !pos 139.96 -18.29 306.27
-----------------------------------
local ID = zones[xi.zone.THE_ELDIEME_NECROPOLIS]
local func = require('scripts/zones/The_Eldieme_Necropolis/globals')
local necropolisGlobal = require('scripts/zones/The_Eldieme_Necropolis/globals')
-----------------------------------
---@type TNpcEntity
local entity = {}

entity.onTrade = function(player, npc, trade)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls

if
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE) and
os.time() > timer
then
func.skullTrade(player, npc)
elseif os.time() < timer then
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrade(player, npc, trade)
end

entity.onTrigger = function(player, npc)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls
local active = npc:getLocalVar('candlesActive')

if os.time() < active then
player:messageSpecial(ID.text.BRAZIER_ACTIVE)
elseif os.time() > timer and os.time() > active then
player:messageSpecial(ID.text.BRAZIER_OUT, 0, xi.item.FLINT_STONE)
else
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrigger(player, npc)
end

return entity
27 changes: 4 additions & 23 deletions scripts/zones/The_Eldieme_Necropolis/npcs/_5fx.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
-----------------------------------
-- Area: The Eldieme Necropolis
-- NPC: Tallow Candle
-- NPC: Tallow Candle
-- !pos 100.01 5.69 -106.07
-----------------------------------
local ID = zones[xi.zone.THE_ELDIEME_NECROPOLIS]
local func = require('scripts/zones/The_Eldieme_Necropolis/globals')
local necropolisGlobal = require('scripts/zones/The_Eldieme_Necropolis/globals')
-----------------------------------
---@type TNpcEntity
local entity = {}

entity.onTrade = function(player, npc, trade)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls

if
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE) and
os.time() > timer
then
func.skullTrade(player, npc)
elseif os.time() < timer then
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrade(player, npc, trade)
end

entity.onTrigger = function(player, npc)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls
local active = npc:getLocalVar('candlesActive')

if os.time() < active then
player:messageSpecial(ID.text.BRAZIER_ACTIVE)
elseif os.time() > timer and os.time() > active then
player:messageSpecial(ID.text.BRAZIER_OUT, 0, xi.item.FLINT_STONE)
else
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrigger(player, npc)
end

return entity
27 changes: 4 additions & 23 deletions scripts/zones/The_Eldieme_Necropolis/npcs/_5fy.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
-----------------------------------
-- Area: The Eldieme Necropolis
-- NPC: Tallow Candle
-- NPC: Tallow Candle
-- !pos 384.07 -34.30 -374.14
-----------------------------------
local ID = zones[xi.zone.THE_ELDIEME_NECROPOLIS]
local func = require('scripts/zones/The_Eldieme_Necropolis/globals')
local necropolisGlobal = require('scripts/zones/The_Eldieme_Necropolis/globals')
-----------------------------------
---@type TNpcEntity
local entity = {}

entity.onTrade = function(player, npc, trade)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls

if
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE) and
os.time() > timer
then
func.skullTrade(player, npc)
elseif os.time() < timer then
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrade(player, npc, trade)
end

entity.onTrigger = function(player, npc)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls
local active = npc:getLocalVar('candlesActive')

if os.time() < active then
player:messageSpecial(ID.text.BRAZIER_ACTIVE)
elseif os.time() > timer and os.time() > active then
player:messageSpecial(ID.text.BRAZIER_OUT, 0, xi.item.FLINT_STONE)
else
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrigger(player, npc)
end

return entity
27 changes: 4 additions & 23 deletions scripts/zones/The_Eldieme_Necropolis/npcs/_5fz.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
-----------------------------------
-- Area: The Eldieme Necropolis
-- NPC: Tallow Candle
-- NPC: Tallow Candle
-- !pos -655.27 -2.30 214.58
-----------------------------------
local ID = zones[xi.zone.THE_ELDIEME_NECROPOLIS]
local func = require('scripts/zones/The_Eldieme_Necropolis/globals')
local necropolisGlobal = require('scripts/zones/The_Eldieme_Necropolis/globals')
-----------------------------------
---@type TNpcEntity
local entity = {}

entity.onTrade = function(player, npc, trade)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls

if
npcUtil.tradeHasExactly(trade, xi.item.FLINT_STONE) and
os.time() > timer
then
func.skullTrade(player, npc)
elseif os.time() < timer then
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrade(player, npc, trade)
end

entity.onTrigger = function(player, npc)
local timer = GetNPCByID(ID.npc.CANDLE_OFFSET):getLocalVar('SkullRespawn') -- 1 hour cooldown to respawn skulls
local active = npc:getLocalVar('candlesActive')

if os.time() < active then
player:messageSpecial(ID.text.BRAZIER_ACTIVE)
elseif os.time() > timer and os.time() > active then
player:messageSpecial(ID.text.BRAZIER_OUT, 0, xi.item.FLINT_STONE)
else
player:messageSpecial(ID.text.BRAZIER_COOLDOWN)
end
necropolisGlobal.handleCandleTrigger(player, npc)
end

return entity
Loading