Files

595 lines
27 KiB
Lua

-- Russian item tooltips. The game gives the tooltip lines in Russian; this turns them into the English
-- lines the parser (Items.lua) already understands, so nothing else in the addon has to know the language.
-- Used automatically: a tooltip with Cyrillic text is converted, an English one is left alone.
-- Lines that are not recognised stay as they are and show up in /adeg unparsed.
-- Lua 5.0: no string.match, no #; patterns are byte based, so words are compared as plain text.
local AG = AdeGear
local Ru = {}
AG.Ru = Ru
-- lower case for Cyrillic (UTF-8: A-P = 208 144-159, R-Ya = 208 160-175, Yo = 208 129)
local function Lower(s)
if not s then return "" end
s = string.lower(s)
s = string.gsub(s, "\208([\144-\159])", function(b) return "\208" .. string.char(string.byte(b) + 32) end)
s = string.gsub(s, "\208([\160-\175])", function(b) return "\209" .. string.char(string.byte(b) - 32) end)
s = string.gsub(s, "\208\129", "\209\145")
return s
end
Ru.Lower = Lower
local function Has(s, stem) return string.find(s, stem, 1, true) ~= nil end
local function Clean(t)
if not t then return "" end
t = string.gsub(t, "|c%x%x%x%x%x%x%x%x", "")
t = string.gsub(t, "|r", "")
t = string.gsub(t, "^%s+", "")
t = string.gsub(t, "%s+$", "")
return t
end
local function HasCyrillic(t)
return t ~= nil and string.find(t, "[\208\209]") ~= nil
end
local function Num(s) return (string.gsub(s, ",", ".")) end
----------------------------------------------------------------------
-- Tables
----------------------------------------------------------------------
local SLOT = {
["голова"] = "Head", ["шея"] = "Neck", ["плечо"] = "Shoulder", ["плечи"] = "Shoulder", ["спина"] = "Back",
["грудь"] = "Chest", ["одежда"] = "Chest", ["рубашка"] = "Shirt", ["гербовая накидка"] = "Tabard",
["запястья"] = "Wrist", ["запястье"] = "Wrist", ["кисти рук"] = "Hands", ["пояс"] = "Waist", ["ноги"] = "Legs",
["ступни"] = "Feet", ["палец"] = "Finger", ["аксессуар"] = "Trinket",
["одноручное"] = "One-Hand", ["двуручное"] = "Two-Hand", ["правая рука"] = "Main Hand",
["левая рука"] = "Off Hand", ["держится в левой руке"] = "Held In Off-hand",
["дальний бой"] = "Ranged", ["метательное"] = "Thrown", ["реликвия"] = "Relic",
}
local BIND = {
["становится персональным при надевании"] = "Binds when equipped",
["становится персональным при получении"] = "Soulbound",
["становится персональным при использовании"] = "Binds when used",
["персональный"] = "Soulbound",
["персональный предмет"] = "Soulbound",
["уникальный"] = "Unique",
}
local CLASS = {
{ "воин", "Warrior" }, { "паладин", "Paladin" }, { "охотник", "Hunter" }, { "разбойник", "Rogue" },
{ "жрец", "Priest" }, { "шаман", "Shaman" }, { "маг", "Mage" }, { "чернокнижник", "Warlock" },
{ "друид", "Druid" },
}
local SCHOOL = {
{ "тайн", "Arcane" }, { "огн", "Fire" }, { "огон", "Fire" }, { "холод", "Frost" }, { "льд", "Frost" },
{ "лед", "Frost" }, { "мороз", "Frost" }, { "свет", "Holy" }, { "свят", "Holy" }, { "природ", "Nature" },
{ "тьм", "Shadow" }, { "темн", "Shadow" }, { "тен", "Shadow" },
}
local function School(w)
for i = 1, table.getn(SCHOOL) do
if Has(w, SCHOOL[i][1]) then return SCHOOL[i][2] end
end
return nil
end
-- main stat from a word ("силе", "Силы", "ловкости", "Выносливости", "интеллекту", "Интелекта", "духа")
local function StatName(w)
if Has(w, "сил") then return "Strength" end
if Has(w, "ловк") then return "Agility" end
if Has(w, "выносл") then return "Stamina" end
if Has(w, "интел") then return "Intellect" end
if Has(w, "дух") then return "Spirit" end
return nil
end
-- kinds of weapons and armor from a word (the right-hand text of a slot line, or an item type)
local WEAPON_STEM = {
{ "арбалет", "Crossbow" }, { "топор", "Axe" }, { "дробящ", "Mace" }, { "кинжал", "Dagger" },
{ "древков", "Polearm" }, { "посох", "Staff" }, { "посохи", "Staff" }, { "кистев", "Fist Weapon" },
{ "кулачн", "Fist Weapon" }, { "огнестрел", "Gun" }, { "жезл", "Wand" }, { "метательн", "Thrown" },
{ "удочк", "Fishing Pole" }, { "меч", "Sword" },
}
local ARMOR_STEM = {
{ "щит", "Shield" }, { "кольчуг", "Mail" }, { "ткан", "Cloth" }, { "кож", "Leather" }, { "лат", "Plate" },
{ "манускрипт", "Libram" }, { "либрам", "Libram" }, { "идол", "Idol" }, { "тотем", "Totem" },
}
local function KindOfWord(w)
w = Lower(w)
if w == "лук" or w == "луки" then return "Bow", true end
for i = 1, table.getn(WEAPON_STEM) do
if Has(w, WEAPON_STEM[i][1]) then return WEAPON_STEM[i][2], true end
end
for i = 1, table.getn(ARMOR_STEM) do
if Has(w, ARMOR_STEM[i][1]) then return ARMOR_STEM[i][2], false end
end
return nil
end
-- the item's inventory type from the game is English whatever the language (GetItemInfo, 8th value)
local EQUIP_LOC = {
INVTYPE_HEAD = "Head", INVTYPE_NECK = "Neck", INVTYPE_SHOULDER = "Shoulder", INVTYPE_BODY = "Shirt",
INVTYPE_CHEST = "Chest", INVTYPE_ROBE = "Chest", INVTYPE_WAIST = "Waist", INVTYPE_LEGS = "Legs",
INVTYPE_FEET = "Feet", INVTYPE_WRIST = "Wrist", INVTYPE_HAND = "Hands", INVTYPE_FINGER = "Finger",
INVTYPE_TRINKET = "Trinket", INVTYPE_CLOAK = "Back", INVTYPE_WEAPON = "One-Hand", INVTYPE_2HWEAPON = "Two-Hand",
INVTYPE_WEAPONMAINHAND = "Main Hand", INVTYPE_WEAPONOFFHAND = "Off Hand", INVTYPE_SHIELD = "Off Hand",
INVTYPE_HOLDABLE = "Held In Off-hand", INVTYPE_RANGED = "Ranged", INVTYPE_RANGEDRIGHT = "Ranged",
INVTYPE_THROWN = "Thrown", INVTYPE_RELIC = "Relic", INVTYPE_TABARD = "Tabard",
}
-- item class / subclass numbers of the item database (armor = class 4, weapon = class 2)
local ARMOR_SUB = { [1] = "Cloth", [2] = "Leather", [3] = "Mail", [4] = "Plate", [6] = "Shield", [7] = "Libram", [8] = "Idol", [9] = "Totem" }
local WEAPON_SUB = {
[0] = "Axe", [1] = "Axe", [2] = "Bow", [3] = "Gun", [4] = "Mace", [5] = "Mace", [6] = "Polearm", [7] = "Sword",
[8] = "Sword", [10] = "Staff", [13] = "Fist Weapon", [15] = "Dagger", [16] = "Thrown", [18] = "Crossbow",
[19] = "Wand", [20] = "Fishing Pole",
}
-- the item database of the server, when an addon of the game exposes it (nampower: GetItemStats and
-- GetItemStatsField). Field names are tried in a few spellings; nil when nothing answers.
local function TemplateField(id, names)
if GetItemStatsField then
for i = 1, table.getn(names) do
local ok, v = pcall(GetItemStatsField, id, names[i])
if ok and v ~= nil then return tonumber(v) end
end
end
if GetItemStats then
local ok, t = pcall(GetItemStats, id)
if ok and type(t) == "table" then
for k, v in pairs(t) do
local lk = string.lower(tostring(k))
for i = 1, table.getn(names) do
if lk == string.lower(names[i]) then return tonumber(v) end
end
end
end
end
return nil
end
local function KindFromTemplate(link)
if not link then return nil end
local s, e, id = string.find(link, "item:(%d+)")
if not s then return nil end
id = tonumber(id)
local class = TemplateField(id, { "class", "itemClass", "item_class" })
local sub = TemplateField(id, { "subclass", "subClass", "itemSubClass", "sub_class" })
if class == nil or sub == nil then return nil end
if class == 4 and ARMOR_SUB[sub] then return ARMOR_SUB[sub], false end
if class == 2 and WEAPON_SUB[sub] then return WEAPON_SUB[sub], true end
return nil
end
Ru.KindFromTemplate = KindFromTemplate
-- the kind from the game: the item database first, then the subtype text of GetItemInfo
local function KindFromInfo(link)
if not link then return nil end
local k, w = KindFromTemplate(link)
if k then return k, w end
if not GetItemInfo then return nil end
local n, l, q, lv, itype, subtype = GetItemInfo(link)
if subtype and subtype ~= "" then
local k2, weapon = KindOfWord(subtype)
if k2 then return k2, weapon end
end
return nil
end
local function EquipLoc(link)
if not link or not GetItemInfo then return nil end
local n, l, q, lv, itype, subtype, stack, loc = GetItemInfo(link)
if loc and EQUIP_LOC[loc] then return EQUIP_LOC[loc], loc end
return nil
end
-- weapons: the kind from words of the name (only when nothing else says it); clear words only
local NAME_STEM = {
{ "кинжал", "Dagger" }, { "стилет", "Dagger" }, { "топор", "Axe" }, { "секир", "Axe" }, { "посох", "Staff" },
{ "арбалет", "Crossbow" }, { "винтовк", "Gun" }, { "ружь", "Gun" }, { "мушкет", "Gun" }, { "пистолет", "Gun" },
{ "булав", "Mace" }, { "молот", "Mace" }, { "дубин", "Mace" }, { "палиц", "Mace" },
{ "ятаган", "Sword" }, { "клеймор", "Sword" }, { "сабл", "Sword" }, { "рапир", "Sword" }, { "меч", "Sword" },
{ "алебард", "Polearm" }, { "копь", "Polearm" }, { "древков", "Polearm" },
}
local function KindFromName(name)
local n = Lower(name)
if string.find(" " .. n .. " ", " лук ", 1, true) then return "Bow" end
for i = 1, table.getn(NAME_STEM) do
if Has(n, NAME_STEM[i][1]) then return NAME_STEM[i][2] end
end
return nil
end
----------------------------------------------------------------------
-- Sentences of Equip / Set / Chance on hit effects
----------------------------------------------------------------------
-- weapon skills named in "Повышение навыка использования арбалетов на 4 ед."
local SKILLS = {
{ "двуручных мечей", "Two-Handed Swords" }, { "двуручных топоров", "Two-Handed Axes" },
{ "двуручного дробящего", "Two-Handed Maces" }, { "арбалет", "Crossbows" }, { "огнестрел", "Guns" },
{ "мечей", "Swords" }, { "топоров", "Axes" }, { "дробящего", "Maces" }, { "кинжал", "Daggers" },
{ "посох", "Staves" }, { "древков", "Polearms" }, { "кистев", "Fist Weapons" }, { "кулачн", "Fist Weapons" },
{ "луков", "Bows" }, { "метательн", "Thrown" }, { "рыбной ловли", "Fishing" },
}
local SKILL_KIND = {
Crossbows = "Crossbow", Guns = "Gun", Bows = "Bow", Daggers = "Dagger", Staves = "Staff", Polearms = "Polearm",
["Fist Weapons"] = "Fist Weapon", Swords = "Sword", Axes = "Axe", Maces = "Mace",
}
-- turns a Russian effect sentence into the English one the parser knows; nil when it is not known
-- second value: the weapon skill the sentence names (it tells the kind of a weapon)
local function Effect(x)
local lw = Lower(x)
local s, e, n = string.find(x, "(%d+[%.,]%d+)")
if not s then s, e, n = string.find(x, "(%d+)") end
if not s then return nil end
n = Num(n)
if Has(lw, "навык") then
for i = 1, table.getn(SKILLS) do
if Has(lw, SKILLS[i][1]) then return "Increased " .. SKILLS[i][2] .. " +" .. n .. ".", SKILLS[i][2] end
end
return nil
end
if Has(lw, "игнорир") and Has(lw, "брон") then return "Your attacks ignore " .. n .. " of the target's armor." end
if Has(lw, "нанесение") and Has(lw, "урона") and Has(lw, "противник") then
local sc = School(lw) or "Physical"
return "When struck in combat inflicts " .. n .. " " .. sc .. " damage to the attacker."
end
if Has(lw, "исцел") or Has(lw, "лечащ") then
if Has(lw, "урон") then return "Increases damage and healing done by magical spells and effects by up to " .. n .. "." end
return "Increases healing done by spells and effects by up to " .. n .. "."
end
if Has(lw, "урон") and Has(lw, "заклинан") and Has(lw, "не более") then
local sc = School(lw)
if sc then return "Increases damage done by " .. sc .. " spells and effects by up to " .. n .. "." end
return "Increases damage and healing done by magical spells and effects by up to " .. n .. "."
end
if Has(lw, "сил") and Has(lw, "атак") and not Has(lw, "заклинан") and not Has(lw, "скорост") then
if Has(lw, "дальн") then return "Increases ranged attack power by " .. n .. "." end
return "Increases attack power by " .. n .. "."
end
if Has(lw, "5 сек") then
if Has(lw, "мана") or Has(lw, "маны") or Has(lw, "маной") then return "Restores " .. n .. " mana per 5 sec." end
if Has(lw, "здоров") then return "Restores " .. n .. " health per 5 sec." end
end
if Has(lw, "скорост") and Has(lw, "%") then
if Has(lw, "атак") and Has(lw, "заклинан") then return "Increases your attack and casting speed by " .. n .. "%." end
if Has(lw, "атак") then return "Increases your attack speed by " .. n .. "%." end
if Has(lw, "заклинан") then return "Increases your casting speed by " .. n .. "%." end
end
if Has(lw, "критическ") and Has(lw, "%") then
if Has(lw, "заклинан") then
-- "...ваших заклинаний светлой магии": only one school, not the general spell crit
if School(lw) then return nil end
return "Improves your chance to get a critical strike with spells by " .. n .. "%."
end
return "Improves your chance to get a critical strike by " .. n .. "%."
end
if (Has(lw, "меткост") or Has(lw, "попадан")) and Has(lw, "%") then
if Has(lw, "заклинан") then return "Improves your chance to hit with spells by " .. n .. "%." end
return "Improves your chance to hit by " .. n .. "%."
end
if Has(lw, "уклонен") and Has(lw, "%") then return "Increases your chance to dodge an attack by " .. n .. "%." end
if Has(lw, "парирован") and Has(lw, "%") then return "Increases your chance to parry an attack by " .. n .. "%." end
if Has(lw, "блокир") then
if Has(lw, "%") then return "Increases your chance to block attacks with a shield by " .. n .. "%." end
return "Increases the block value of your shield by " .. n .. "."
end
if Has(lw, "защит") and not Has(lw, "%") then return "Increased Defense +" .. n .. "." end
return nil
end
----------------------------------------------------------------------
-- One line
----------------------------------------------------------------------
-- text of the left side -> English line (or nil when the line is not recognised)
local Left
Left = function(t)
local s, e, a, b, c
local lt = Lower(t)
if BIND[lt] then return BIND[lt] end
s, e, a = string.find(t, "^Требуется уровень:? (%d+)$")
if s then return "Requires Level " .. a end
s, e, a = string.find(t, "^Броня:? (%d+)$")
if s then return a .. " Armor" end
s, e, a = string.find(t, "^Блокирование:? (%d+)$")
if s then return a .. " Block" end
s, e, a, b = string.find(t, "^Прочность:? (%d+) / (%d+)$")
if s then return "Durability " .. a .. " / " .. b end
if string.find(t, "^Железный шип") then return "Iron Spike" end
s, e, a, b = string.find(t, "^Урон:? (%d+) %- (%d+)$")
if s then return a .. " - " .. b .. " Damage" end
-- wands: "56 - 104 ед. (тайная магия)"
s, e, a, b, c = string.find(t, "^(%d+) %- (%d+) ед%. %((.+)%)$")
if s then
local sc = School(Lower(c)) or "Physical"
return a .. " - " .. b .. " " .. sc .. " Damage"
end
s, e, a = string.find(t, "^%((%d+[%.,]?%d*) ед%. урона в секунду%)$")
if s then return "(" .. Num(a) .. " damage per second)" end
s, e, a = string.find(t, "^Добавляет (%d+[%.,]?%d*) ед%. урона в секунду%.?$")
if s then return "Adds " .. Num(a) .. " damage per second." end
s, e, a = string.find(t, "^Классы:? (.+)$")
if s then
local list = {}
local la = Lower(a)
for i = 1, table.getn(CLASS) do
-- "маг" is inside other words, so a class counts as a whole word
if string.find(", " .. la .. ",", "[, ]" .. CLASS[i][1] .. "[, ]") then table.insert(list, CLASS[i][2]) end
end
if table.getn(list) > 0 then return "Classes: " .. table.concat(list, ", ") end
return "Classes: " .. a
end
-- requirements: reputation, professions
s, e, a = string.find(t, "^Требуется: (.+)$")
if s then
if Has(Lower(a), "фракции") or Has(Lower(a), "репутац") then return "Requires reputation -- Honored" end
return "Requires " .. a
end
-- effects
s, e, a = string.find(t, "^Если на персонаже: (.+)$")
if s then
local en = Effect(a)
if en then return "Equip: " .. en end
return "Equip: " .. a
end
s, e, a = string.find(t, "^Использование: (.+)$")
if s then
if Has(Lower(a), "обучает") then return "Use: Teaches you how to " .. a end
return "Use: " .. a
end
s, e, a = string.find(t, "^Возможный эффект при попадании: (.+)$")
if s then
-- "...наносящей 35 ед. урона от темной магии": the damage is read, the rest stays Russian
local lo, hi
s, e, lo, hi = string.find(a, "(%d+) %- (%d+) ед%. урона")
local dmg
local sc = School(Lower(a)) or "Physical"
if s then dmg = lo .. " to " .. hi .. " " .. sc .. " damage"
else
s, e, lo = string.find(a, "(%d+) ед%. урона")
if s then dmg = lo .. " " .. sc .. " damage" end
end
if dmg then return "Chance on hit: causing " .. dmg .. "." end
return "Chance on hit: " .. a
end
-- set bonuses
s, e, a, b = string.find(t, "^Комплект %((%d+) [^%)]*%): (.+)$")
if s then
local en = Effect(b)
local text = en or Left(b) or b
return "(" .. a .. ") Set: " .. text
end
s, e, a = string.find(t, "^Комплект: (.+)$")
if s then
local en = Effect(a)
local text = en or Left(a) or a
return "Set: " .. text
end
-- armor kits: "Усиление брони +16, Выносливость +2"
s, e, a, b, c = string.find(t, "^Усиление брони %+(%d+), (.+) %+(%d+)$")
if s then
local st = StatName(Lower(b))
if st then return "Reinforced Armor +" .. a .. "/+" .. c .. " " .. st end
end
-- stat lines: "+12 к силе", "+4 Духа", "-3 к духу", spell damage, healing, resistance
s, e, a, b, c = string.find(t, "^([%+%-])(%d+) к (.+)$")
if not s then s, e, a, b, c = string.find(t, "^([%+%-])(%d+) (.+)$") end
if s then
local lc = Lower(c)
local sign = a
if Has(lc, "заклинан") and Has(lc, "урон") then
local sc = School(lc)
if sc then return sign .. b .. " " .. sc .. " Spell Damage" end
return sign .. b .. " Spell Damage"
end
if Has(lc, "исцел") or Has(lc, "лечащ") then return sign .. b .. " Healing Spells" end
if Has(lc, "сопротивлен") then
if Has(lc, "всем") then return sign .. b .. " All Resistances" end
local sc = School(lc)
if sc then return sign .. b .. " " .. sc .. " Resistance" end
end
if Has(lc, "сил") and Has(lc, "атак") then return sign .. b .. " Attack Power" end
if Has(lc, "брон") then return sign .. b .. " Armor" end
local st = StatName(lc)
if st then return sign .. b .. " " .. st end
end
-- enchant lines: "Выносливость +1", "Броня +30"
s, e, a, b = string.find(t, "^(.+) %+(%d+)$")
if s then
local la = Lower(a)
if la == "броня" then return "Armor +" .. b end
if la == "здоровье" then return "Health +" .. b end
if la == "мана" then return "Mana +" .. b end
if la == "защита" then return "Defense +" .. b end
local st = StatName(la)
if st and string.len(la) < 40 then return st .. " +" .. b end
end
return nil
end
----------------------------------------------------------------------
-- Whole tooltip
----------------------------------------------------------------------
local RECIPE_PREFIX = {
{ "^Рецепт:", "Recipe:" }, { "^Чертеж:", "Plans:" }, { "^Чертёж:", "Plans:" }, { "^Схема:", "Schematic:" },
{ "^Выкройка:", "Pattern:" }, { "^Формула:", "Formula:" }, { "^Эскиз:", "Design:" },
}
local ARMOR_SLOTS = { Head = true, Shoulder = true, Chest = true, Waist = true, Legs = true, Feet = true, Wrist = true, Hands = true }
local WEAPON_SLOTS = { ["One-Hand"] = true, ["Two-Hand"] = true, ["Main Hand"] = true, ["Off Hand"] = true, Ranged = true }
-- lines: { { l, r, c }, ... } as read from the tooltip; link: the item (for its type).
-- Returns the new lines and a table about what the Russian tooltip did not say:
-- { typeUnknown = true } for armor or a weapon whose type (cloth/mail..., sword/bow...) is not known.
function Ru.Lines(lines, link)
local n = table.getn(lines)
local russian = false
for i = 2, n do
if HasCyrillic(lines[i].l) or HasCyrillic(lines[i].r) then russian = true break end
end
if not russian then return lines end
-- what the item has, to tell shields, held items and weapons apart
local hasBlock, hasDamage, hasWandDamage, slotAt, skillKind = false, false, false, nil, nil
for i = 2, n do
local t = Clean(lines[i].l)
if string.find(t, "^Блокирование") then hasBlock = true end
if string.find(t, "^Урон:? %d") then hasDamage = true end
if string.find(t, "^%d+ %- %d+ ед%. %(") then hasDamage = true; hasWandDamage = true end
if not slotAt and SLOT[Lower(t)] then slotAt = i end
local s, e, x = string.find(t, "^Если на персонаже: (.+)$")
if s then
local en, skill = Effect(x)
if skill and SKILL_KIND[skill] then skillKind = SKILL_KIND[skill] end
end
end
local infoKind, infoWeapon = KindFromInfo(link)
local locSlot, loc = EquipLoc(link)
local out = {}
local name = Clean(lines[1].l)
local first = { l = lines[1].l, r = lines[1].r, c = lines[1].c }
for i = 1, table.getn(RECIPE_PREFIX) do
local s, e = string.find(name, RECIPE_PREFIX[i][1])
if s then
first.l = RECIPE_PREFIX[i][2] .. string.sub(name, e + 1)
break
end
end
table.insert(out, first)
-- slot and kind of the item
local slot = locSlot
if slotAt and not slot then slot = SLOT[Lower(Clean(lines[slotAt].l))] end
local rightText = ""
if slotAt then rightText = Clean(lines[slotAt].r) end
local kind, isWeapon = nil, nil
if rightText ~= "" then kind, isWeapon = KindOfWord(rightText) end
if not kind then kind, isWeapon = infoKind, infoWeapon end
if loc == "INVTYPE_SHIELD" then kind = "Shield" end
if loc == "INVTYPE_RANGED" and not kind then kind = "Bow" end
if slot == "Off Hand" and hasBlock and not loc then kind = "Shield" end
if slot == "Off Hand" and not hasBlock and not hasDamage and (not loc or loc == "INVTYPE_HOLDABLE") then slot = "Held In Off-hand" end
if not kind and hasDamage then
if hasWandDamage then kind = "Wand"
elseif skillKind then kind = skillKind
else kind = KindFromName(name) end
if not kind and Has(Lower(name), "жезл") then kind = "Wand" end
end
-- a weapon with a damage line and no slot line is a ranged weapon (bow, gun, crossbow, wand)
if not slotAt and hasDamage and not slot then slot = "Ranged" end
local meta = { ru = true, orig = {} }
if slot and ARMOR_SLOTS[slot] and not kind then meta.typeUnknown = true end
if slot and WEAPON_SLOTS[slot] and hasDamage and not kind then meta.typeUnknown = true end
local slotDone = false
for i = 2, n do
local raw, rawR = lines[i].l, lines[i].r
local t, tr = Clean(raw), Clean(rawR)
local line = { l = raw, r = rawR, c = lines[i].c }
if t ~= "" or tr ~= "" then
if i == slotAt and slot then
line.l = slot
line.r = kind
if slot == "Held In Off-hand" then line.r = nil end
slotDone = true
else
local s, e, speed = string.find(tr, "^Скорость:? (%d+[%.,]?%d*)$")
local en = Left(t)
if s and en then
line.l = en
line.r = "Speed " .. Num(speed)
elseif en then
line.l = en
if tr ~= "" then line.r = tr end
end
if en and en ~= t then meta.orig[en] = t end
end
end
table.insert(out, line)
end
if slot and not slotDone then
-- no slot line in the tooltip (ranged weapons, some others): the game's inventory type gives it
table.insert(out, 2, { l = slot, r = kind, c = { 1, 1, 1 } })
end
return out, meta
end
----------------------------------------------------------------------
-- /adeg probe: what the game offers for item data (saved for the author)
----------------------------------------------------------------------
local function Dump(v)
if type(v) ~= "table" then return tostring(v) end
local parts = {}
local count = 0
for k, x in pairs(v) do
count = count + 1
if count > 60 then break end
table.insert(parts, tostring(k) .. "=" .. tostring(x))
end
table.sort(parts)
return "{" .. table.concat(parts, ", ") .. "}"
end
function Ru.Probe()
AdeGearDB = AdeGearDB or {}
local names = {}
local env = getfenv(0)
for k, v in pairs(env) do
if type(v) == "function" and type(k) == "string" then
if string.find(k, "Item") or string.find(k, "Equip") or string.find(k, "Usable") or string.find(k, "RecField")
or string.find(k, "CanUse") or string.find(k, "Stats") then
table.insert(names, k)
end
end
end
table.sort(names)
local probe = { funcs = table.concat(names, ", "), calls = {} }
local ids = { 60694, 3430, 6389 }
local fields = { "class", "subclass", "itemClass", "itemSubClass", "inventoryType", "itemLevel", "allowableClass", "requiredLevel", "armor" }
local found = {}
local cands = { "GetItemStats", "GetItemStatsField", "GetItemRecField", "GetItemInfoEx", "GetItemTemplate", "GetItemData" }
for i = 1, table.getn(cands) do
local fn = env[cands[i]]
if type(fn) == "function" then
table.insert(found, cands[i])
for j = 1, table.getn(ids) do
local ok, res = pcall(fn, ids[j])
table.insert(probe.calls, cands[i] .. "(" .. ids[j] .. ") -> " .. tostring(ok) .. " " .. Dump(res))
for f = 1, table.getn(fields) do
local ok2, res2 = pcall(fn, ids[j], fields[f])
if ok2 and res2 ~= nil then
table.insert(probe.calls, cands[i] .. "(" .. ids[j] .. ", " .. fields[f] .. ") -> " .. Dump(res2))
end
end
end
end
end
AdeGearDB.probe = probe
AG.Msg("probe saved: " .. table.getn(names) .. " item related functions, item database functions: " .. (table.getn(found) > 0 and table.concat(found, ", ") or "none"))
AG.Msg("now /reload and send the saved variables file")
end