Skip to content

Commit

Permalink
refactor: optimize isSpecialItem function with range table
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Aug 28, 2024
1 parent a874b1c commit 42a853a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions data/scripts/eventcallbacks/player/on_look.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
local callback = EventCallback()
local specialItemRanges = {
{ rangeStart = ITEM_HEALTH_CASK_START, rangeEnd = ITEM_HEALTH_CASK_END },
{ rangeStart = ITEM_MANA_CASK_START, rangeEnd = ITEM_MANA_CASK_END },
{ rangeStart = ITEM_SPIRIT_CASK_START, rangeEnd = ITEM_SPIRIT_CASK_END },
{ rangeStart = ITEM_KEG_START, rangeEnd = ITEM_KEG_END },
}

local function isSpecialItem(itemId)
return (itemId >= ITEM_HEALTH_CASK_START and itemId <= ITEM_HEALTH_CASK_END) or (itemId >= ITEM_MANA_CASK_START and itemId <= ITEM_MANA_CASK_END) or (itemId >= ITEM_SPIRIT_CASK_START and itemId <= ITEM_SPIRIT_CASK_END) or (itemId >= ITEM_KEG_START and itemId <= ITEM_KEG_END)
for _, range in ipairs(specialItemRanges) do
if itemId >= range.rangeStart and itemId <= range.rangeEnd then
return true
end
end
return false
end

local function getPositionDescription(position)
Expand Down Expand Up @@ -98,6 +108,8 @@ local function appendAdminDetails(descriptionText, inspectedThing, inspectedPosi
return descriptionText
end

local callback = EventCallback()

function callback.playerOnLook(player, inspectedThing, inspectedPosition, lookDistance)
local descriptionText

Expand Down

0 comments on commit 42a853a

Please sign in to comment.