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.

214 lines
7.6KB

  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. elseif starts_with(a, "contains:") then
  44. return string.match(string.sub(a, 9), b)
  45. else
  46. return (a == b)
  47. end
  48. end
  49. local function find_items(params, _3fsort)
  50. _G.assert((nil ~= params), "Missing argument params on main.fnl:57")
  51. local results
  52. do
  53. local tbl_17_auto = {}
  54. local i_18_auto = #tbl_17_auto
  55. for _, row in ipairs(itemdb) do
  56. local val_19_auto
  57. do
  58. local hit = true
  59. for key, param in pairs(params) do
  60. hit = (hit and matches(param, row[key]))
  61. end
  62. if hit then
  63. val_19_auto = row
  64. else
  65. val_19_auto = nil
  66. end
  67. end
  68. if (nil ~= val_19_auto) then
  69. i_18_auto = (i_18_auto + 1)
  70. do end (tbl_17_auto)[i_18_auto] = val_19_auto
  71. else
  72. end
  73. end
  74. results = tbl_17_auto
  75. end
  76. if (_3fsort and results) then
  77. table.sort(results, _3fsort)
  78. return results
  79. else
  80. return results
  81. end
  82. end
  83. local function find_item(params, _3fsort)
  84. _G.assert((nil ~= params), "Missing argument params on main.fnl:72")
  85. local results = find_items(params, _3fsort)
  86. if results then
  87. return results[1]
  88. else
  89. return nil
  90. end
  91. end
  92. local function find_item_by_name(name)
  93. return find_item({[8] = ("contains:" .. name)})
  94. end
  95. local function find_next_better_item(class, subclass, invtype, lv, ilv, stat_position, item_stat, _3fsort)
  96. local stat_comparison = "gt>:%d"
  97. return find_items({[4] = class, [6] = subclass, [10] = invtype, [14] = string.format("lte:%d", lv), [stat_position] = string.format(stat_comparison, item_stat)}, _3fsort)
  98. end
  99. local function find_good_item(invtype, lv, stat_position, stat_baseline, _3fsort)
  100. _G.assert((nil ~= stat_baseline), "Missing argument stat-baseline on main.fnl:91")
  101. _G.assert((nil ~= stat_position), "Missing argument stat-position on main.fnl:91")
  102. _G.assert((nil ~= lv), "Missing argument lv on main.fnl:91")
  103. _G.assert((nil ~= invtype), "Missing argument invtype on main.fnl:91")
  104. return find_items({[10] = invtype, [14] = string.format("lte:%d", lv), [stat_position] = string.format("gte:%d", stat_baseline)}, _3fsort)
  105. end
  106. local function parse_item_id(link)
  107. return tonumber(string.sub(string.match(link, "item:[%d+]+"), 6))
  108. end
  109. local function parse_opts(msg)
  110. local tbl_17_auto = {}
  111. local i_18_auto = #tbl_17_auto
  112. for k, v in string.gmatch(msg, "%w+") do
  113. local val_19_auto = v
  114. if (nil ~= val_19_auto) then
  115. i_18_auto = (i_18_auto + 1)
  116. do end (tbl_17_auto)[i_18_auto] = val_19_auto
  117. else
  118. end
  119. end
  120. return tbl_17_auto
  121. end
  122. local function ui_print(msg)
  123. return UIErrorsFrame:AddMessage(msg)
  124. end
  125. local function stat_name(n)
  126. 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"}
  127. return (stat_names[(n + 1)] .. " (" .. n .. ")")
  128. end
  129. local function stat_print(item)
  130. local val = ""
  131. for n = 22, 56 do
  132. if (0 < item[n]) then
  133. val = (val .. " " .. stat_name((n - 21)) .. ": " .. item[n])
  134. else
  135. end
  136. end
  137. return val
  138. end
  139. local function main0(msg)
  140. local opts
  141. do
  142. local tbl_17_auto = {}
  143. local i_18_auto = #tbl_17_auto
  144. for v in string.gmatch(msg, "%w+") do
  145. local val_19_auto = v
  146. if (nil ~= val_19_auto) then
  147. i_18_auto = (i_18_auto + 1)
  148. do end (tbl_17_auto)[i_18_auto] = val_19_auto
  149. else
  150. end
  151. end
  152. opts = tbl_17_auto
  153. end
  154. local _let_12_ = opts
  155. local slot = _let_12_[1]
  156. local stat = _let_12_[2]
  157. local gear_index = _let_12_[3]
  158. local slot0 = (slot .. "Slot")
  159. local stat0 = (21 + tonumber(stat))
  160. local gear_index0 = tonumber((gear_index or "1"))
  161. local inv_slot = GetInventorySlotInfo(slot0)
  162. local i_link = GetInventoryItemLink("player", inv_slot)
  163. local i_id
  164. if i_link then
  165. i_id = parse_item_id(i_link)
  166. else
  167. i_id = nil
  168. end
  169. local p_level = UnitLevel("player")
  170. if not i_link then
  171. local best
  172. local function _14_(a, b)
  173. return ((a[12] + a[stat0]) < (b[12] + b[stat0]))
  174. end
  175. best = (find_good_item(inv_slot, UnitLevel("player"), stat0, 0, _14_))[gear_index0]
  176. if best then
  177. DEFAULT_CHAT_FRAME:AddMessage(string.format("|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r", best[2], best[8]))
  178. return ui_print(("next best available: " .. best[8] .. " " .. stat_print(best) .. " at " .. best[20] .. "N/A"))
  179. else
  180. return nil
  181. end
  182. else
  183. local i_name = GetItemInfo(i_link)
  184. local stats = find_item_by_name(un_quote(i_name))
  185. if stats then
  186. local i_class = stats[4]
  187. local i_subclass = stats[6]
  188. local i_invtype = stats[10]
  189. local i_level = stats[12]
  190. local i_stat = stats[stat0]
  191. local best
  192. local function _16_(a, b)
  193. return ((a[12] + a[stat0]) < (b[12] + b[stat0]))
  194. end
  195. best = (find_next_better_item(i_class, i_subclass, i_invtype, p_level, i_level, stat0, max(i_stat, 0), _16_))[gear_index0]
  196. if best then
  197. DEFAULT_CHAT_FRAME:AddMessage(string.format("|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r", best[2], best[8]))
  198. ui_print(("next best available: " .. best[8] .. " " .. stat_print(best) .. " at " .. best[20] .. "N/A"))
  199. ui_print(("currently equipped " .. i_name .. " " .. (stats[stat0] or "N/A")))
  200. else
  201. end
  202. else
  203. print(("Item " .. un_quote(i_name) .. " not found"))
  204. end
  205. return "ok"
  206. end
  207. end
  208. main = main0
  209. local function maxxed()
  210. 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"}
  211. return slots
  212. end
  213. return maxxed