Doubt with function
Raynou opened this issue ยท 2 comments
Hi, I want to make a refactor of a function in Core.lua, but I don't understand very well what exactly the function does:
function mog:ToNumberItem(item)
if type(item) == "string" then
local id, diff, bonus = item:match(mog.itemStringPattern);
-- bonus ID can also be warforged, socketed, etc
-- if there is more than one bonus ID, need to check all
if bonus then
if not tonumber(bonus) then
for bonusID in gmatch(bonus, "%d+") do
if bonusDiffs[tonumber(bonusID)] then
bonus = bonusID;
break;
end
end
elseif not bonusDiffs[tonumber(bonus)] then
bonus = nil;
end
end
id = id or item:match("item:(%d+)");
return tonumber(id), tonumber(bonus), tonumber(diff);
elseif type(item) == "number" then
return item;
end
end
The function takes an item in the shape of a simple item ID, such as 113979
, or an item string, such as item:113979::::::::70::512::1:9075:70
. If the input is an item ID, it is returned as is. If it is an item string, the function will attempt to parse and return from it an item ID, a bonus ID and a difficulty ID.