2.4.3. addon, shows better gear by slot and stat type
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

183 lines
6.6KB

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