-- chunkname: @/mods/game_tooltip/game_tooltip.lua m_TooltipList = {} m_TooltipFunction = {} m_TooltipFunction.cache = {} m_TooltipFunction.delay = 50 m_TooltipFunction.maximumWidth = 400 COMBAT_PHYSICALDAMAGE = 0 COMBAT_ENERGYDAMAGE = 1 COMBAT_EARTHDAMAGE = 2 COMBAT_FIREDAMAGE = 3 COMBAT_UNDEFINEDDAMAGE = 4 COMBAT_LIFEDRAIN = 5 COMBAT_MANADRAIN = 6 COMBAT_HEALING = 7 COMBAT_DROWNDAMAGE = 8 COMBAT_ICEDAMAGE = 9 COMBAT_HOLYDAMAGE = 10 COMBAT_DEATHDAMAGE = 11 STAT_MAXHITPOINTS = 0 STAT_MAXMANAPOINTS = 1 STAT_MAGICPOINTS = 4 SKILL_FIST = 0 SKILL_CLUB = 1 SKILL_SWORD = 2 SKILL_AXE = 3 SKILL_DISTANCE = 4 SKILL_SHIELD = 5 SKILL_FISHING = 6 ITEM_RARITY_COMMON = 1 ITEM_RARITY_COMMON_2 = 2 ITEM_RARITY_RARE_1 = 3 ITEM_RARITY_RARE_2 = 4 ITEM_RARITY_RARE_3 = 5 ITEM_RARITY_MYTHIC_1 = 6 ITEM_RARITY_MYTHIC_2 = 7 ITEM_RARITY_MYTHIC_3 = 8 ITEM_RARITY_LEGENDARY_1 = 9 ITEM_RARITY_LEGENDARY_2 = 10 ITEM_RARITY_LEGENDARY_3 = 11 m_TooltipFunction.GameServerSendTooltip = 159 m_TooltipFunction.GameServerParseTooltip = 158 m_TooltipFunction.TOOLTIP_ATTRIBUTE_NONE = 0 m_TooltipFunction.TOOLTIP_ATTRIBUTE_ATTACK = 1 m_TooltipFunction.TOOLTIP_ATTRIBUTE_DEFENSE = 2 m_TooltipFunction.TOOLTIP_ATTRIBUTE_NAME = 3 m_TooltipFunction.TOOLTIP_ATTRIBUTE_WEIGHT = 4 m_TooltipFunction.TOOLTIP_ATTRIBUTE_ARMOR = 5 m_TooltipFunction.TOOLTIP_ATTRIBUTE_HITCHANCE = 6 m_TooltipFunction.TOOLTIP_ATTRIBUTE_SHOOTRANGE = 7 m_TooltipFunction.TOOLTIP_ATTRIBUTE_DURATION = 8 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CHARGES = 9 m_TooltipFunction.TOOLTIP_ATTRIBUTE_FLUIDTYPE = 10 m_TooltipFunction.TOOLTIP_ATTRIBUTE_ATTACK_SPEED = 11 m_TooltipFunction.TOOLTIP_ATTRIBUTE_RESISTANCES = 12 m_TooltipFunction.TOOLTIP_ATTRIBUTE_STATS = 13 m_TooltipFunction.TOOLTIP_ATTRIBUTE_SKILL = 14 m_TooltipFunction.TOOLTIP_ATTRIBUTE_KEY = 15 m_TooltipFunction.TOOLTIP_ATTRIBUTE_TEXT = 16 m_TooltipFunction.TOOLTIP_ATTRIBUTE_WIELDINFO = 17 m_TooltipFunction.TOOLTIP_ATTRIBUTE_COUNT = 18 m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_LEVEL = 19 m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_MAGIC_LEVEL = 20 m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_NAME = 21 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CONTAINER_SIZE = 22 m_TooltipFunction.TOOLTIP_ATTRIBUTE_SPEED = 23 m_TooltipFunction.TOOLTIP_ATTRIBUTE_FIELD_ABSORB = 24 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRITICALHITCHANCE = 25 m_TooltipFunction.TOOLTIP_ATTRIBUTE_IMMUNE = 26 m_TooltipFunction.TOOLTIP_ATTRIBUTE_LIFELEECH = 27 m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANALEECH = 28 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRITICALHITDAMAGE = 29 m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEINCREASE = 30 m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEREDUCTION = 31 m_TooltipFunction.TOOLTIP_ATTRIBUTE_DODGE = 32 m_TooltipFunction.TOOLTIP_ATTRIBUTE_MOREWEAPONATTACK = 33 m_TooltipFunction.TOOLTIP_ATTRIBUTE_HEALINGRUNEINCREASE = 34 m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEPENETRATION = 35 m_TooltipFunction.TOOLTIP_ATTRIBUTE_RARITY = 36 m_TooltipFunction.TOOLTIP_ATTRIBUTE_SUPG = 37 m_TooltipFunction.TOOLTIP_ATTRIBUTE_NUPG = 38 m_TooltipFunction.TOOLTIP_ATTRIBUTE_PRICE = 39 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFT = 40 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTSET = 41 m_TooltipFunction.TOOLTIP_ATTRIBUTE_WAVES = 42 m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANARUNEINCREASE2 = 43 m_TooltipFunction.TOOLTIP_ATTRIBUTE_ARMORBLOCKPHYSICAL = 44 m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANACOSTREDUCTION = 45 m_TooltipFunction.TOOLTIP_ATTRIBUTE_LUCK = 46 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMAGIC = 47 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMELEE = 48 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTDISTANCE = 49 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTHEALTH = 50 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMANA = 51 m_TooltipFunction.TOOLTIP_ATTRIBUTE_CELUGG = 52 m_TooltipFunction.TOOLTIP_ATTRIBUTE_EXPERIENCE = 53 m_TooltipFunction.TOOLTIP_ATTRIBUTE_HEALTH_REGEN = 54 m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANA_REGEN = 55 m_TooltipFunction.TOOLTIP_ATTRIBUTE_VIRTUAL = 56 m_TooltipFunction.TOOLTIP_ATTRIBUTE_BOUNCE = 57 m_TooltipFunction.TOOLTIP_ATTRIBUTE_BOUNCECOUNT = 58 m_TooltipFunction.descriptionByAttributeId = { [m_TooltipFunction.TOOLTIP_ATTRIBUTE_ATTACK] = { icon = 1, name = "Attack: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_DEFENSE] = { icon = 3, name = "Defense: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_WEIGHT] = { icon = 8, name = "%s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_ARMOR] = { icon = 2, name = "Armor: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_HITCHANCE] = { symbol = true, name = "Hit Chance: %s", icon = 47 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_SHOOTRANGE] = { icon = 9, name = "Range: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_DURATION] = { icon = 38, name = "%s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CHARGES] = { icon = 10, name = "Charges: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_FLUIDTYPE] = { icon = 27, name = "%s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_ATTACK_SPEED] = { icon = 20, name = "Attack Speed: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_KEY] = { icon = 28, name = "Key: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_TEXT] = { icon = 17, name = "%s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_WIELDINFO] = { icon = 44, name = "%s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_HEALTH_REGEN] = { icon = 39, name = "Regeneration %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANA_REGEN] = { icon = 40, name = "Regeneration %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_LEVEL] = { icon = 59, name = "Rune Level: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_MAGIC_LEVEL] = { icon = 59, name = "Rune Magic Level: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_NAME] = { icon = 58, name = "Rune Spell Name: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CONTAINER_SIZE] = { icon = 15, name = "Vol: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_SPEED] = { symbol = true, name = "Speed: %s", icon = 51 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRITICALHITCHANCE] = { symbol = true, name = "Critical Hit Chance: %s%%", icon = 12 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRITICALHITDAMAGE] = { symbol = true, name = "Critical Hit Multiplier: %s%%", icon = 12 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANALEECH] = { symbol = true, name = "Mana Leech Chance: %s%%", icon = 45 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_LIFELEECH] = { symbol = true, name = "Mana Leech Multiplier: %s%%", icon = 45 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_EXPERIENCE] = { symbol = true, name = "%s%% Extra Experience", icon = 49 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMAGIC] = { icon = 17, name = "Craft Magic Level: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMELEE] = { icon = 19, name = "Craft Melee: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTDISTANCE] = { icon = 22, name = "Craft Distance: %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTHEALTH] = { icon = 39, name = "Craft Regeneration %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMANA] = { icon = 40, name = "Craft Regeneration %s" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEINCREASE] = { icon = 12, name = "Damage Increase: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEREDUCTION] = { icon = 5, name = "Damage Reduction: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_DODGE] = { icon = 6, name = "Dodge Chance: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_MOREWEAPONATTACK] = { symbol = true, name = "Extra Weapon Attack: %s", icon = 11 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_HEALINGRUNEINCREASE] = { icon = 40, name = "Healing Rune Increase: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANARUNEINCREASE2] = { icon = 39, name = "Mana Rune Increase: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEPENETRATION] = { icon = 14, name = "Damage Penetration: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMANA] = { icon = 40, name = "Craft Mana Regeneration: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANACOSTREDUCTION] = { icon = 38, name = "Mana Cost Reduction: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_LUCK] = { icon = 15, name = "Luck: %s%%" }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_BOUNCE] = { symbol = true, name = "Bounce: %s%%", icon = 20 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_BOUNCECOUNT] = { symbol = true, name = "bounce target: %s", icon = 11 }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_RARITY] = { [ITEM_RARITY_COMMON] = { color = "white", name = "", icon = 16 }, [ITEM_RARITY_COMMON_2] = { color = "white", name = "", icon = 16 }, [ITEM_RARITY_RARE_1] = { color = "#74C365", name = "Rare", icon = 16 }, [ITEM_RARITY_RARE_2] = { color = "#74C365", name = "Rare", icon = 16 }, [ITEM_RARITY_RARE_3] = { color = "#74C365", name = "Rare", icon = 16 }, [ITEM_RARITY_MYTHIC_1] = { color = "#8040BF", name = "Mythic", icon = 16 }, [ITEM_RARITY_MYTHIC_2] = { color = "#8040BF", name = "Mythic", icon = 16 }, [ITEM_RARITY_MYTHIC_3] = { color = "#8040BF", name = "Mythic", icon = 16 }, [ITEM_RARITY_LEGENDARY_1] = { color = "#dde02d", name = "Legendary", icon = 16 }, [ITEM_RARITY_LEGENDARY_2] = { color = "#dde02d", name = "Legendary", icon = 16 }, [ITEM_RARITY_LEGENDARY_3] = { color = "#dde02d", name = "Legendary", icon = 16 } }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_RESISTANCES] = { [COMBAT_PHYSICALDAMAGE] = { icon = 30, name = "Physical Absorb: %s%%" }, [COMBAT_ENERGYDAMAGE] = { icon = 31, name = "Energy Absorb: %s%%" }, [COMBAT_EARTHDAMAGE] = { icon = 34, name = "Earth Absorb: %s%%" }, [COMBAT_FIREDAMAGE] = { icon = 32, name = "Fire Absorb: %s%%" }, [COMBAT_LIFEDRAIN] = { icon = 37, name = "Lifedrain Absorb: %s%%" }, [COMBAT_MANADRAIN] = { icon = 40, name = "Manadrain Absorb: %s%%" }, [COMBAT_DROWNDAMAGE] = { icon = 40, name = "Manadrain Absorb: %s%%" }, [COMBAT_ICEDAMAGE] = { icon = 33, name = "Ice Absorb: %s%%" }, [COMBAT_HOLYDAMAGE] = { icon = 36, name = "Holy Absorb: %s%%" }, [COMBAT_DEATHDAMAGE] = { icon = 35, name = "Death Absorb: %s%%" } }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_STATS] = { [STAT_MAXHITPOINTS] = { icon = 39, name = "Maximum Health: %s%%" }, [STAT_MAXMANAPOINTS] = { icon = 40, name = "Maximum Mana: %s%%" }, [STAT_MAGICPOINTS] = { icon = 17, name = "Magic Level: %s" } }, [m_TooltipFunction.TOOLTIP_ATTRIBUTE_SKILL] = { [SKILL_FIST] = { icon = 60, name = "Fist Fighting: %s" }, [SKILL_CLUB] = { icon = 30, name = "Club Fighting: %s" }, [SKILL_SWORD] = { icon = 18, name = "Melee Fighting: %s" }, [SKILL_AXE] = { icon = 19, name = "Axe Fighting: %s" }, [SKILL_DISTANCE] = { icon = 22, name = "Distance Fighting: %s" }, [SKILL_SHIELD] = { icon = 25, name = "Shielding: %s" }, [SKILL_FISHING] = { icon = 23, name = "Fishing: %s" } } } m_TooltipFunction.config = { maxIconsInLine = 8, iconSize = 19 } function onLoad() connect(g_game, { onGameStart = onGameStart, onGameEnd = onGameEnd }) if g_game.isOnline() then onGameStart() end end function onUnLoad() disconnect(g_game, { onGameStart = onGameStart, onGameEnd = onGameEnd }) onGameEnd() end function onGameStart() m_TooltipFunction.registerProtocol() m_TooltipFunction.destroy() end function onGameEnd() m_TooltipFunction.unregisterProtocol() m_TooltipFunction.destroy() end function m_TooltipFunction.registerProtocol() m_TooltipFunction.protocol = g_game.getProtocolGame() ProtocolGame.registerOpcode(m_TooltipFunction.GameServerParseTooltip, m_TooltipFunction.parseTooltip) end function m_TooltipFunction.unregisterProtocol() m_TooltipFunction.protocol = nil ProtocolGame.unregisterOpcode(m_TooltipFunction.GameServerParseTooltip, m_TooltipFunction.parseTooltip) end function m_TooltipFunction.parseTooltip(protocol, msg) local size = msg:getU8() local list = {} local virtual = false for i = 1, size do local attributeId = msg:getU8() local attributeValue, attributeType if msg:getU8() == 1 then if msg:getU8() == 1 then attributeValue = -msg:getU32() else attributeValue = msg:getU32() end attributeType = msg:getU32() else attributeValue = msg:getString() end if attributeId == TOOLTIP_ATTRIBUTE_VIRTUAL then virtual = true else table.insert(list, { id = attributeId, value = attributeValue, type = attributeType }) end end m_TooltipFunction.open(list) if virtual then m_TooltipFunction.cache[m_TooltipList.clientId] = list end end function m_TooltipFunction.cancelEvent() m_TooltipList.clientId = false m_TooltipList.serverId = false m_TooltipList.position = false if m_TooltipFunction.event then m_TooltipFunction.event:cancel() m_TooltipFunction.event = nil end end function m_TooltipFunction.create(position, item, virtual) m_TooltipFunction.cancelEvent() m_TooltipList.clientId = item:getId() m_TooltipList.serverId = item:getServerId() m_TooltipList.position = position if virtual then m_TooltipFunction.event = scheduleEvent(function() local cacheItem = m_TooltipFunction.cache[m_TooltipList.clientId] if cacheItem then m_TooltipFunction.open(cacheItem) else local msg = OutputMessage.create() msg:addU8(m_TooltipFunction.GameServerSendTooltip) msg:addU8(0) if m_TooltipList.serverId > 0 then msg:addU8(1) msg:addU16(m_TooltipList.serverId) else msg:addU8(0) msg:addU16(m_TooltipList.clientId) end msg:addU16(item:getCount()) m_TooltipFunction.protocol:send(msg) end end, m_TooltipFunction.delay) else m_TooltipFunction.event = scheduleEvent(function() local msg = OutputMessage.create() msg:addU8(m_TooltipFunction.GameServerSendTooltip) msg:addU8(1) msg:addU8(item.counter and 1 or 0) m_TooltipFunction.protocol:addPosition(msg, item.position or item:getPosition()) msg:addU16(m_TooltipList.clientId) msg:addU8(item:getStackPos()) m_TooltipFunction.protocol:send(msg) end, m_TooltipFunction.delay) end end function m_TooltipFunction.destroyByItem(itemId) if itemId and m_TooltipList.clientId == itemId then m_TooltipFunction.destroy() end end function m_TooltipFunction.destroy() m_TooltipFunction.cancelEvent() if m_TooltipList.window then m_TooltipList.list:destroyChildren() m_TooltipList.window:destroy() m_TooltipList = {} end end function m_TooltipFunction.addLabel(name, height, width, description, icon, color, update) local widget = g_ui.createWidget(name) widget:setId(description) if update then widget:setParent(m_TooltipFunction.list) end if description then widget:setText(description) width = math.min(m_TooltipFunction.maximumWidth, math.max(widget:getWidth() + 16, width)) end if color then widget:setColor(color) end if icon then m_TooltipFunction.setIconImageType(widget:getChildById("icon"), icon) end if not update then widget:setParent(m_TooltipList.list) end return height + widget:getHeight() + 4, width, widget end function m_TooltipFunction.getImageClip(id) if not id then return "0 0 " .. m_TooltipFunction.config.iconSize .. " " .. m_TooltipFunction.config.iconSize end return (id - 1) % m_TooltipFunction.config.maxIconsInLine * m_TooltipFunction.config.iconSize .. " " .. (math.ceil(id / m_TooltipFunction.config.maxIconsInLine) - 1) * m_TooltipFunction.config.iconSize .. " " .. m_TooltipFunction.config.iconSize .. " " .. m_TooltipFunction.config.iconSize end function m_TooltipFunction.setIconImageType(widget, id) if not id then return false end widget:setImageClip(m_TooltipFunction.getImageClip(id)) end function m_TooltipFunction.getAttribute(list, id) for _, attributeValues in pairs(list) do if attributeValues.id == id then return attributeValues.value end end return "" end function m_TooltipFunction.titleCase(str) local words = {} for word in str:gmatch("%S+") do table.insert(words, word) end for i, word in ipairs(words) do local firstLetter = word:sub(1, 1):upper() local restOfWord = word:sub(2) words[i] = firstLetter .. restOfWord end local result = table.concat(words, " ") return result end function m_TooltipFunction.getBonusAttribute(bonuses) if bonuses then local data = {} for bonus in bonuses:gmatch("([^|]+)") do data[#data + 1] = tonumber(bonus) end return data end return nil end function m_TooltipFunction.open(list) if not m_TooltipList.position then return true end if not m_TooltipList.window then m_TooltipList.window = g_ui.displayUI("game_tooltip") m_TooltipList.list = m_TooltipList.window:getChildById("list") else m_TooltipList.list:destroyChildren() end m_TooltipList.window:show() m_TooltipList.window:setImageColor("#000000d4") m_TooltipList.window:getChildById("item"):setItemId(m_TooltipList.clientId) local height = 48 local width = 40 local color local name = m_TooltipFunction.titleCase(m_TooltipFunction.getAttribute(list, m_TooltipFunction.TOOLTIP_ATTRIBUTE_NAME)) local mainAttributes = { m_TooltipFunction.TOOLTIP_ATTRIBUTE_DEFENSE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_ATTACK, m_TooltipFunction.TOOLTIP_ATTRIBUTE_ARMOR, m_TooltipFunction.TOOLTIP_ATTRIBUTE_SHOOTRANGE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_DURATION, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CHARGES, m_TooltipFunction.TOOLTIP_ATTRIBUTE_FLUIDTYPE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_KEY, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CONTAINER_SIZE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_WEIGHT, m_TooltipFunction.TOOLTIP_ATTRIBUTE_TEXT, m_TooltipFunction.TOOLTIP_ATTRIBUTE_RARITY } local secondaryAttributes = { m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEREDUCTION, m_TooltipFunction.TOOLTIP_ATTRIBUTE_HITCHANCE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_ATTACK_SPEED, m_TooltipFunction.TOOLTIP_ATTRIBUTE_HEALTH_REGEN, m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANA_REGEN, m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_LEVEL, m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_MAGIC_LEVEL, m_TooltipFunction.TOOLTIP_ATTRIBUTE_RUNE_NAME, m_TooltipFunction.TOOLTIP_ATTRIBUTE_SPEED, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRITICALHITCHANCE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRITICALHITDAMAGE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANALEECH, m_TooltipFunction.TOOLTIP_ATTRIBUTE_LIFELEECH, m_TooltipFunction.TOOLTIP_ATTRIBUTE_EXPERIENCE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMAGIC, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMELEE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTDISTANCE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTHEALTH, m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEINCREASE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_MOREWEAPONATTACK, m_TooltipFunction.TOOLTIP_ATTRIBUTE_HEALINGRUNEINCREASE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANARUNEINCREASE2, m_TooltipFunction.TOOLTIP_ATTRIBUTE_DAMAGEPENETRATION, m_TooltipFunction.TOOLTIP_ATTRIBUTE_CRAFTMANA, m_TooltipFunction.TOOLTIP_ATTRIBUTE_MANACOSTREDUCTION, m_TooltipFunction.TOOLTIP_ATTRIBUTE_LUCK, m_TooltipFunction.TOOLTIP_ATTRIBUTE_DODGE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_BOUNCE, m_TooltipFunction.TOOLTIP_ATTRIBUTE_BOUNCECOUNT } local skillsAndResistances = { m_TooltipFunction.TOOLTIP_ATTRIBUTE_RESISTANCES, m_TooltipFunction.TOOLTIP_ATTRIBUTE_SKILL, m_TooltipFunction.TOOLTIP_ATTRIBUTE_STATS } function handleAttributes(attributes, height, width) for _, attributeValues in pairs(list) do local displayInfo = m_TooltipFunction.descriptionByAttributeId[attributeValues.id] if displayInfo and table.contains(attributes, attributeValues.id) then if type(displayInfo) == "table" and not displayInfo.name then displayInfo = displayInfo[attributeValues.type or attributeValues.value] end if displayInfo and displayInfo.name then if displayInfo.symbol then local valueStr = tostring(attributeValues.value) valueStr = valueStr:gsub("^+*", "") attributeValues.value = "+" .. valueStr elseif string.sub(attributeValues.value, 1, 1) == "\n" then attributeValues.value = string.sub(attributeValues.value, 2, #attributeValues.value) end if attributeValues.id == m_TooltipFunction.TOOLTIP_ATTRIBUTE_TEXT then height, width = m_TooltipFunction.addLabel("LookItemIconDescription", height, width, displayInfo.name:format(attributeValues.value), displayInfo.icon) else height, width = m_TooltipFunction.addLabel("LookItemIconAttribute", height, width, displayInfo.name:format(attributeValues.value), displayInfo.icon) end end end end return height, width end function hasValidAttributes(attributes) for _, attributeValues in pairs(list) do local displayInfo = m_TooltipFunction.descriptionByAttributeId[attributeValues.id] if displayInfo and table.contains(attributes, attributeValues.id) then if type(displayInfo) == "table" and not displayInfo.name then displayInfo = displayInfo[attributeValues.type or attributeValues.value] end if displayInfo and displayInfo.name then return true end end end return false end for _, attributeValues in pairs(list) do if attributeValues.id == m_TooltipFunction.TOOLTIP_ATTRIBUTE_RARITY then local v = m_TooltipFunction.descriptionByAttributeId[attributeValues.id][attributeValues.value] name = v.name:format(attributeValues.value) .. " " .. name color = v.color break end end height, width, nameWidget = m_TooltipFunction.addLabel("LookItemName", height, width, name, nil, color) height = m_TooltipFunction.addLabel("TooltipSeparator", height, width) height, width = handleAttributes(mainAttributes, height, width) for _, attributeValues in pairs(list) do if attributeValues.id == m_TooltipFunction.TOOLTIP_ATTRIBUTE_WIELDINFO then local displayInfo = m_TooltipFunction.descriptionByAttributeId[attributeValues.id] local vocations = regexMatch(displayInfo.name:format(attributeValues.value), "properly by ([a-zA-Z, ]+?(?: and [a-zA-Z]+)?)(?: of| with|\\.)") if #vocations ~= 0 then height, width = m_TooltipFunction.addLabel("LookItemIconAttribute", height, width, "Vocations: " .. vocations[1][2], 46) end local level = regexMatch(displayInfo.name:format(attributeValues.value), "level ([0-9]*) or higher") if #level ~= 0 then height, width = m_TooltipFunction.addLabel("LookItemIconAttribute", height, width, "Level: " .. tonumber(level[1][2]), 58) end end if attributeValues.id == m_TooltipFunction.TOOLTIP_ATTRIBUTE_RARITY then local v = m_TooltipFunction.descriptionByAttributeId[attributeValues.id][attributeValues.value] height, width = m_TooltipFunction.addLabel("LookItemIconAttribute", height, width, v.name:format(attributeValues.value), v.icon, v.color) end end if hasValidAttributes(secondaryAttributes) then height = m_TooltipFunction.addLabel("TooltipSeparator", height, width) height, width = m_TooltipFunction.addLabel("LookItemName", height, width, "Attributes") height, width = handleAttributes(secondaryAttributes, height, width) end if hasValidAttributes(skillsAndResistances) then height = m_TooltipFunction.addLabel("TooltipSeparator", height, width) height, width = m_TooltipFunction.addLabel("LookItemName", height, width, "Skills and Resistances") height, width = handleAttributes(skillsAndResistances, height, width) end m_TooltipList.window:setWidth(width) m_TooltipList.window:setHeight(height) local mousePos = g_window.getMousePosition() if mousePos.x > g_window.getSize().width / 2 then m_TooltipList.window:move(mousePos.x - (width + 5), mousePos.y + 10) else m_TooltipList.window:move(mousePos.x + 5, mousePos.y + 10) end m_TooltipList.window:raise() m_TooltipList.window:show() g_effects.fadeIn(m_TooltipList.window, 200) end