2.4.3. addon, shows better gear by slot and stat type
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

196 Zeilen
7.1KB

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