-- to-do -- change to ItemsDatabase.setTier(UIitem) to UIitem:setTier() ItemsDatabase = {} ItemsDatabase.rarityColors = { ["yellow"] = TextColors.yellow, ["purple"] = TextColors.purple, ["blue"] = TextColors.blue, ["green"] = TextColors.green, ["grey"] = TextColors.grey, } local function getColorForValue(value) if value >= 1000000 then return "yellow" elseif value >= 100000 then return "purple" elseif value >= 10000 then return "blue" elseif value >= 1000 then return "green" elseif value >= 50 then return "grey" else return "white" end end local function clipfunction(value) if value >= 1000000 then return "128 0 32 32" elseif value >= 100000 then return "96 0 32 32" elseif value >= 10000 then return "64 0 32 32" elseif value >= 1000 then return "32 0 32 32" elseif value >= 50 then return "0 0 32 32" end return "" end function ItemsDatabase.getClipAndImagePath(item) if not item then return nil, nil, nil end local frameOption = modules.client_options.getOption('framesRarity') if frameOption == "none" then return nil, nil, nil end local imagePath = '/images/ui/item' local clip = nil if type(item) == "number" then item = g_things.getThingType(item, ThingCategoryItem) end if not item then return nil, nil, nil end if item then local price = type(item) == "number" and item or (item and item:getMeanPrice()) or 0 local itemRarity = getColorForValue(price) if itemRarity then clip = clipfunction(price) if clip ~= "" then if frameOption == "frames" then imagePath = "/images/ui/rarity_frames" elseif frameOption == "corners" then imagePath = "/images/ui/containerslot-coloredges" end else clip = nil end end end local clipObject = nil if clip then local x, y, w, h = clip:match("(%d+) (%d+) (%d+) (%d+)") clipObject = { x = tonumber(x), y = tonumber(y), width = tonumber(w), height = tonumber(h) } end return clip, imagePath, clipObject end -- OT-MMO: la calidad del objeto llega como 'tier' (server/scripts/equipo/equipo.lua; los efectos de la Forja estan -- apagados en config.lua): 1 poco comun, 2 rara, 3 epica, 4 legendaria. Marco de color en la casilla; sin calidad, nada. ItemsDatabase.calidadClip = { [1] = 32, [2] = 64, [3] = 96, [4] = 128 } -- rarity_frames.png ItemsDatabase.calidadColor = { ['1'] = '#4cc94c', ['2'] = '#3d8fe0', ['3'] = '#b05ce6', ['4'] = '#e6b23a' } function ItemsDatabase.setCalidad(widget, item) if not widget then return end local tier = (type(item) == "userdata" or type(item) == "table") and item.getTier and item:getTier() or 0 local x = ItemsDatabase.calidadClip[tier] local opcion = modules.client_options.getOption('framesRarity') if x and opcion ~= 'none' then if not widget.fondoOriginal then widget.fondoOriginal = { widget:getImageSource() or '', widget:getImageClip() } end widget:setImageSource(opcion == 'corners' and '/images/ui/containerslot-coloredges' or '/images/ui/rarity_frames') widget:setImageClip({ x = x, y = 0, width = 32, height = 32 }) elseif widget.fondoOriginal then widget:setImageSource(widget.fondoOriginal[1]) widget:setImageClip(widget.fondoOriginal[2]) widget.fondoOriginal = nil end end -- '{q3|arco elfico (epica)}' (lo manda el servidor) -> '{arco elfico (epica), #b05ce6}' para setColoredText function ItemsDatabase.colorCalidad(text) return (text:gsub("{q(%d)|(.-)}", function(n, nombre) return "{" .. nombre .. ", " .. (ItemsDatabase.calidadColor[n] or '#ffffff') .. "}" end)) end function ItemsDatabase.setRarityItem(widget, item, style) if type(item) ~= "number" and item and item.getTier then -- objetos del juego: marco por calidad return ItemsDatabase.setCalidad(widget, item) end if not g_game.getFeature(GameColorizedLootValue) or not widget then return end local clip, imagePath = ItemsDatabase.getClipAndImagePath(item) if not imagePath then -- no frame applies (empty slot or frames disabled): clear a frame left by a previous item, -- but only if this widget is currently showing one, to avoid clobbering custom backgrounds local currentSource = widget:getImageSource() if currentSource == "/images/ui/rarity_frames" or currentSource == "/images/ui/containerslot-coloredges" then widget:setImageClip(nil) widget:setImageSource('/images/ui/item') end return end widget:setImageClip(clip) widget:setImageSource(imagePath) if style then widget:setStyle(style) end end function ItemsDatabase.getColorForRarity(rarity) return ItemsDatabase.rarityColors[rarity] or TextColors.white end function ItemsDatabase.setColorLootMessage(text) text = ItemsDatabase.colorCalidad(text) local function coloringLootName(match) local id, itemName = match:match("(%d+)|(.+)") if not id or not itemName then -- If pattern doesn't match itemId|itemName format, return the original match with braces return "{" .. match .. "}" end local itemId = tonumber(id) if not itemId then return itemName or match end local thingType = g_things.getThingType(itemId, ThingCategoryItem) if not thingType then return itemName end local itemInfo = thingType:getMeanPrice() if itemInfo then local color = ItemsDatabase.getColorForRarity(getColorForValue(itemInfo)) return "{" .. itemName .. ", " .. color .. "}" else return itemName end end return text:gsub("{(.-)}", coloringLootName) end function ItemsDatabase.getTierClip(tier) local xOffset = (math.min(math.max(tier, 1), 10) - 1) * 9 return { x = xOffset, y = 0, width = 10, height = 9 } end -- OT-MMO: el tier es la calidad y se ve como marco (setCalidad): el rombo de la Forja no se muestra function ItemsDatabase.setTier(widget) if widget and widget.tier then widget.tier:setVisible(false) end end