Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------------
- --[[ doorUtils.lua v1.0 by KBM-Quine ]]--
- --[[ with some code help from: ]]--
- --[[ Enjl and MrDoubleA ]]--
- -------------------------------------------
- local effectconfig = require("base/game/effectconfig")
- local doorUtils = {}
- doorUtils.defaults = {
- usePluralMacguffins = true,
- macguffin = "star",
- macguffinPlural = "stars",
- macguffinMessage = "You need [number] [macguffin] to enter.",
- macguffinMessagePlural = "You need [number] [macguffinplural] to enter.",
- macguffinIcon = nil,
- centerMacguffinOnBackground = false,
- macguffinAlignX = 0.5,
- macguffinAlignY = 1,
- macguffinOffsetX = 0,
- macguffinOffsetY = 0,
- lockIcon = nil,
- centerLockOnBackground = false,
- lockAlignX = 0,
- lockAlignY = 0,
- lockOffsetX = 0,
- lockOffsetY = 0,
- effectOffsetX = 0,
- effectOffsetY = 0,
- autoResizeWarp = false,
- autoRegisterBaseDoors = true,
- }
- if doorUtils.defaults.autoRegisterBaseDoors then
- BGO.config[87].door = BGO.config[87].door or true
- BGO.config[88].door = BGO.config[88].door or true
- BGO.config[107].door = BGO.config[107].door or true
- BGO.config[141].door = BGO.config[141].door or true
- end
- function effectconfig.onTick.TICK_DOORUTILS(v)
- v.timer = 2
- v.frSpeed = v.frSpeed or v.framespeed
- v.framespeed = 0
- v.doorTimer = v.doorTimer or v.lifetime
- v.doorTimer = v.doorTimer - 1
- v.animDir = v.animDir or 1
- if v.animDir == 1 then
- if v.doorTimer%v.frSpeed == 0 and v.doorTimer > math.floor(v.lifetime*0.667) and v.animationFrame ~= v.frames - 1 then
- v.animationFrame = v.animationFrame + 1
- elseif v.animationFrame == v.frames - 1 then
- v.animationFrame = v.frames - 1
- end
- if v.doorTimer < math.floor(v.lifetime*0.667) then
- v.animDir = 0
- end
- end
- if v.animDir == 0 then
- v.animationFrame = v.frames - 1
- if v.doorTimer < math.ceil(v.lifetime*0.333) then
- v.animationFrame = v.frames - 2
- v.animDir = -1
- end
- end
- if v.animDir == -1 then
- if v.doorTimer%v.frSpeed == 0 then
- v.animationFrame = v.animationFrame - 1
- end
- end
- if v.animationFrame == -1 then
- v.timer = 0
- end
- end
- function doorUtils.onInitAPI()
- registerEvent (doorUtils, "onStart", "onStart", true)
- registerEvent (doorUtils, "onDraw", "onDraw", true)
- registerEvent (doorUtils, "onMessageBox", "onMessageBox", true)
- end
- function doorUtils.onStart()
- if not isOverworld then
- for _,v in ipairs(BGO.get()) do
- for _,wEnt in ipairs(Warp.getIntersectingEntrance(v.x, v.y, v.x + v.width + 8, v.y + v.height + 8)) do
- for _,wExi in ipairs(Warp.getIntersectingExit(v.x, v.y, v.x + v.width + 8, v.y + v.height + 8)) do
- if wEnt ~= nil and BGO.config[v.id].door and v.width > 32 then
- if BGO.config[v.id].autoResizeWarp or doorUtils.defaults.autoResizeWarp then
- wEnt.entranceX = v.x + 16
- wEnt.entranceWidth = v.width - 32
- end
- end
- if wExi ~= nil and BGO.config[v.id].door and v.width > 32 then
- if BGO.config[v.id].autoResizeWarp or doorUtils.defaults.autoResizeWarp then
- wExi.exitX = v.x + 16
- wExi.exitWidth = v.width - 32
- end
- end
- end
- end
- end
- for _,v in ipairs(BGO.get({98, 160})) do
- if v.id == 160 then
- for _,b in ipairs(BGO.getIntersecting(v.x, v.y, v.x + v.width + 8, v.y + v.height + 8)) do
- for _,w in ipairs(Warp.getIntersectingEntrance(v.x, v.y, v.x + v.width + 8, v.y + v.height + 8)) do
- if b ~= nil and BGO.config[b.id].door then
- v.data.macguffinIconIndex = v.data.macguffinIconIndex or w.idx
- if b.id ~= 160 then
- if BGO.config[b.id].macguffinIcon ~= nil or doorUtils.defaults.macguffinIcon ~= nil then
- v.id = BGO.config[b.id].macguffinIcon or doorUtils.defaults.macguffinIcon
- v.data.IconWidth = BGO.config[BGO.config[b.id].macguffinIcon].width or BGO.config[doorUtils.defaults.macguffinIcon].width
- v.data.IconHeight = BGO.config[BGO.config[b.id].macguffinIcon].height or BGO.config[doorUtils.defaults.macguffinIcon].height
- end
- if BGO.config[b.id].centerMacguffinOnBackground or doorUtils.defaults.centerMacguffinOnBackground then
- v.x = (b.x + b.width*0.5) - (v.data.IconWidth or v.width)*(BGO.config[b.id].macguffinAlignX or doorUtils.defaults.macguffinAlignX) + (BGO.config[b.id].macguffinOffsetX or doorUtils.defaults.macguffinOffsetX)
- v.y = (b.y + b.height*0.5) - (v.data.IconHeight or v.height)*(BGO.config[b.id].macguffinAlignY or doorUtils.defaults.macguffinAlignY) + (BGO.config[b.id].macguffinOffsetY or doorUtils.defaults.macguffinOffsetY)
- else
- v.x = (w.entranceX + w.entranceWidth*0.5) - (v.data.IconWidth or v.width)*(BGO.config[b.id].macguffinAlignX or doorUtils.defaults.macguffinAlignX) + (BGO.config[b.id].macguffinOffsetX or doorUtils.defaults.macguffinOffsetX)
- v.y = w.entranceY - (v.data.IconHeight or v.height)*(BGO.config[b.id].macguffinAlignY or doorUtils.defaults.macguffinAlignY) + (BGO.config[b.id].macguffinOffsetY or doorUtils.defaults.macguffinOffsetY)
- end
- end
- end
- end
- end
- end
- if v.id == 98 then
- for _,b in ipairs(BGO.getIntersecting(v.x, v.y, v.x + v.width + 8, v.y + v.height + 8)) do
- for _,w in ipairs(Warp.getIntersectingEntrance(v.x, v.y, v.x + v.width + 8, v.y + v.height + 8)) do
- if b ~= nil and BGO.config[b.id].door then
- v.data.lockIconIndex = v.data.lockIconIndex or w.idx
- if b.id ~= 98 then
- if BGO.config[b.id].lockIcon ~= nil or doorUtils.defaults.lockIcon ~= nil then
- v.id = BGO.config[b.id].lockIcon or doorUtils.defaults.lockIcon
- v.data.IconWidth = BGO.config[BGO.config[b.id].lockIcon].width or BGO.config[doorUtils.defaults.lockIcon].width
- v.data.IconHeight = BGO.config[BGO.config[b.id].lockIcon].height or BGO.config[doorUtils.defaults.lockIcon].height
- end
- if BGO.config[b.id].centerlockonbackground or doorUtils.defaults.centerLockOnBackground then
- v.x = (b.x + b.width*0.5) - (v.data.IconWidth or v.width)*(BGO.config[b.id].lockAlignX or doorUtils.defaults.lockAlignX) + (BGO.config[b.id].lockOffsetX or doorUtils.defaults.lockOffsetX)
- v.y = (b.y + b.height*0.5) - (v.data.IconHeight or v.height)*(BGO.config[b.id].lockAlignY or doorUtils.defaults.lockAlignY) + (BGO.config[b.id].lockOffsetY or doorUtils.defaults.lockOffsetY)
- else
- v.x = w.entranceX + w.entranceWidth*(BGO.config[b.id].lockAlignX or doorUtils.defaults.lockAlignX) + (BGO.config[b.id].lockOffsetX or doorUtils.defaults.lockOffsetX)
- v.y = w.entranceY + w.entranceHeight*(BGO.config[b.id].lockAlignY or doorUtils.defaults.lockAlignY) + (BGO.config[b.id].lockOffsetY or doorUtils.defaults.lockOffsetX)
- end
- end
- end
- end
- end
- end
- end
- end
- end
- function doorUtils.resolveStrings(message, number, BGOID)
- local singular = BGO.config[BGOID].macguffin or doorUtils.defaults.macguffin
- local plural = BGO.config[BGOID].macguffinPlural or doorUtils.defaults.macguffinPlural
- message = string.gsub(message, "%[macguffin%]", singular)
- message = string.gsub(message, "%[macguffinplural%]", plural)
- message = string.gsub(message, "%[number%]", number)
- return message
- end
- function doorUtils.onDraw()
- if not isOverworld then
- for _,v in ipairs(BGO.get()) do
- if v.data.macguffinIconIndex ~= nil then
- if Warp(v.data.macguffinIconIndex).starsRequired <= mem(0x00B251E0, FIELD_WORD) and not v.isHidden then
- v.isHidden = true
- v.layer = ""
- end
- if Warp(v.data.macguffinIconIndex).starsRequired > mem(0x00B251E0, FIELD_WORD) and v.isHidden then -- allow relocking
- v.isHidden = false
- v.layer = Warp(v.data.macguffinIconIndex).layer
- end
- end
- if v.data.lockIconIndex ~= nil then
- if not Warp(v.data.lockIconIndex).locked and not v.isHidden then
- v.isHidden = true
- v.layer = ""
- end
- if Warp(v.data.lockIconIndex).locked and v.isHidden then -- allow relocking
- v.isHidden = false
- v.layer = Warp(v.data.lockIconIndex).layer
- end
- end
- end
- for _, p in ipairs(Player.get()) do
- if p.ForcedAnimationState == 7 and p.ForcedAnimationTimer == 0 then
- local warpID = 0
- for _,w in ipairs(Warp.getIntersectingEntrance(p.x, p.y, p.x + p.width, p.y + p.height)) do
- for _,b in ipairs(BGO.getIntersecting(w.entranceX, w.entranceY, w.entranceX + w.entranceWidth, w.entranceY + w.entranceHeight)) do
- if b.data.macguffinIconIndex == nil and b.data.lockIconIndex == nil and BGO.config[b.id].door then
- warpID = w.idx
- local effect = BGO.config[b.id].effect
- local spawned = false
- if effect ~= nil then
- Effect.spawn(effect, b.x + (BGO.config[b.id].effectOffsetX or doorUtils.defaults.effectOffsetX), b.y + (BGO.config[b.id].effectOffsetY or doorUtils.defaults.effectOffsetY))
- spawned = true
- end
- for _,e in ipairs(Effect.getIntersecting(w.entranceX, w.entranceY, w.entranceX + w.entranceWidth, w.entranceY + w.entranceHeight)) do
- if e.id == 54 or e.id == 55 or e.id == 59 or e.id == 103 then
- if spawned then
- e.timer = 0
- end
- end
- if effect == nil then
- if e.id == 54 or e.id == 55 or e.id == 59 or e.id == 103 then
- if spawned then
- e.timer = 0
- end
- e.x = b.x + (BGO.config[b.id].effectOffsetX or doorUtils.defaults.effectOffsetX)
- e.y = b.y + (BGO.config[b.id].effectOffsetY or doorUtils.defaults.effectOffsetY)
- e.width = Graphics.sprites.effect[e.id].img.width -- make the ghost house door effect resizable
- end
- end
- end
- end
- end
- for _,b in ipairs(BGO.getIntersecting(w.exitX, w.exitY, w.exitX + w.exitWidth, w.exitY + w.exitHeight)) do -- spawn an effect at the exit, to mimic vanilla behaviour.
- if b.data.macguffinIconIndex == nil and b.data.lockIconIndex == nil and BGO.config[b.id].door then
- local effect = BGO.config[b.id].effect
- local spawned = false
- if effect ~= nil then
- Effect.spawn(effect, b.x + (BGO.config[b.id].effectOffsetX or doorUtils.defaults.effectOffsetX), b.y + (BGO.config[b.id].effectOffsetY or doorUtils.defaults.effectOffsetY))
- spawned = true
- end
- for _,e in ipairs(Effect.getIntersecting(w.exitX, w.exitY, w.exitX + w.exitWidth, w.exitY + w.exitHeight)) do
- if e.id == 54 or e.id == 55 or e.id == 59 or e.id == 103 then
- if spawned then
- e.timer = 0
- end
- end
- if effect == nil then
- if e.id == 54 or e.id == 55 or e.id == 59 or e.id == 103 then
- if spawned then
- e.timer = 0
- end
- e.x = b.x + (BGO.config[b.id].effectOffsetX or doorUtils.defaults.effectOffsetX)
- e.y = b.y + (BGO.config[b.id].effectOffsetY or doorUtils.defaults.effectOffsetY)
- e.width = Graphics.sprites.effect[e.id].img.width -- make the ghost house door effect resizable
- end
- end
- end
- end
- end
- end
- end
- end
- end
- end
- function doorUtils.onMessageBox(event, message)
- if not isOverworld then
- if string.find(message, "You need %d+ stars? to enter%.") then
- local BGOID
- local newMessage
- local number = string.match(message, "%d+")
- local usePlural
- local plural
- local singular
- for _, p in ipairs(Player.get()) do
- for _,w in ipairs(Warp.getIntersectingEntrance(p.x, p.y, p.x + p.width, p.y + p.height)) do
- for _,b in ipairs(BGO.getIntersecting(w.entranceX, w.entranceY, w.entranceX + w.entranceWidth, w.entranceY + w.entranceHeight)) do
- if w.starsRequired > 0 then
- if b.data.macguffinIconIndex == nil and BGO.config[b.id].door then
- BGOID = b.id
- end
- end
- end
- end
- end
- if BGO.config[BGOID].usePluralMacguffins ~= nil then
- usePlural = BGO.config[BGOID].usePluralMacguffins
- else
- usePlural = doorUtils.defaults.usePluralMacguffins
- end
- if tonumber(number) > 1 and usePlural then
- newMessage = doorUtils.resolveStrings(BGO.config[BGOID].macguffinMessagePlural or doorUtils.defaults.macguffinMessagePlural, number, BGOID)
- else
- newMessage = doorUtils.resolveStrings(BGO.config[BGOID].macguffinMessage or doorUtils.defaults.macguffinMessage, number, BGOID)
- end
- if not string.find(newMessage, "You need %d+ stars? to enter%.") then
- event.cancelled = true
- else
- newMessage = nil
- end
- if newMessage ~= nil then
- Text.showMessageBox(newMessage)
- end
- end
- end
- end
- return doorUtils
- --Someone told me someone's there. I lost myself, you're always moving.
Add Comment
Please, Sign In to add comment