2.4.3. addon, shows better gear by slot and stat type
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
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. return find_items({[4] = class, [6] = subclass, [10] = invtype, [14] = string.format("lte:%d", lv), [stat_position] = string.format("gt>:%d", item_stat)}, _3fsort)
  95. end
  96. local function find_good_item(invtype, lv, stat_position, stat_baseline, _3fsort)
  97. _G.assert((nil ~= stat_baseline), "Missing argument stat-baseline on main.fnl:89")
  98. _G.assert((nil ~= stat_position), "Missing argument stat-position on main.fnl:89")
  99. _G.assert((nil ~= lv), "Missing argument lv on main.fnl:89")
  100. _G.assert((nil ~= invtype), "Missing argument invtype on main.fnl:89")
  101. return find_items({[10] = invtype, [14] = string.format("lte:%d", lv), [stat_position] = string.format("gte:%d", stat_baseline)}, _3fsort)
  102. end
  103. local function parse_item_id(link)
  104. return tonumber(string.sub(string.match(link, "item:[%d+]+"), 6))
  105. end
  106. local function parse_opts(msg)
  107. local tbl_17_auto = {}
  108. local i_18_auto = #tbl_17_auto
  109. for k, v in string.gmatch(msg, "%w+") do
  110. local val_19_auto = v
  111. if (nil ~= val_19_auto) then
  112. i_18_auto = (i_18_auto + 1)
  113. do end (tbl_17_auto)[i_18_auto] = val_19_auto
  114. else
  115. end
  116. end
  117. return tbl_17_auto
  118. end
  119. local function ui_print(msg)
  120. return UIErrorsFrame:AddMessage(msg)
  121. end
  122. local function stat_name(n)
  123. 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"}
  124. return (stat_names[(n + 1)] .. " (" .. n .. ")")
  125. end
  126. local function stat_print(item)
  127. local val = ""
  128. for n = 22, 56 do
  129. if (0 < item[n]) then
  130. val = (val .. " " .. stat_name((n - 21)) .. ": " .. item[n])
  131. else
  132. end
  133. end
  134. return val
  135. end
  136. local function main0(msg)
  137. local opts
  138. do
  139. local tbl_17_auto = {}
  140. local i_18_auto = #tbl_17_auto
  141. for v in string.gmatch(msg, "%w+") do
  142. local val_19_auto = v
  143. if (nil ~= val_19_auto) then
  144. i_18_auto = (i_18_auto + 1)
  145. do end (tbl_17_auto)[i_18_auto] = val_19_auto
  146. else
  147. end
  148. end
  149. opts = tbl_17_auto
  150. end
  151. local _let_12_ = opts
  152. local slot = _let_12_[1]
  153. local stat = _let_12_[2]
  154. local gear_index = _let_12_[3]
  155. local slot0 = (slot .. "Slot")
  156. local stat0 = (21 + tonumber(stat))
  157. local gear_index0 = tonumber((gear_index or "1"))
  158. local inv_slot = GetInventorySlotInfo(slot0)
  159. local i_link = GetInventoryItemLink("player", inv_slot)
  160. local i_id
  161. if i_link then
  162. i_id = parse_item_id(i_link)
  163. else
  164. i_id = nil
  165. end
  166. local p_level = UnitLevel("player")
  167. if not i_link then
  168. local best
  169. local function _14_(a, b)
  170. return ((a[stat0] < b[stat0]) and (a[12] < b[12]))
  171. end
  172. best = (find_good_item(inv_slot, UnitLevel("player"), stat0, 1, _14_))[gear_index0]
  173. if best then
  174. DEFAULT_CHAT_FRAME:AddMessage(string.format("|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r", best[2], best[8]))
  175. return ui_print(("next best available: " .. best[8] .. " " .. stat_print(best) .. " at " .. best[20] .. "N/A"))
  176. else
  177. return nil
  178. end
  179. else
  180. local i_name = GetItemInfo(i_link)
  181. local stats = find_item_by_name(un_quote(i_name))
  182. if stats then
  183. local i_class = stats[4]
  184. local i_subclass = stats[6]
  185. local i_invtype = stats[10]
  186. local i_level = stats[12]
  187. local i_stat = stats[stat0]
  188. local best
  189. local function _16_(a, b)
  190. return (a[stat0] < b[stat0])
  191. end
  192. best = (find_next_better_item(i_class, i_subclass, i_invtype, p_level, i_level, stat0, max(i_stat, 1), _16_))[gear_index0]
  193. if best then
  194. DEFAULT_CHAT_FRAME:AddMessage(string.format("|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r", best[2], best[8]))
  195. ui_print(("next best available: " .. best[8] .. " " .. stat_print(best) .. " at " .. best[20] .. "N/A"))
  196. ui_print(("currently equipped " .. i_name .. " " .. (stats[stat0] or "N/A")))
  197. else
  198. end
  199. else
  200. print(("Item " .. un_quote(i_name) .. " not found"))
  201. end
  202. return "ok"
  203. end
  204. end
  205. main = main0
  206. local function maxxed()
  207. 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"}
  208. return slots
  209. end
  210. return maxxed