2.4.3. addon, shows better gear by slot and stat type
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

212 líneas
7.5KB

  1. if (1 > #itemdb) then
  2. print("Failed to load item database")
  3. else
  4. print("Item database loaded")
  5. end
  6. local function length_of(coll)
  7. if coll then
  8. local c = 0
  9. for k in pairs(coll) do
  10. c = (c + 1)
  11. end
  12. return c
  13. else
  14. return 0
  15. end
  16. end
  17. local function first(coll)
  18. local key = next(coll)
  19. return coll[key]
  20. end
  21. local function starts_with(s, patt)
  22. return (string.sub(s, 1, string.len(patt)) == patt)
  23. end
  24. local function un_quote(s)
  25. return string.gsub(s, "'", "")
  26. end
  27. local function max(a, b)
  28. if (a > b) then
  29. return a
  30. else
  31. return b
  32. end
  33. end
  34. local function matches(a, b)
  35. if starts_with(a, "lte:") then
  36. return (tonumber(string.sub(a, 5)) >= tonumber(b))
  37. elseif starts_with(a, "gte:") then
  38. return (tonumber(string.sub(a, 5)) <= tonumber(b))
  39. elseif starts_with(a, "lt<:") then
  40. return (tonumber(string.sub(a, 5)) > tonumber(b))
  41. elseif starts_with(a, "gt>:") then
  42. return (tonumber(string.sub(a, 5)) < tonumber(b))
  43. else
  44. return (a == b)
  45. end
  46. end
  47. local function find_items(params, _3fsort)
  48. _G.assert((nil ~= params), "Missing argument params on main.fnl:54")
  49. local results
  50. do
  51. local tbl_17_auto = {}
  52. local i_18_auto = #tbl_17_auto
  53. for _, row in ipairs(itemdb) do
  54. local val_19_auto
  55. do
  56. local hit = true
  57. for key, param in pairs(params) do
  58. hit = (hit and matches(param, row[key]))
  59. end
  60. if hit then
  61. val_19_auto = row
  62. else
  63. val_19_auto = nil
  64. end
  65. end
  66. if (nil ~= val_19_auto) then
  67. i_18_auto = (i_18_auto + 1)
  68. do end (tbl_17_auto)[i_18_auto] = val_19_auto
  69. else
  70. end
  71. end
  72. results = tbl_17_auto
  73. end
  74. if (_3fsort and results) then
  75. table.sort(results, _3fsort)
  76. return results
  77. else
  78. return results
  79. end
  80. end
  81. local function find_item(params, _3fsort)
  82. _G.assert((nil ~= params), "Missing argument params on main.fnl:69")
  83. local results = find_items(params, _3fsort)
  84. if results then
  85. return results[1]
  86. else
  87. return nil
  88. end
  89. end
  90. local function find_item_by_name(name)
  91. return find_item({[8] = name})
  92. end
  93. local function find_next_better_item(class, subclass, invtype, lv, ilv, stat_position, item_stat, _3fsort)
  94. local stat_comparison = "gt>:%d"
  95. return find_items({[4] = class, [6] = subclass, [10] = invtype, [14] = string.format("lte:%d", lv), [stat_position] = string.format(stat_comparison, item_stat)}, _3fsort)
  96. end
  97. local function find_good_item(invtype, lv, stat_position, stat_baseline, _3fsort)
  98. _G.assert((nil ~= stat_baseline), "Missing argument stat-baseline on main.fnl:88")
  99. _G.assert((nil ~= stat_position), "Missing argument stat-position on main.fnl:88")
  100. _G.assert((nil ~= lv), "Missing argument lv on main.fnl:88")
  101. _G.assert((nil ~= invtype), "Missing argument invtype on main.fnl:88")
  102. return find_items({[10] = invtype, [14] = string.format("lte:%d", lv), [stat_position] = string.format("gte:%d", stat_baseline)}, _3fsort)
  103. end
  104. local function parse_item_id(link)
  105. return tonumber(string.sub(string.match(link, "item:[%d+]+"), 6))
  106. end
  107. local function parse_opts(msg)
  108. local tbl_17_auto = {}
  109. local i_18_auto = #tbl_17_auto
  110. for k, v in string.gmatch(msg, "%w+") do
  111. local val_19_auto = v
  112. if (nil ~= val_19_auto) then
  113. i_18_auto = (i_18_auto + 1)
  114. do end (tbl_17_auto)[i_18_auto] = val_19_auto
  115. else
  116. end
  117. end
  118. return tbl_17_auto
  119. end
  120. local function ui_print(msg)
  121. return UIErrorsFrame:AddMessage(msg)
  122. end
  123. local function stat_name(n)
  124. local stat_names = {"Mana", "Health", "No Visible Effect", "Agility", "Strength", "Intellect", "Spirit", "Stamina", "No Visible Effect", "No Visible Effect", "No Visible Effect", "No Visible Effect*", "Defense Rating", "Dodge", "Parry Rating", "Shield Block Rating", "Melee Hit Rating", "Ranged Hit Rating", "Spell Hit Rating", "Melee Critical Strike", "Ranged Critical Strike", "Spell Critical Strike", "Melee Hit Avoidance", "Ranged Hit Avoidance", "Spell Hit Avoidance", "Melee Critical Avoidance", "Spell Critical Avoidance", "Melee Haste Rating", "Ranged Haste Rating", "Spell Haste Rating", "Hit Avoidance Rating", "Hit Rating", "Critical Strike", "Hit Avoidance Rating", "Critical Avoidance Rating", "Resilience", "Haste", "Expertise", "Attack Power", "Ranged Attack Power", "No Visible Effect", "Healing Done By Magical Spells and Effects up to value", "Damage Done By Magical Spells and Effects up to value", "Mana Regeneration (Ticks every 5 seconds)", "Armor Penetration Rating", "Spell Power", "Health Regeneration (Ticks every 5 seconds)", "Spell Penetration", "Block Value of Shield", "Mastery", "Armor", "Fire Resist", "Frost Resist", "Shadow Resist", "Nature Resist", "Arcane Resist"}
  125. return (stat_names[(n + 1)] .. " (" .. n .. ")")
  126. end
  127. local function stat_print(item)
  128. local val = ""
  129. for n = 22, 56 do
  130. if (0 < item[n]) then
  131. val = (val .. " " .. stat_name((n - 21)) .. ": " .. item[n])
  132. else
  133. end
  134. end
  135. return val
  136. end
  137. local function main0(msg)
  138. local opts
  139. do
  140. local tbl_17_auto = {}
  141. local i_18_auto = #tbl_17_auto
  142. for v in string.gmatch(msg, "%w+") do
  143. local val_19_auto = v
  144. if (nil ~= val_19_auto) then
  145. i_18_auto = (i_18_auto + 1)
  146. do end (tbl_17_auto)[i_18_auto] = val_19_auto
  147. else
  148. end
  149. end
  150. opts = tbl_17_auto
  151. end
  152. local _let_12_ = opts
  153. local slot = _let_12_[1]
  154. local stat = _let_12_[2]
  155. local gear_index = _let_12_[3]
  156. local slot0 = (slot .. "Slot")
  157. local stat0 = (21 + tonumber(stat))
  158. local gear_index0 = tonumber((gear_index or "1"))
  159. local inv_slot = GetInventorySlotInfo(slot0)
  160. local i_link = GetInventoryItemLink("player", inv_slot)
  161. local i_id
  162. if i_link then
  163. i_id = parse_item_id(i_link)
  164. else
  165. i_id = nil
  166. end
  167. local p_level = UnitLevel("player")
  168. if not i_link then
  169. local best
  170. local function _14_(a, b)
  171. return ((a[12] + a[stat0]) < (b[12] + b[stat0]))
  172. end
  173. best = (find_good_item(inv_slot, UnitLevel("player"), stat0, 0, _14_))[gear_index0]
  174. if best then
  175. DEFAULT_CHAT_FRAME:AddMessage(string.format("|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r", best[2], best[8]))
  176. return ui_print(("next best available: " .. best[8] .. " " .. stat_print(best) .. " at " .. best[20] .. "N/A"))
  177. else
  178. return nil
  179. end
  180. else
  181. local i_name = GetItemInfo(i_link)
  182. local stats = find_item_by_name(un_quote(i_name))
  183. if stats then
  184. local i_class = stats[4]
  185. local i_subclass = stats[6]
  186. local i_invtype = stats[10]
  187. local i_level = stats[12]
  188. local i_stat = stats[stat0]
  189. local best
  190. local function _16_(a, b)
  191. return ((a[12] + a[stat0]) < (b[12] + b[stat0]))
  192. end
  193. best = (find_next_better_item(i_class, i_subclass, i_invtype, p_level, i_level, stat0, max(i_stat, 0), _16_))[gear_index0]
  194. if best then
  195. DEFAULT_CHAT_FRAME:AddMessage(string.format("|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r", best[2], best[8]))
  196. ui_print(("next best available: " .. best[8] .. " " .. stat_print(best) .. " at " .. best[20] .. "N/A"))
  197. ui_print(("currently equipped " .. i_name .. " " .. (stats[stat0] or "N/A")))
  198. else
  199. end
  200. else
  201. print(("Item " .. un_quote(i_name) .. " not found"))
  202. end
  203. return "ok"
  204. end
  205. end
  206. main = main0
  207. local function maxxed()
  208. local slots = {"AmmoSlot", "BackSlot", "Bag0Slot", "Bag1Slot", "Bag2Slot", "Bag3Slot", "ChestSlot", "FeetSlot", "Finger0Slot", "Finger1Slot", "HandsSlot", "HeadSlot", "LegsSlot", "MainHandSlot", "NeckSlot", "RangedSlot", "SecondaryHandSlot", "ShirtSlot", "ShoulderSlot", "TabardSlot", "Trinket0Slot", "Trinket1Slot", "WaistSlot", "WristSlot"}
  209. return slots
  210. end
  211. return maxxed