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.

192 lines
6.9KB

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